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 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | 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 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 29x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 29x 1x 1x 1x 1x 1x 1x 1x 1x 29x 1x 1x 1x 2x 2x 2x 2x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 27x 27x 27x 27x 27x 27x 27x 27x 27x 33x 33x 27x 27x 27x 54x 54x 27x 33x 33x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 24x 29x 29x 29x 29x 3x 3x 3x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 29x 33x 33x 33x 33x 33x 33x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 33x 33x 33x 33x 33x 33x 33x 33x 114x 114x 33x 33x 57x 33x 33x 57x 33x 33x 112x 112x 112x 112x 112x 112x 112x 112x 112x 33x 33x 56x 56x 56x 56x 56x 56x 33x 33x 33x 5x 33x 33x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 2x 1x 1x 1x 1x 1x 5x 4x 4x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 1x 1x | <template>
<div
v-if="show"
class="modal-overlay"
@click="$emit('close')"
data-testid="edit-modal"
>
<div class="modal-content" @click.stop>
<div class="p-6">
<h3 class="text-lg font-medium text-fg mb-1">Edit Match</h3>
<!-- Which match this is. Teams are multi-age (one canonical "IFA"
row across U13-U19), so the fixture alone does not identify a
match: the same clubs can meet twice on one day at different
age groups. A score was once typed into the wrong one of those
(SB-911). -->
<p
v-if="match"
class="text-sm text-fg-muted mb-4"
data-testid="edit-modal-subtitle"
>
<span class="font-medium text-fg"
>{{ homeTeamName }} vs {{ awayTeamName }}</span
>
<span v-if="match.age_group_name">
·
<span class="font-semibold text-fg">{{
match.age_group_name
}}</span></span
>
<span v-if="match.match_date"> · {{ match.match_date }}</span>
<span v-if="match.match_type_name">
· {{ match.match_type_name }}</span
>
</p>
<!-- Audit Trail Info -->
<div
v-if="
match && (match.match_id || match.created_at || match.updated_at)
"
class="mb-4 p-3 bg-surface-alt border border-line rounded-md text-xs text-fg-muted space-y-1"
>
<div v-if="isAdmin && match.id" class="flex items-center space-x-2">
<span class="font-medium">Match ID:</span>
<span class="font-mono text-fg">{{ match.id }}</span>
</div>
<div v-if="match.match_id" class="flex items-center space-x-2">
<span class="font-medium">External Match ID:</span>
<span class="font-mono text-fg">{{ match.match_id }}</span>
</div>
<div v-if="match.source" class="flex items-center space-x-2">
<span class="font-medium">Source:</span>
<span
:class="{
'px-2 py-0.5 rounded text-xs font-medium': true,
'bg-purple-100 text-purple-800 dark:bg-purple-500/15 dark:text-purple-300':
match.source === 'match-scraper',
'bg-gray-100 text-gray-700 dark:bg-surface-alt dark:text-fg-muted':
match.source === 'manual',
'bg-yellow-100 text-yellow-700 dark:bg-yellow-500/15 dark:text-yellow-300':
match.source === 'import',
}"
>
{{ getSourceText(match.source) }}
</span>
</div>
<div v-if="match.created_at">
<span class="font-medium">Created:</span>
{{ formatDate(match.created_at) }}
</div>
<div v-if="match.updated_at">
<span class="font-medium">Last Updated:</span>
{{ formatDate(match.updated_at) }}
</div>
</div>
<form @submit.prevent="updateMatch()">
<div class="grid grid-cols-3 gap-4 mb-4">
<div>
<label class="block text-sm font-medium text-fg mb-2">Date</label>
<input
v-model="formData.match_date"
type="date"
required
data-testid="date-input"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
<div>
<label class="block text-sm font-medium text-fg mb-2"
>Kickoff Time
<span class="text-fg-muted text-xs">(optional)</span></label
>
<input
v-model="formData.kickoff_time"
type="time"
data-testid="kickoff-time-input"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
<div>
<label class="block text-sm font-medium text-fg mb-2"
>Match Type</label
>
<select
v-model="formData.match_type_id"
required
data-testid="match-type-select"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option
v-for="matchType in matchTypes"
:key="matchType.id"
:value="matchType.id"
>
{{ matchType.name }}
</option>
</select>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-sm font-medium text-fg mb-2"
>Home Team</label
>
<select
v-model="formData.home_team_id"
required
data-testid="home-team-select"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option
v-for="team in availableTeams"
:key="team.id"
:value="team.id"
>
{{ team.name }}
</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-fg mb-2"
>Away Team</label
>
<select
v-model="formData.away_team_id"
required
data-testid="away-team-select"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option
v-for="team in availableTeams"
:key="team.id"
:value="team.id"
>
{{ team.name }}
</option>
</select>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label
class="block text-sm font-medium text-fg mb-2"
for="edit-home-score"
data-testid="home-score-label"
>{{ homeTeamName }}
<span class="text-fg-muted font-normal">(home)</span></label
>
<input
id="edit-home-score"
v-model.number="formData.home_score"
type="number"
min="0"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
placeholder="Leave empty if not played"
/>
</div>
<div>
<label
class="block text-sm font-medium text-fg mb-2"
for="edit-away-score"
data-testid="away-score-label"
>{{ awayTeamName }}
<span class="text-fg-muted font-normal">(away)</span></label
>
<input
id="edit-away-score"
v-model.number="formData.away_score"
type="number"
min="0"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
placeholder="Leave empty if not played"
/>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-sm font-medium text-fg mb-2"
>Season</label
>
<select
v-model="formData.season_id"
required
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option
v-for="season in seasons"
:key="season.id"
:value="season.id"
>
{{ season.name }}
</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-fg mb-2"
>Age Group</label
>
<select
v-model="formData.age_group_id"
required
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option
v-for="ageGroup in ageGroups"
:key="ageGroup.id"
:value="ageGroup.id"
>
{{ ageGroup.name }}
</option>
</select>
</div>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Match Status</label
>
<select
v-model="formData.match_status"
required
data-testid="status-select"
class="w-full px-3 py-2 border border-line rounded-md bg-card text-fg focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option value="scheduled">Scheduled</option>
<option value="live">Live</option>
<option value="completed">Completed</option>
<option value="postponed">Postponed</option>
<option value="cancelled">Cancelled</option>
</select>
<p class="mt-1 text-xs text-fg-muted">
Set to "Live" when the match is in progress
</p>
</div>
<!-- Error Display -->
<div
v-if="error"
class="mb-4 p-3 bg-red-50 dark:bg-red-500/10 border border-red-200 dark:border-red-900 rounded-md text-red-800 dark:text-red-300 text-sm"
data-testid="error-message"
>
{{ error }}
</div>
<div class="flex justify-end space-x-3">
<button
type="button"
@click="$emit('close')"
data-testid="cancel-button"
class="px-4 py-2 text-sm font-medium text-fg bg-surface-alt hover:bg-line rounded-md"
>
Cancel
</button>
<button
type="submit"
:disabled="loading"
data-testid="submit-button"
class="px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md disabled:opacity-50"
>
{{ loading ? 'Updating...' : 'Update Match' }}
</button>
</div>
</form>
</div>
</div>
</div>
</template>
<script>
import { computed, ref, watch } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '../config/api';
export default {
name: 'MatchEditModal',
props: {
show: {
type: Boolean,
default: false,
},
match: {
type: Object,
default: null,
},
teams: {
type: Array,
default: () => [],
},
seasons: {
type: Array,
default: () => [],
},
matchTypes: {
type: Array,
default: () => [],
},
ageGroups: {
type: Array,
default: () => [],
},
},
emits: ['close', 'updated'],
setup(props, { emit }) {
const authStore = useAuthStore();
const loading = ref(false);
const error = ref(null);
const availableTeams = ref([]);
// The two teams already on the match, as option-shaped rows.
//
// A <select required> whose current value has no matching <option> reports
// itself empty, so the browser blocks the submit and the whole form dies
// quietly — no error, nothing happens on Update Match. That is what every
// Flex match did (SB-1011). Whatever the filter returns, the match's own
// teams have to be in the list, because the control has to be able to
// represent the value it already holds.
const teamsOnMatch = match =>
[
match?.home_team_id && {
id: match.home_team_id,
name: match.home_team_name || `Team ${match.home_team_id}`,
},
match?.away_team_id && {
id: match.away_team_id,
name: match.away_team_name || `Team ${match.away_team_id}`,
},
].filter(Boolean);
const withMatchTeams = (list, match) => {
const rows = Array.isArray(list) ? [...list] : [];
const seen = new Set(rows.map(t => t.id));
for (const team of teamsOnMatch(match)) {
if (!seen.has(team.id)) rows.push(team);
}
return rows.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
};
const fetchTeamsForMatch = async match => {
if (!match) return;
const params = new URLSearchParams({ for_match_edit: 'true' });
if (match.match_type_id)
params.append('match_type_id', match.match_type_id);
if (match.age_group_id) params.append('age_group_id', match.age_group_id);
if (match.division_id) params.append('division_id', match.division_id);
try {
const result = await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams?${params.toString()}`
);
availableTeams.value = withMatchTeams(
Array.isArray(result) ? result : props.teams,
match
);
} catch {
// Fall back to the teams passed by the parent
availableTeams.value = withMatchTeams(props.teams, match);
}
};
const formData = ref({
match_date: '',
kickoff_time: '',
home_team_id: '',
away_team_id: '',
home_score: null,
away_score: null,
match_type_id: '',
season_id: '',
age_group_id: '',
division_id: null,
match_status: 'scheduled',
});
// Extract local time from scheduled_kickoff (UTC ISO string)
const extractLocalTime = isoString => {
if (!isoString) return '';
const date = new Date(isoString);
// Format as HH:MM for time input
return date.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
});
};
// Watch for match prop changes to populate form and fetch relevant teams
watch(
() => props.match,
newMatch => {
if (newMatch) {
formData.value = {
match_date: newMatch.match_date,
kickoff_time: extractLocalTime(newMatch.scheduled_kickoff),
home_team_id: newMatch.home_team_id,
away_team_id: newMatch.away_team_id,
home_score: newMatch.home_score,
away_score: newMatch.away_score,
match_type_id: newMatch.match_type_id,
season_id: newMatch.season_id,
age_group_id: newMatch.age_group_id,
division_id: newMatch.division_id,
match_status: newMatch.match_status || 'scheduled',
};
error.value = null;
fetchTeamsForMatch(newMatch);
}
},
{ immediate: true }
);
// The team currently selected in each dropdown, not the one the match
// was opened with — the labels have to follow an edit that swaps sides.
// Falls back to the names the match arrived with while the team list is
// still loading.
const teamNameFor = (teamId, fallback) => {
const team = availableTeams.value.find(t => t.id === teamId);
return team?.name || fallback || '';
};
const homeTeamName = computed(() =>
teamNameFor(formData.value.home_team_id, props.match?.home_team_name)
);
const awayTeamName = computed(() =>
teamNameFor(formData.value.away_team_id, props.match?.away_team_name)
);
const formatDate = dateString => {
if (!dateString) return '';
const date = new Date(dateString);
return date.toLocaleString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
});
};
const getSourceText = source => {
const sourceMap = {
manual: 'Manually entered',
'match-scraper': 'Auto-scraped',
import: 'Imported from backup',
};
return sourceMap[source] || source;
};
// Convert local date + time to UTC ISO string for scheduled_kickoff
const toScheduledKickoffUTC = (date, time) => {
if (!date || !time) return null;
// Combine date and time into a local datetime, then convert to UTC
const localDateTime = new Date(`${date}T${time}`);
return localDateTime.toISOString();
};
const updateMatch = async () => {
if (!props.match) return;
try {
loading.value = true;
error.value = null;
// Build match data for API
const matchData = {
...formData.value,
scheduled_kickoff: toScheduledKickoffUTC(
formData.value.match_date,
formData.value.kickoff_time
),
};
// Remove kickoff_time as it's not a valid API field
delete matchData.kickoff_time;
// Parse scores - treat null/undefined/empty string as "no score entered"
// Note: 0 is a valid score (e.g., 3-0 match)
const homeScoreValue = formData.value.home_score;
const awayScoreValue = formData.value.away_score;
// Check if scores have been entered (not null, undefined, or empty string)
const homeScoreEntered =
homeScoreValue !== null &&
homeScoreValue !== undefined &&
homeScoreValue !== '';
const awayScoreEntered =
awayScoreValue !== null &&
awayScoreValue !== undefined &&
awayScoreValue !== '';
// Convert to numbers, defaulting to 0 if not entered
matchData.home_score = homeScoreEntered ? Number(homeScoreValue) : 0;
matchData.away_score = awayScoreEntered ? Number(awayScoreValue) : 0;
// Use the manually selected status
matchData.status = formData.value.match_status;
console.log('MatchEditModal - Update data:', {
homeScoreValue,
awayScoreValue,
homeScoreEntered,
awayScoreEntered,
status: matchData.status,
fullMatchData: matchData,
});
const updatedMatch = await authStore.apiRequest(
`${getApiBaseUrl()}/api/matches/${props.match.id}`,
{
method: 'PATCH',
body: JSON.stringify(matchData),
}
);
console.log(
'MatchEditModal - Received updated match from API:',
updatedMatch
);
// Emit the updated match data so parent can update immediately
emit('updated', updatedMatch);
emit('close');
} catch (err) {
console.error('Update match error:', err);
if (
err.message.includes('401') ||
err.message.includes('Invalid or expired token') ||
err.message.includes('Session expired')
) {
error.value =
'Your session has expired. Please refresh the page or log out and log back in to continue.';
} else {
error.value = err.message || 'Failed to update match';
}
} finally {
loading.value = false;
}
};
return {
formData,
loading,
error,
availableTeams,
homeTeamName,
awayTeamName,
isAdmin: authStore.isAdmin,
updateMatch,
formatDate,
getSourceText,
};
},
};
</script>
<style scoped>
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal-content {
background: rgb(var(--color-card));
border-radius: 0.5rem;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
}
</style>
|