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 | 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 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 1x 20x 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 21x 21x 21x 21x 21x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 2x 2x 2x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 20x 21x 21x 21x 21x 21x 21x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 21x 21x 21x 21x 96x 96x 96x 96x 96x 96x 96x 96x 96x 21x 21x 48x 48x 48x 48x 48x 48x 21x 21x 21x 5x 21x 21x 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 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 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-gray-900 mb-4">Edit Match</h3>
<!-- Audit Trail Info -->
<div
v-if="
match && (match.match_id || match.created_at || match.updated_at)
"
class="mb-4 p-3 bg-gray-50 border border-gray-200 rounded-md text-xs text-gray-600 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-gray-800">{{ 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-gray-800">{{ 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':
match.source === 'match-scraper',
'bg-gray-100 text-gray-700': match.source === 'manual',
'bg-yellow-100 text-yellow-700': 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-gray-700 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-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-2"
>Kickoff Time
<span class="text-gray-400 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-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 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-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-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-gray-700 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-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-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-gray-700 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-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-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-gray-700 mb-2"
>Home Score</label
>
<input
v-model.number="formData.home_score"
type="number"
min="0"
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Leave empty if not played"
/>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-2"
>Away Score</label
>
<input
v-model.number="formData.away_score"
type="number"
min="0"
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-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-gray-700 mb-2"
>Season</label
>
<select
v-model="formData.season_id"
required
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-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-gray-700 mb-2"
>Age Group</label
>
<select
v-model="formData.age_group_id"
required
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-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-gray-700 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-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-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-gray-500">
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 border border-red-200 rounded-md text-red-800 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-gray-700 bg-gray-100 hover:bg-gray-200 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-blue-600 hover:bg-blue-700 rounded-md disabled:opacity-50"
>
{{ loading ? 'Updating...' : 'Update Match' }}
</button>
</div>
</form>
</div>
</div>
</div>
</template>
<script>
import { 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([]);
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 = Array.isArray(result) ? result : props.teams;
} catch {
// Fall back to the teams passed by the parent
availableTeams.value = props.teams;
}
};
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 }
);
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,
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: white;
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>
|