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 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | 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 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 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 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 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 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 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 | <template>
<div>
<div class="flex justify-between items-center mb-6">
<h3 class="text-lg font-semibold text-fg">Players Management</h3>
<button
@click="openAddModal"
class="px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md"
data-testid="admin-add-player-button"
>
+ Add Player
</button>
</div>
<!-- Search and Filters -->
<div class="mb-6 flex flex-wrap gap-4">
<div class="flex-1 min-w-[200px]">
<input
v-model="searchQuery"
type="text"
placeholder="Search by name or email..."
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
@input="debouncedSearch"
/>
</div>
<div class="w-48">
<select
v-model="selectedClubId"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
@change="fetchPlayers"
>
<option :value="null">All Clubs</option>
<option v-for="club in clubs" :key="club.id" :value="club.id">
{{ club.name }}
</option>
</select>
</div>
<div class="w-48">
<select
v-model="selectedTeamId"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
@change="fetchPlayers"
>
<option :value="null">All Teams</option>
<option v-for="team in filteredTeams" :key="team.id" :value="team.id">
{{ team.name }}
</option>
</select>
</div>
<div class="w-44">
<select
v-model="sourceFilter"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
data-testid="source-filter"
>
<option value="all">All Players</option>
<option value="account">With Account</option>
<option value="roster">Roster Only</option>
</select>
</div>
</div>
<!-- Loading State -->
<div v-if="loading" class="flex justify-center py-8">
<div
class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600"
></div>
</div>
<!-- Error State -->
<div
v-if="error"
class="bg-red-50 border border-red-200 rounded-md p-4 mb-4"
>
<div class="text-red-800">{{ error }}</div>
</div>
<!-- Players Table -->
<div
v-else-if="!loading"
class="overflow-x-auto shadow ring-1 ring-black ring-opacity-5 md:rounded-lg"
>
<table class="min-w-full divide-y divide-line">
<thead class="bg-surface-alt">
<tr>
<th
class="px-6 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider"
>
Player
</th>
<th
class="px-6 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider"
>
Email
</th>
<th
class="px-6 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider"
>
Jersey #
</th>
<th
class="px-6 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider"
>
Current Teams
</th>
<th
class="px-6 py-3 text-right text-xs font-medium text-fg-muted uppercase tracking-wider"
>
Actions
</th>
</tr>
</thead>
<tbody class="bg-card divide-y divide-line">
<tr
v-for="player in visiblePlayers"
:key="`${player.source}-${player.id}`"
>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div
class="h-10 w-10 flex-shrink-0 rounded-full bg-surface-alt flex items-center justify-center"
>
<img
v-if="player.photo_1_url"
:src="player.photo_1_url"
class="h-10 w-10 rounded-full object-cover"
alt=""
/>
<span v-else class="text-fg-muted text-sm">{{
getInitials(player.display_name)
}}</span>
</div>
<div class="ml-4">
<div class="text-sm font-medium text-fg">
{{ player.display_name || 'Unknown' }}
<span
v-if="player.source === 'roster'"
class="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-amber-100 text-amber-800"
>No account</span
>
</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-fg-muted">
{{ player.email || '-' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-fg-muted">
{{ player.player_number || '-' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-fg-muted">
<div class="flex flex-wrap gap-1">
<span
v-for="assignment in player.current_teams"
:key="assignment.id"
class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-brand-100 text-brand-800"
>
{{ assignment.team?.name || 'Unknown Team' }}
</span>
<span
v-if="
!player.current_teams || player.current_teams.length === 0
"
class="text-fg-muted italic"
>
No team assigned
</span>
</div>
</td>
<td
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium"
>
<template v-if="player.source !== 'roster'">
<button
@click="openEditModal(player)"
class="text-brand-600 dark:text-brand-300 hover:text-brand-900 dark:hover:text-brand-200 mr-3"
>
Edit
</button>
<button
@click="openTeamsModal(player)"
class="text-green-600 hover:text-green-900"
>
Teams
</button>
</template>
<span v-else class="text-fg-muted text-xs italic"
>Managed via team roster</span
>
</td>
</tr>
<tr v-if="visiblePlayers.length === 0">
<td colspan="5" class="px-6 py-8 text-center text-fg-muted">
No players found
</td>
</tr>
</tbody>
</table>
<!-- Pagination -->
<div
v-if="totalCount > 0"
class="bg-card px-4 py-3 flex items-center justify-between border-t border-line sm:px-6"
>
<div class="flex-1 flex justify-between sm:hidden">
<button
@click="previousPage"
:disabled="offset === 0"
class="relative inline-flex items-center px-4 py-2 border border-line text-sm font-medium rounded-md text-fg bg-card hover:bg-surface-alt disabled:opacity-50"
>
Previous
</button>
<button
@click="nextPage"
:disabled="offset + limit >= totalCount"
class="ml-3 relative inline-flex items-center px-4 py-2 border border-line text-sm font-medium rounded-md text-fg bg-card hover:bg-surface-alt disabled:opacity-50"
>
Next
</button>
</div>
<div
class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between"
>
<div>
<p class="text-sm text-fg">
Showing
<span class="font-medium">{{ offset + 1 }}</span>
to
<span class="font-medium">{{
Math.min(offset + limit, totalCount)
}}</span>
of
<span class="font-medium">{{ totalCount }}</span>
results
</p>
</div>
<div>
<nav
class="relative z-0 inline-flex rounded-md shadow-sm -space-x-px"
aria-label="Pagination"
>
<button
@click="previousPage"
:disabled="offset === 0"
class="relative inline-flex items-center px-2 py-2 rounded-l-md border border-line bg-card text-sm font-medium text-fg-muted hover:bg-surface-alt disabled:opacity-50"
>
Previous
</button>
<button
@click="nextPage"
:disabled="offset + limit >= totalCount"
class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-line bg-card text-sm font-medium text-fg-muted hover:bg-surface-alt disabled:opacity-50"
>
Next
</button>
</nav>
</div>
</div>
</div>
</div>
<!-- Edit Player Modal -->
<div
v-if="showEditModal"
class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50"
@click="closeModals"
>
<div
class="relative top-20 mx-auto p-5 border border-line w-96 shadow-lg rounded-md bg-card"
@click.stop
>
<div class="mt-3">
<h3 class="text-lg font-medium text-fg mb-4">Edit Player</h3>
<form @submit.prevent="updatePlayer">
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Display Name</label
>
<input
v-model="editForm.display_name"
type="text"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Jersey Number</label
>
<input
v-model.number="editForm.player_number"
type="number"
min="1"
max="99"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Positions</label
>
<PositionPicker v-model="editForm.positions" />
</div>
<div class="flex justify-end gap-2">
<button
type="button"
@click="closeModals"
class="px-4 py-2 bg-surface-alt text-fg rounded-md hover:bg-line"
>
Cancel
</button>
<button
type="submit"
:disabled="formLoading"
class="px-4 py-2 bg-brand-600 text-white rounded-md hover:bg-brand-700 disabled:opacity-50"
>
{{ formLoading ? 'Saving...' : 'Save' }}
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Add Player Modal (roster entry, no account needed) -->
<div
v-if="showAddModal"
class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50"
@click="closeModals"
>
<div
class="relative top-20 mx-auto p-5 border border-line w-[480px] shadow-lg rounded-md bg-card"
@click.stop
data-testid="admin-add-player-modal"
>
<div class="mt-3">
<h3 class="text-lg font-medium text-fg mb-1">Add Player</h3>
<p class="text-sm text-fg-muted mb-4">
Creates a roster entry — no account needed. The player can claim it
later via an invite with their jersey number.
</p>
<form @submit.prevent="submitAddPlayer">
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-sm text-fg-muted mb-1">Team</label>
<select
v-model="addPlayerForm.team_id"
required
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option :value="null" disabled>Select team</option>
<option v-for="team in teams" :key="team.id" :value="team.id">
{{ team.name }}
</option>
</select>
</div>
<div>
<label class="block text-sm text-fg-muted mb-1">Season</label>
<select
v-model="addPlayerForm.season_id"
required
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option :value="null" disabled>Select season</option>
<option
v-for="season in seasons"
:key="season.id"
:value="season.id"
>
{{ season.name }}
</option>
</select>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-sm text-fg-muted mb-1"
>Age Group</label
>
<select
v-model="addPlayerForm.age_group_id"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option :value="null">No age group</option>
<option
v-for="ageGroup in ageGroups"
:key="ageGroup.id"
:value="ageGroup.id"
>
{{ ageGroup.name }}
</option>
</select>
</div>
<div>
<label class="block text-sm text-fg-muted mb-1"
>Jersey Number</label
>
<input
v-model.number="addPlayerForm.jersey_number"
type="number"
min="1"
max="99"
required
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-sm text-fg-muted mb-1"
>First Name</label
>
<input
v-model="addPlayerForm.first_name"
type="text"
maxlength="100"
placeholder="Optional"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
<div>
<label class="block text-sm text-fg-muted mb-1"
>Last Name</label
>
<input
v-model="addPlayerForm.last_name"
type="text"
maxlength="100"
placeholder="Optional"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
</div>
<div class="mb-4">
<label class="block text-sm text-fg-muted mb-1">Positions</label>
<PositionPicker v-model="addPlayerForm.positions" />
</div>
<div class="flex justify-end gap-2">
<button
type="button"
@click="closeModals"
class="px-4 py-2 bg-surface-alt text-fg rounded-md hover:bg-line"
>
Cancel
</button>
<button
type="submit"
:disabled="formLoading"
class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50"
data-testid="admin-save-player-button"
>
{{ formLoading ? 'Adding...' : 'Add Player' }}
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Manage Teams Modal -->
<div
v-if="showTeamsModal"
class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50"
@click="closeModals"
>
<div
class="relative top-20 mx-auto p-5 border border-line w-[500px] shadow-lg rounded-md bg-card"
@click.stop
>
<div class="mt-3">
<h3 class="text-lg font-medium text-fg mb-4">
Manage Teams for {{ selectedPlayer?.display_name }}
</h3>
<!-- Current Team Assignments -->
<div class="mb-6">
<h4 class="text-sm font-medium text-fg mb-2">
Current Team Assignments
</h4>
<div
v-if="selectedPlayer?.current_teams?.length > 0"
class="space-y-2"
>
<div
v-for="assignment in selectedPlayer.current_teams"
:key="assignment.id"
class="flex items-center justify-between p-2 bg-surface-alt rounded"
>
<div>
<span class="font-medium">{{
assignment.team?.name || 'Unknown'
}}</span>
<span class="text-fg-muted text-sm ml-2">
({{ assignment.season?.name || 'Unknown Season' }})
</span>
</div>
<button
@click="endTeamAssignment(assignment)"
class="text-red-600 hover:text-red-800 text-sm"
>
End
</button>
</div>
</div>
<div v-else class="text-fg-muted text-sm">
No current assignments
</div>
</div>
<!-- Add New Assignment -->
<div class="border-t border-line pt-4">
<h4 class="text-sm font-medium text-fg mb-2">
Add Team Assignment
</h4>
<form @submit.prevent="addTeamAssignment">
<div class="grid grid-cols-2 gap-4 mb-4">
<div>
<label class="block text-sm text-fg-muted mb-1">Season</label>
<select
v-model="assignmentForm.season_id"
required
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option :value="null" disabled>Select season</option>
<option
v-for="season in seasons"
:key="season.id"
:value="season.id"
>
{{ season.name }}
</option>
</select>
</div>
<div>
<label class="block text-sm text-fg-muted mb-1">Team</label>
<select
v-model="assignmentForm.team_id"
required
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option :value="null" disabled>Select team</option>
<option
v-for="team in teams"
: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 text-fg-muted mb-1"
>Age Group</label
>
<select
v-model="assignmentForm.age_group_id"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option :value="null">Auto (from team)</option>
<option
v-for="ageGroup in ageGroups"
:key="ageGroup.id"
:value="ageGroup.id"
>
{{ ageGroup.name }}
</option>
</select>
<p class="mt-1 text-xs text-fg-muted">
Set explicitly for umbrella teams (e.g. IFA fields U13–U15)
or to play a player up.
</p>
</div>
<div>
<label class="block text-sm text-fg-muted mb-1"
>Jersey Number</label
>
<input
v-model.number="assignmentForm.jersey_number"
type="number"
min="1"
max="99"
class="w-full px-3 py-2 bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
/>
</div>
</div>
<div class="mb-4">
<label class="inline-flex items-center">
<input
type="checkbox"
v-model="assignmentForm.is_current"
class="rounded border-line text-brand-600 focus:ring-brand-500"
/>
<span class="ml-2 text-sm text-fg">Current team</span>
</label>
</div>
<div class="flex justify-end gap-2">
<button
type="button"
@click="closeModals"
class="px-4 py-2 bg-surface-alt text-fg rounded-md hover:bg-line"
>
Close
</button>
<button
type="submit"
:disabled="formLoading"
class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50"
>
{{ formLoading ? 'Adding...' : 'Add Team' }}
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import { ref, computed, onMounted } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '../../config/api';
import PositionPicker from '@/components/shared/PositionPicker.vue';
import { parsePositions } from '@/constants/positions';
export default {
name: 'AdminPlayers',
components: {
PositionPicker,
},
setup() {
const authStore = useAuthStore();
// State
const players = ref([]);
const clubs = ref([]);
const teams = ref([]);
const seasons = ref([]);
const ageGroups = ref([]);
const loading = ref(false);
const formLoading = ref(false);
const error = ref(null);
const searchQuery = ref('');
const selectedClubId = ref(null);
const selectedTeamId = ref(null);
const offset = ref(0);
const limit = ref(50);
const totalCount = ref(0);
const sourceFilter = ref('all'); // all | account | roster
// Modal state
const showEditModal = ref(false);
const showTeamsModal = ref(false);
const showAddModal = ref(false);
const selectedPlayer = ref(null);
// Form state
const editForm = ref({
display_name: '',
player_number: null,
positions: [],
});
const assignmentForm = ref({
team_id: null,
season_id: null,
age_group_id: null,
jersey_number: null,
is_current: true,
});
const addPlayerForm = ref({
team_id: null,
season_id: null,
age_group_id: null,
jersey_number: null,
first_name: '',
last_name: '',
positions: [],
});
// Computed
const filteredTeams = computed(() => {
if (!selectedClubId.value) return teams.value;
return teams.value.filter(t => t.club_id === selectedClubId.value);
});
const visiblePlayers = computed(() => {
if (sourceFilter.value === 'all') return players.value;
return players.value.filter(p => p.source === sourceFilter.value);
});
// Debounced search
let searchTimeout = null;
const debouncedSearch = () => {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
offset.value = 0;
fetchPlayers();
}, 300);
};
// API calls
const fetchPlayers = async () => {
try {
loading.value = true;
error.value = null;
const params = new URLSearchParams();
if (searchQuery.value) params.append('search', searchQuery.value);
if (selectedClubId.value)
params.append('club_id', selectedClubId.value);
if (selectedTeamId.value)
params.append('team_id', selectedTeamId.value);
params.append('limit', limit.value);
params.append('offset', offset.value);
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/players?${params.toString()}`,
{ method: 'GET' }
);
players.value = response.players || [];
totalCount.value = response.total || 0;
} catch (err) {
error.value = err.message;
} finally {
loading.value = false;
}
};
const fetchClubs = async () => {
try {
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/clubs?include_empty=true`,
{ method: 'GET' }
);
clubs.value = response.sort((a, b) => a.name.localeCompare(b.name));
} catch (err) {
console.error('Error fetching clubs:', err);
}
};
const fetchTeams = async () => {
try {
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams`,
{ method: 'GET' }
);
teams.value = response.sort((a, b) => a.name.localeCompare(b.name));
} catch (err) {
console.error('Error fetching teams:', err);
}
};
const fetchSeasons = async () => {
try {
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/seasons`,
{ method: 'GET' }
);
seasons.value = response;
} catch (err) {
console.error('Error fetching seasons:', err);
}
};
const fetchAgeGroups = async () => {
try {
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/age-groups`,
{ method: 'GET' }
);
ageGroups.value = response;
} catch (err) {
console.error('Error fetching age groups:', err);
}
};
const updatePlayer = async () => {
try {
formLoading.value = true;
await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/players/${selectedPlayer.value.id}`,
{
method: 'PUT',
body: JSON.stringify({
display_name: editForm.value.display_name,
player_number: editForm.value.player_number,
positions: editForm.value.positions,
}),
}
);
await fetchPlayers();
closeModals();
} catch (err) {
error.value = err.message;
} finally {
formLoading.value = false;
}
};
const addTeamAssignment = async () => {
try {
formLoading.value = true;
await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/players/${selectedPlayer.value.id}/teams`,
{
method: 'POST',
body: JSON.stringify({
team_id: assignmentForm.value.team_id,
season_id: assignmentForm.value.season_id,
age_group_id: assignmentForm.value.age_group_id,
jersey_number: assignmentForm.value.jersey_number,
is_current: assignmentForm.value.is_current,
}),
}
);
// Refresh player data
await fetchPlayers();
// Refresh selected player's team assignments
const updatedPlayer = players.value.find(
p => p.id === selectedPlayer.value.id
);
if (updatedPlayer) {
selectedPlayer.value = updatedPlayer;
}
// Reset form
assignmentForm.value = {
team_id: null,
season_id: null,
age_group_id: null,
jersey_number: null,
is_current: true,
};
} catch (err) {
error.value = err.message;
} finally {
formLoading.value = false;
}
};
const endTeamAssignment = async assignment => {
if (!confirm('End this team assignment?')) return;
try {
formLoading.value = true;
await authStore.apiRequest(
`${getApiBaseUrl()}/api/admin/players/teams/${assignment.id}/end`,
{
method: 'PUT',
}
);
// Refresh player data
await fetchPlayers();
// Refresh selected player's team assignments
const updatedPlayer = players.value.find(
p => p.id === selectedPlayer.value.id
);
if (updatedPlayer) {
selectedPlayer.value = updatedPlayer;
}
} catch (err) {
error.value = err.message;
} finally {
formLoading.value = false;
}
};
// Modal helpers
const openEditModal = player => {
selectedPlayer.value = player;
editForm.value = {
display_name: player.display_name || '',
player_number: player.player_number || null,
// user_profiles.positions is a TEXT column returned as a JSON string
positions: parsePositions(player.positions),
};
showEditModal.value = true;
};
const openTeamsModal = player => {
selectedPlayer.value = player;
assignmentForm.value = {
team_id: null,
season_id: null,
age_group_id: null,
jersey_number: null,
is_current: true,
};
showTeamsModal.value = true;
};
const closeModals = () => {
showEditModal.value = false;
showTeamsModal.value = false;
showAddModal.value = false;
selectedPlayer.value = null;
};
const openAddModal = () => {
addPlayerForm.value = {
team_id: selectedTeamId.value ?? null,
season_id: null,
age_group_id: null,
jersey_number: null,
first_name: '',
last_name: '',
positions: [],
};
showAddModal.value = true;
};
const submitAddPlayer = async () => {
try {
formLoading.value = true;
error.value = null;
await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${addPlayerForm.value.team_id}/roster`,
{
method: 'POST',
body: JSON.stringify({
season_id: addPlayerForm.value.season_id,
age_group_id: addPlayerForm.value.age_group_id,
jersey_number: addPlayerForm.value.jersey_number,
first_name: addPlayerForm.value.first_name || null,
last_name: addPlayerForm.value.last_name || null,
positions:
addPlayerForm.value.positions.length > 0
? addPlayerForm.value.positions
: null,
}),
}
);
await fetchPlayers();
closeModals();
} catch (err) {
error.value = err.message;
} finally {
formLoading.value = false;
}
};
// Pagination
const previousPage = () => {
if (offset.value > 0) {
offset.value = Math.max(0, offset.value - limit.value);
fetchPlayers();
}
};
const nextPage = () => {
if (offset.value + limit.value < totalCount.value) {
offset.value += limit.value;
fetchPlayers();
}
};
// Helpers
const getInitials = name => {
if (!name) return '?';
return name
.split(' ')
.map(n => n[0])
.join('')
.toUpperCase()
.slice(0, 2);
};
// Lifecycle
onMounted(() => {
fetchPlayers();
fetchClubs();
fetchTeams();
fetchSeasons();
fetchAgeGroups();
});
return {
// State
players,
clubs,
teams,
seasons,
ageGroups,
loading,
formLoading,
error,
searchQuery,
selectedClubId,
selectedTeamId,
offset,
limit,
totalCount,
sourceFilter,
showEditModal,
showTeamsModal,
showAddModal,
selectedPlayer,
editForm,
assignmentForm,
addPlayerForm,
filteredTeams,
visiblePlayers,
// Methods
fetchPlayers,
debouncedSearch,
updatePlayer,
addTeamAssignment,
endTeamAssignment,
openEditModal,
openTeamsModal,
openAddModal,
submitAddPlayer,
closeModals,
previousPage,
nextPage,
getInitials,
};
},
};
</script>
|