Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 18x 1x 1x 1x 1x 1x 1x 1x 1x 18x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 62x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 1x 1x 1x 1x 1x 1x 1x 1x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 61x 61x 61x 61x 1x 1x 19x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 1x 1x 1x 1x 1x 24x 22x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 9x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 1x 27x 27x 8x 27x 27x 1x 1x 20x 20x 1x 20x 20x 1x 1x 30x 30x 30x 30x 1x 1x 7x 7x | <template>
<form
v-if="form"
class="channel-form"
data-testid="channel-form"
@submit.prevent="submit"
>
<div class="grid gap-3 sm:grid-cols-2">
<label class="field">
<span>Platform</span>
<select
v-model="form.platform"
:disabled="editing || busy"
data-testid="form-platform"
>
<option v-for="p in platforms" :key="p.id" :value="p.id">
{{ p.icon }} {{ p.label }}
</option>
</select>
</label>
<fieldset v-if="scopeType !== 'global'" class="field">
<legend>Who it's for</legend>
<div class="flex gap-4 text-sm text-fg pt-1">
<label class="inline-flex items-center gap-1.5">
<input
v-model="form.audience"
type="radio"
value="fans"
:disabled="editing || busy"
data-testid="form-audience-fans"
/>
Fans
</label>
<label class="inline-flex items-center gap-1.5">
<input
v-model="form.audience"
type="radio"
value="players"
:disabled="editing || busy"
data-testid="form-audience-players"
/>
Players
</label>
</div>
</fieldset>
</div>
<label class="field">
<span>Name <em>(optional)</em></span>
<input
v-model="form.label"
maxlength="80"
:disabled="busy"
placeholder="e.g. #ifa-announcements or #ifa-hg-u15"
data-testid="form-label"
/>
<small>Only managers see this. It tells your channels apart.</small>
</label>
<label class="field">
<span>{{ destinationLabel }}</span>
<input
v-model="form.destination"
:disabled="busy"
:placeholder="
editing
? 'Leave blank to keep the current one'
: platform?.placeholder
"
autocomplete="off"
data-testid="form-destination"
/>
<small
v-if="destinationError"
class="error"
data-testid="form-destination-error"
>
{{ destinationError }}
</small>
</label>
<label class="field">
<span>Invite link <em>(optional)</em></span>
<input
v-model="form.invite_url"
:disabled="busy"
placeholder="The link people use to join"
autocomplete="off"
data-testid="form-invite"
/>
<small v-if="inviteError" class="error" data-testid="form-invite-error">
{{ inviteError }}
</small>
<small v-else>
Shown only to people you approve, or who qualify to join. Anyone who has
the link can pass it on, so treat the channel as open to them.
</small>
</label>
<label
v-if="threadsOffered"
class="field inline-flex items-start gap-2 text-sm text-fg"
>
<input
v-model="form.post_as_threads"
type="checkbox"
:disabled="busy"
data-testid="form-threads"
/>
<span>
One post per match
<small class="block">
For a Discord forum channel: each match gets its own post and its
updates go into it. Point the webhook at the forum channel itself.
</small>
</span>
</label>
<fieldset class="field">
<legend>What to post</legend>
<div class="flex gap-4 text-sm text-fg pt-1">
<label class="inline-flex items-center gap-1.5">
<input
v-model="form.eventsMode"
type="radio"
value="all"
:disabled="busy"
data-testid="form-events-all"
/>
Every match event
</label>
<label class="inline-flex items-center gap-1.5">
<input
v-model="form.eventsMode"
type="radio"
value="some"
:disabled="busy"
data-testid="form-events-some"
/>
Only these
</label>
</div>
<div
v-if="form.eventsMode === 'some'"
class="flex flex-wrap gap-x-4 gap-y-1 text-sm text-fg mt-2"
>
<label
v-for="e in offeredEvents"
:key="e.id"
class="inline-flex items-center gap-1.5"
>
<input
v-model="form.events"
type="checkbox"
:value="e.id"
:disabled="busy"
:data-testid="`form-event-${e.id}`"
/>
{{ e.label }}
</label>
</div>
<small
v-if="form.eventsMode === 'some' && !form.events.length"
class="warn"
data-testid="form-events-none"
>
Nothing is selected, so nothing will be posted.
</small>
</fieldset>
<details
v-if="platform?.setup_steps?.length"
class="setup"
:open="!editing"
data-testid="form-setup"
>
<summary>How to set up {{ platform.label }}</summary>
<ol>
<li v-for="(step, i) in platform.setup_steps" :key="i">{{ step }}</li>
</ol>
<template
v-if="
form.audience === 'players' && platform.player_setup_steps?.length
"
>
<p class="setup-sub">For a player channel</p>
<ol data-testid="form-player-setup">
<li v-for="(step, i) in platform.player_setup_steps" :key="i">
{{ step }}
</li>
</ol>
</template>
<p
v-if="platform.age_note"
class="setup-note"
data-testid="form-age-note"
>
{{ platform.age_note }}
</p>
<p class="setup-note">
You own and moderate this channel. Missing Table only posts match
updates to it.
</p>
<button
type="button"
class="guide-link"
data-testid="form-open-guide"
@click="
emit('open-guide', {
platform: form.platform,
audience: form.audience,
})
"
>
Full guide: permissions, invite links and private channels
</button>
</details>
<div class="flex gap-2 mt-1">
<button
type="submit"
class="btn primary"
:disabled="!valid || busy"
data-testid="form-save"
>
{{ busy ? 'Saving…' : editing ? 'Save' : 'Add channel' }}
</button>
<button
type="button"
class="btn secondary"
:disabled="busy"
data-testid="form-cancel"
@click="emit('cancel')"
>
Cancel
</button>
</div>
</form>
</template>
<script setup>
import { computed, watch } from 'vue';
/**
* Add or edit one notification channel (SB-1605). The parent owns the form
* object; validation patterns and setup steps come from the platform registry.
* Platform and audience are fixed once a channel exists.
*/
const form = defineModel({ type: Object, default: null });
const props = defineProps({
platforms: { type: Array, required: true },
eventTypes: { type: Array, required: true },
scopeType: { type: String, required: true },
editing: { type: Boolean, default: false },
busy: { type: Boolean, default: false },
});
const emit = defineEmits(['submit', 'cancel', 'open-guide']);
const platform = computed(() =>
props.platforms.find(p => p.id === form.value?.platform)
);
// Match threads (SB-1606): platforms that have them, except a club players
// room, which stays flat.
const threadsOffered = computed(
() =>
Boolean(platform.value?.capabilities?.includes('threads')) &&
!(props.scopeType === 'club' && form.value?.audience === 'players')
);
watch(threadsOffered, offered => {
if (!offered && form.value) form.value.post_as_threads = false;
});
// Player-only events (SB-1610, e.g. lineup posted) only make sense on a
// squad's player channel; anywhere else they would never be sent.
const playerChannel = computed(
() => props.scopeType === 'team' && form.value?.audience === 'players'
);
const offeredEvents = computed(() =>
props.eventTypes.filter(e => !e.player_only || playerChannel.value)
);
watch(playerChannel, isPlayerChannel => {
if (isPlayerChannel || !form.value?.events) return;
const playerOnly = new Set(
props.eventTypes.filter(e => e.player_only).map(e => e.id)
);
form.value.events = form.value.events.filter(id => !playerOnly.has(id));
});
const destinationLabel = computed(
() => platform.value?.destination_label || 'Destination'
);
const matches = (pattern, value) => {
try {
return new RegExp(pattern).test(value);
} catch {
return true; // the server checks again
}
};
const destinationError = computed(() => {
const value = form.value?.destination.trim();
if (!value || !platform.value) return null;
return matches(platform.value.destination_pattern, value)
? null
: platform.value.destination_error;
});
const inviteError = computed(() => {
const value = form.value?.invite_url.trim();
if (!value || !platform.value?.invite_pattern) return null;
return matches(platform.value.invite_pattern, value)
? null
: platform.value.invite_error;
});
const valid = computed(() => {
if (!form.value || !platform.value) return false;
const hasDestination = Boolean(form.value.destination.trim());
if (!props.editing && !hasDestination) return false;
return !destinationError.value && !inviteError.value;
});
const submit = () => {
if (valid.value) emit('submit');
};
</script>
<style scoped>
.channel-form {
display: flex;
flex-direction: column;
gap: 0.75rem;
margin-top: 0.75rem;
}
.field {
display: flex;
flex-direction: column;
gap: 0.25rem;
font-size: 0.8125rem;
color: rgb(var(--color-fg-muted));
min-width: 0;
}
.field > span,
.field > legend {
color: rgb(var(--color-fg));
font-weight: 500;
}
.field em {
font-style: normal;
color: rgb(var(--color-fg-muted));
font-weight: 400;
}
.field input:not([type='radio']):not([type='checkbox']),
.field select {
padding: 0.45rem 0.7rem;
border: 1px solid rgb(var(--color-line));
border-radius: 0.375rem;
font-size: 0.875rem;
background: rgb(var(--color-card));
color: rgb(var(--color-fg));
min-width: 0;
}
.field input::placeholder {
color: rgb(var(--color-fg-muted));
}
.error {
color: #b91c1c;
}
.warn {
color: #b45309;
}
.setup {
font-size: 0.8125rem;
color: rgb(var(--color-fg-muted));
}
.setup summary {
cursor: pointer;
color: rgb(var(--color-fg));
font-weight: 500;
}
.setup ol {
margin: 0.5rem 0 0 1.25rem;
list-style: decimal;
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.setup-sub {
margin: 0.75rem 0 0;
color: rgb(var(--color-fg));
font-weight: 500;
}
.setup-note {
margin: 0.5rem 0 0;
}
.guide-link {
margin-top: 0.5rem;
padding: 0;
background: none;
border: none;
color: rgb(37 99 235);
font-weight: 600;
font-size: 0.8125rem;
cursor: pointer;
}
.btn {
padding: 0.4rem 0.8rem;
border-radius: 0.375rem;
font-size: 0.875rem;
font-weight: 500;
border: 1px solid transparent;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn.primary {
background: #2563eb;
color: #fff;
}
.btn.secondary {
background: rgb(var(--color-surface-alt));
color: rgb(var(--color-fg));
border-color: rgb(var(--color-line));
}
:global(.dark .channel-form .error) {
color: #fca5a5;
}
:global(.dark .channel-form .warn) {
color: #fcd34d;
}
</style>
|