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 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1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8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x | <template>
<div
class="modal-overlay"
@click="$emit('close')"
data-testid="roster-manager-overlay"
>
<div
class="modal-content roster-modal"
@click.stop
data-testid="roster-manager"
>
<!-- Header -->
<div class="p-4 border-b border-line flex justify-between items-center">
<h3 class="text-lg font-semibold text-fg">Roster: {{ teamName }}</h3>
<button
@click="$emit('close')"
class="text-fg-muted hover:text-fg"
data-testid="close-roster-button"
>
<svg
class="w-6 h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
<!-- Action Bar -->
<div class="p-4 border-b border-line flex justify-between items-center">
<div class="flex items-center space-x-3">
<!-- Season selector: roster is scoped to (team, season, age group).
Defaults to the current season. -->
<select
v-model.number="selectedSeasonId"
class="px-2 py-1 text-sm bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
data-testid="roster-season-select"
>
<option v-for="s in seasons" :key="s.id" :value="s.id">
{{ s.name }}
</option>
</select>
<!-- Age-group filter: scope the roster to one squad of an
umbrella team (e.g. IFA U15). -->
<select
v-model="ageGroupFilter"
class="px-2 py-1 text-sm bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
data-testid="roster-age-group-filter"
>
<option value="">All age groups</option>
<option v-for="ag in ageGroupOptions" :key="ag.id" :value="ag.id">
{{ ag.name }}
</option>
<option value="none">Unassigned</option>
</select>
<div class="text-sm text-fg-muted">
{{ filteredRoster.length }} player{{
filteredRoster.length !== 1 ? 's' : ''
}}
</div>
<!-- Bulk age-group assignment (SB-69): shows when rows are selected -->
<div
v-if="selectedIds.length"
class="flex items-center space-x-2"
data-testid="bulk-age-group-bar"
>
<span class="text-sm text-fg-muted"
>{{ selectedIds.length }} selected</span
>
<select
v-model.number="bulkAgeGroupId"
class="px-2 py-1 text-sm bg-card text-fg border border-line rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
data-testid="bulk-age-group-select"
>
<option :value="null" disabled>Age group…</option>
<option v-for="ag in ageGroups" :key="ag.id" :value="ag.id">
{{ ag.name }}
</option>
</select>
<button
@click="assignSelected"
:disabled="!bulkAgeGroupId || formLoading"
class="px-3 py-1.5 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md disabled:opacity-50"
data-testid="assign-age-group-button"
>
{{ formLoading ? 'Assigning…' : 'Assign Age Group' }}
</button>
</div>
</div>
<div class="flex space-x-2">
<button
@click="showBulkImportModal = true"
class="px-3 py-1.5 text-sm font-medium text-fg bg-surface-alt hover:bg-line rounded-md"
data-testid="bulk-import-button"
>
Bulk Import
</button>
<button
@click="showAddModal = true"
class="px-3 py-1.5 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md"
data-testid="add-player-button"
>
+ Add Player
</button>
</div>
</div>
<!-- Loading State -->
<div
v-if="loading"
class="flex justify-center py-12"
data-testid="roster-loading"
>
<div
class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600"
></div>
</div>
<!-- Error State -->
<div
v-else-if="error"
class="m-4 bg-red-50 border border-red-200 rounded-md p-4"
data-testid="roster-error"
>
<div class="text-red-800">{{ error }}</div>
</div>
<!-- Empty State -->
<div
v-else-if="filteredRoster.length === 0"
class="p-8 text-center text-fg-muted"
data-testid="roster-empty"
>
<div class="text-4xl mb-2">👤</div>
<p v-if="roster.length === 0">No players on roster yet</p>
<p v-else>No players in this age group</p>
<p class="text-sm mt-1">Add players individually or use bulk import</p>
</div>
<!-- Roster Table -->
<div v-else class="overflow-x-auto" data-testid="roster-table-container">
<table class="min-w-full divide-y divide-line">
<thead class="bg-surface-alt">
<tr>
<th class="px-4 py-3 text-left w-10">
<input
type="checkbox"
:checked="allSelected"
@change="toggleSelectAll"
class="rounded border-line text-brand-600 focus:ring-brand-500"
title="Select all"
data-testid="select-all-checkbox"
/>
</th>
<th
class="px-4 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider w-16"
>
#
</th>
<th
class="px-4 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider"
>
Name
</th>
<th
class="px-4 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider w-28"
>
Age Group
</th>
<th
class="px-4 py-3 text-center text-xs font-medium text-fg-muted uppercase tracking-wider w-20"
>
Account
</th>
<th
class="px-4 py-3 text-left text-xs font-medium text-fg-muted uppercase tracking-wider"
>
Positions
</th>
<th
class="px-4 py-3 text-right text-xs font-medium text-fg-muted uppercase tracking-wider w-40"
>
Actions
</th>
</tr>
</thead>
<tbody class="bg-card divide-y divide-line">
<tr
v-for="player in filteredRoster"
:key="player.id"
:data-testid="`roster-row-${player.id}`"
>
<td class="px-4 py-3 whitespace-nowrap">
<input
type="checkbox"
:value="player.id"
v-model="selectedIds"
class="rounded border-line text-brand-600 focus:ring-brand-500"
:data-testid="`select-player-${player.id}`"
/>
</td>
<td class="px-4 py-3 whitespace-nowrap text-sm font-bold text-fg">
{{ player.jersey_number }}
</td>
<td class="px-4 py-3 whitespace-nowrap text-sm text-fg">
{{ player.display_name }}
</td>
<!-- Age-group badge + inline single-row quick-assign (SB-69) -->
<td class="px-4 py-3 whitespace-nowrap text-sm">
<select
:value="player.age_group_id ?? ''"
@change="event => quickAssign(player, event.target.value)"
:disabled="formLoading"
class="px-2 py-1 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-brand-500"
:class="
player.age_group_id
? 'border-line text-fg bg-card'
: 'border-amber-300 text-amber-700 bg-amber-50'
"
:data-testid="`row-age-group-${player.id}`"
>
<option value="">—</option>
<option v-for="ag in ageGroups" :key="ag.id" :value="ag.id">
{{ ag.name }}
</option>
</select>
</td>
<td class="px-4 py-3 whitespace-nowrap text-center">
<span
v-if="player.has_account"
class="text-green-600"
title="Linked to account"
>
✓
</span>
<span v-else class="text-fg-muted">—</span>
</td>
<td class="px-4 py-3 whitespace-nowrap text-sm text-fg-muted">
<div class="flex flex-wrap gap-1">
<span
v-for="pos in player.positions || []"
:key="pos"
class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-surface-alt text-fg"
>
{{ pos }}
</span>
</div>
</td>
<td
class="px-4 py-3 whitespace-nowrap text-right text-sm font-medium space-x-2"
>
<button
@click="openEditModal(player)"
class="text-brand-600 hover:text-brand-900 dark:text-brand-300 dark:hover:text-brand-200"
title="Edit name/positions"
data-testid="edit-player-button"
>
Edit
</button>
<button
@click="openChangeNumberModal(player)"
class="text-fg-muted hover:text-fg"
title="Change jersey number"
data-testid="change-number-button"
>
#
</button>
<button
v-if="!player.has_account"
@click="createInvite(player)"
class="text-green-600 hover:text-green-900"
title="Send invite"
data-testid="send-invite-button"
>
✉
</button>
<button
@click="deletePlayer(player)"
class="text-red-600 hover:text-red-900"
title="Remove from roster"
data-testid="delete-player-button"
>
✕
</button>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Add Player Modal -->
<div
v-if="showAddModal"
class="modal-overlay inner-modal"
@click="closeInnerModals"
data-testid="add-player-modal-overlay"
>
<div
class="modal-content inner-modal-content"
@click.stop
data-testid="add-player-modal"
>
<div class="p-6">
<h4 class="text-lg font-medium text-fg mb-4">Add Player</h4>
<form @submit.prevent="addPlayer" data-testid="add-player-form">
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2">
Jersey Number <span class="text-red-500">*</span>
</label>
<input
v-model.number="addForm.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"
placeholder="1-99"
data-testid="jersey-number-input"
/>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>First Name</label
>
<input
v-model="addForm.first_name"
type="text"
maxlength="100"
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"
placeholder="Optional"
data-testid="first-name-input"
/>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Last Name</label
>
<input
v-model="addForm.last_name"
type="text"
maxlength="100"
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"
placeholder="Optional"
data-testid="last-name-input"
/>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Age Group</label
>
<select
v-model="addForm.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"
data-testid="add-player-age-group"
>
<option :value="null">No age group</option>
<option v-for="ag in ageGroups" :key="ag.id" :value="ag.id">
{{ ag.name }}
</option>
</select>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Positions</label
>
<PositionPicker v-model="addForm.positions" />
</div>
<div class="flex justify-end space-x-3">
<button
type="button"
@click="closeInnerModals"
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="formLoading"
class="px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md disabled:opacity-50"
data-testid="save-player-button"
>
{{ formLoading ? 'Adding...' : 'Add Player' }}
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Player Modal -->
<div
v-if="showEditModal"
class="modal-overlay inner-modal"
@click="closeInnerModals"
data-testid="edit-player-modal-overlay"
>
<div
class="modal-content inner-modal-content"
@click.stop
data-testid="edit-player-modal"
>
<div class="p-6">
<h4 class="text-lg font-medium text-fg mb-4">
Edit Player #{{ editingPlayer?.jersey_number }}
</h4>
<form @submit.prevent="updatePlayer" data-testid="edit-player-form">
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>First Name</label
>
<input
v-model="editForm.first_name"
type="text"
maxlength="100"
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="edit-first-name-input"
/>
</div>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Last Name</label
>
<input
v-model="editForm.last_name"
type="text"
maxlength="100"
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="edit-last-name-input"
/>
</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 space-x-3">
<button
type="button"
@click="closeInnerModals"
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="formLoading"
class="px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md disabled:opacity-50"
data-testid="update-player-button"
>
{{ formLoading ? 'Saving...' : 'Save Changes' }}
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Change Number Modal -->
<div
v-if="showChangeNumberModal"
class="modal-overlay inner-modal"
@click="closeInnerModals"
data-testid="change-number-modal-overlay"
>
<div
class="modal-content inner-modal-content"
@click.stop
data-testid="change-number-modal"
>
<div class="p-6">
<h4 class="text-lg font-medium text-fg mb-4">
Change Jersey Number
</h4>
<p class="text-sm text-fg-muted mb-4">
Current: #{{ editingPlayer?.jersey_number }} ({{
editingPlayer?.display_name
}})
</p>
<form
@submit.prevent="changeJerseyNumber"
data-testid="change-number-form"
>
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2">
New Number <span class="text-red-500">*</span>
</label>
<input
v-model.number="newJerseyNumber"
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"
data-testid="new-jersey-number-input"
/>
</div>
<div class="flex justify-end space-x-3">
<button
type="button"
@click="closeInnerModals"
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="formLoading"
class="px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md disabled:opacity-50"
data-testid="confirm-change-number-button"
>
{{ formLoading ? 'Changing...' : 'Change Number' }}
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Bulk Import Modal -->
<div
v-if="showBulkImportModal"
class="modal-overlay inner-modal"
@click="closeInnerModals"
data-testid="bulk-import-modal-overlay"
>
<div
class="modal-content inner-modal-content"
@click.stop
data-testid="bulk-import-modal"
>
<div class="p-6">
<h4 class="text-lg font-medium text-fg mb-4">
Bulk Import Players
</h4>
<p class="text-sm text-fg-muted mb-4">
One player per line: a jersey number, optionally followed by last
and first name (e.g. <code>7, Smith, Gabe</code>). Names can be
added later.
</p>
<form @submit.prevent="bulkImport" data-testid="bulk-import-form">
<div class="mb-4">
<label class="block text-sm font-medium text-fg mb-2"
>Age Group</label
>
<select
v-model="bulkImportAgeGroupId"
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="bulk-import-age-group"
>
<option :value="null">No age group</option>
<option v-for="ag in ageGroups" :key="ag.id" :value="ag.id">
{{ ag.name }}
</option>
</select>
<p class="mt-1 text-xs text-fg-muted">
Jersey numbers are unique within an age group — umbrella clubs
can reuse numbers across squads.
</p>
</div>
<div class="mb-4">
<textarea
v-model="bulkImportText"
rows="8"
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 font-mono"
placeholder="1 7, Smith, Gabe 10, Jones 11 23"
data-testid="bulk-import-textarea"
></textarea>
</div>
<div class="flex justify-end space-x-3">
<button
type="button"
@click="closeInnerModals"
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="formLoading || !bulkImportText.trim()"
class="px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md disabled:opacity-50"
data-testid="confirm-bulk-import-button"
>
{{ formLoading ? 'Importing...' : 'Import Players' }}
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Invite Created Modal -->
<div
v-if="showInviteModal"
class="modal-overlay inner-modal"
@click="closeInnerModals"
data-testid="invite-created-modal-overlay"
>
<div
class="modal-content inner-modal-content"
@click.stop
data-testid="invite-created-modal"
>
<div class="p-6 text-center">
<div class="text-4xl mb-4">✉️</div>
<h4 class="text-lg font-medium text-fg mb-2">Invite Created!</h4>
<p class="text-sm text-fg-muted mb-4">
Share this code with #{{ invitePlayer?.jersey_number }}:
</p>
<div class="bg-surface-alt rounded-lg p-4 mb-4">
<code
class="text-lg font-mono font-bold text-brand-600 dark:text-brand-300"
>{{ inviteCode }}</code
>
</div>
<button
@click="copyInviteCode"
class="px-4 py-2 text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 rounded-md mr-2"
>
Copy Code
</button>
<button
@click="closeInnerModals"
class="px-4 py-2 text-sm font-medium text-fg bg-surface-alt hover:bg-line rounded-md"
>
Close
</button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import { ref, computed, onMounted, watch } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '@/config/api';
import PositionPicker from '@/components/shared/PositionPicker.vue';
export default {
name: 'RosterManager',
components: {
PositionPicker,
},
props: {
teamId: {
type: Number,
required: true,
},
teamName: {
type: String,
required: true,
},
seasonId: {
type: Number,
required: true,
},
ageGroupId: {
type: Number,
default: null,
},
// Age groups this team actually fields (from team.age_groups). When
// provided, the age-group filter/selectors are scoped to these instead
// of every age group globally.
teamAgeGroups: {
type: Array,
default: () => [],
},
},
emits: ['close'],
setup(props) {
const authStore = useAuthStore();
// State
const roster = ref([]);
const loading = ref(false);
const formLoading = ref(false);
const error = ref(null);
// Modal states
const showAddModal = ref(false);
const showEditModal = ref(false);
const showChangeNumberModal = ref(false);
const showBulkImportModal = ref(false);
const showInviteModal = ref(false);
// Form data
const addForm = ref({
jersey_number: null,
first_name: '',
last_name: '',
positions: [],
age_group_id: props.ageGroupId ?? null,
});
const editForm = ref({
first_name: '',
last_name: '',
positions: [],
});
const editingPlayer = ref(null);
const newJerseyNumber = ref(null);
const bulkImportText = ref('');
const bulkImportAgeGroupId = ref(props.ageGroupId ?? null);
const inviteCode = ref('');
const invitePlayer = ref(null);
// Season selector: default to the season AdminTeams considers current
// (newest); the roster is scoped to (team, season, age group).
const seasons = ref([]);
const selectedSeasonId = ref(props.seasonId);
// Age-group assignment (SB-69)
const ageGroups = ref([]);
const selectedIds = ref([]);
const bulkAgeGroupId = ref(null);
// Age-group filter: scope the visible roster to one squad of an umbrella
// team. '' = all, 'none' = players with no age group, else the id.
// Default to "All" (so untagged players stay visible and can be assigned),
// except when the team fields exactly one age group.
const ageGroupFilter = ref(
props.teamAgeGroups.length === 1 ? props.teamAgeGroups[0].id : ''
);
// Selector options: the team's fielded age groups when known, else the
// global list fetched from /api/age-groups.
const ageGroupOptions = computed(() =>
props.teamAgeGroups.length ? props.teamAgeGroups : ageGroups.value
);
const filteredRoster = computed(() => {
if (ageGroupFilter.value === '') return roster.value;
if (ageGroupFilter.value === 'none') {
return roster.value.filter(p => p.age_group_id == null);
}
return roster.value.filter(
p => p.age_group_id === Number(ageGroupFilter.value)
);
});
// Keep Add Player / Bulk Import defaulting to the chosen squad.
const currentFilterAgeGroupId = computed(() => {
const v = ageGroupFilter.value;
return v === '' || v === 'none' ? null : Number(v);
});
watch(currentFilterAgeGroupId, id => {
addForm.value.age_group_id = id;
bulkImportAgeGroupId.value = id;
});
// Seed the add/bulk defaults from the initial filter value.
addForm.value.age_group_id = currentFilterAgeGroupId.value;
bulkImportAgeGroupId.value = currentFilterAgeGroupId.value;
const allSelected = computed(
() =>
filteredRoster.value.length > 0 &&
filteredRoster.value.every(p => selectedIds.value.includes(p.id))
);
// Fetch roster data
const fetchRoster = async () => {
try {
loading.value = true;
error.value = null;
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/roster?season_id=${selectedSeasonId.value}`,
{ method: 'GET' }
);
roster.value = response.roster || [];
} catch (err) {
error.value = err.message || 'Failed to load roster';
console.error('Error fetching roster:', err);
} finally {
loading.value = false;
}
};
// Fetch age groups for the assignment dropdowns (SB-69)
const fetchAgeGroups = async () => {
try {
ageGroups.value = await authStore.apiRequest(
`${getApiBaseUrl()}/api/age-groups`,
{ method: 'GET' }
);
} catch (err) {
console.error('Error fetching age groups:', err);
}
};
const fetchSeasons = async () => {
try {
seasons.value = await authStore.apiRequest(
`${getApiBaseUrl()}/api/seasons`,
{ method: 'GET' }
);
} catch (err) {
console.error('Error fetching seasons:', err);
}
};
// Refetch the roster when the season changes.
watch(selectedSeasonId, () => {
selectedIds.value = [];
fetchRoster();
});
// Select-all toggle for the bulk assignment (SB-69) — scoped to the
// currently visible (filtered) rows.
const toggleSelectAll = () => {
selectedIds.value = allSelected.value
? []
: filteredRoster.value.map(p => p.id);
};
// Assign an age group to a set of players via the bulk endpoint (SB-69)
const assignAgeGroup = async (ids, ageGroupId) => {
try {
formLoading.value = true;
error.value = null;
await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/players/age-group`,
{
method: 'PATCH',
body: JSON.stringify({
season_id: selectedSeasonId.value,
player_ids: ids,
age_group_id: ageGroupId,
}),
}
);
await fetchRoster();
selectedIds.value = [];
bulkAgeGroupId.value = null;
} catch (err) {
error.value = err.message || 'Failed to assign age group';
} finally {
formLoading.value = false;
}
};
// Apply the chosen age group to all checked players
const assignSelected = () => {
if (bulkAgeGroupId.value && selectedIds.value.length) {
assignAgeGroup([...selectedIds.value], bulkAgeGroupId.value);
}
};
// Single-row quick assign from the inline dropdown
const quickAssign = (player, value) => {
const ageGroupId = Number(value);
if (ageGroupId) {
assignAgeGroup([player.id], ageGroupId);
}
};
// Add a single player
const addPlayer = async () => {
try {
formLoading.value = true;
error.value = null;
const playerData = {
jersey_number: addForm.value.jersey_number,
first_name: addForm.value.first_name || null,
last_name: addForm.value.last_name || null,
positions:
addForm.value.positions.length > 0 ? addForm.value.positions : null,
season_id: selectedSeasonId.value,
age_group_id: addForm.value.age_group_id ?? null,
};
await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/roster`,
{
method: 'POST',
body: JSON.stringify(playerData),
}
);
await fetchRoster();
closeInnerModals();
resetAddForm();
} catch (err) {
error.value = err.message || 'Failed to add player';
} finally {
formLoading.value = false;
}
};
// Update player name/positions
const updatePlayer = async () => {
if (!editingPlayer.value) return;
try {
formLoading.value = true;
error.value = null;
const updateData = {
first_name: editForm.value.first_name || null,
last_name: editForm.value.last_name || null,
// Always send the array: [] clears positions (null would mean
// "keep current" to the backend, silently ignoring a clear).
positions: editForm.value.positions,
};
await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/roster/${editingPlayer.value.id}`,
{
method: 'PUT',
body: JSON.stringify(updateData),
}
);
await fetchRoster();
closeInnerModals();
} catch (err) {
error.value = err.message || 'Failed to update player';
} finally {
formLoading.value = false;
}
};
// Change jersey number
const changeJerseyNumber = async () => {
if (!editingPlayer.value || !newJerseyNumber.value) return;
try {
formLoading.value = true;
error.value = null;
await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/roster/${editingPlayer.value.id}/number`,
{
method: 'PUT',
body: JSON.stringify({ new_number: newJerseyNumber.value }),
}
);
await fetchRoster();
closeInnerModals();
} catch (err) {
error.value = err.message || 'Failed to change jersey number';
} finally {
formLoading.value = false;
}
};
// Delete player
const deletePlayer = async player => {
if (
!confirm(
`Remove #${player.jersey_number} (${player.display_name}) from roster?`
)
) {
return;
}
try {
error.value = null;
await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/roster/${player.id}`,
{ method: 'DELETE' }
);
await fetchRoster();
} catch (err) {
error.value = err.message || 'Failed to remove player';
}
};
// Bulk import players
const bulkImport = async () => {
try {
formLoading.value = true;
error.value = null;
// Parse lines: "7" or "7, Lastname" or "7, Lastname, Firstname"
const players = bulkImportText.value
.split('\n')
.map(line => line.trim())
.filter(Boolean)
.map(line => {
const [numPart, lastName, firstName] = line
.split(',')
.map(s => s.trim());
const num = parseInt(numPart);
if (isNaN(num) || num < 1 || num > 99) return null;
const entry = { jersey_number: num };
if (lastName) entry.last_name = lastName;
if (firstName) entry.first_name = firstName;
return entry;
})
.filter(Boolean);
if (players.length === 0) {
error.value = 'No valid jersey numbers found';
formLoading.value = false;
return;
}
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/teams/${props.teamId}/roster/bulk`,
{
method: 'POST',
body: JSON.stringify({
season_id: selectedSeasonId.value,
age_group_id: bulkImportAgeGroupId.value ?? null,
players: players,
}),
}
);
const created = response.created_count || 0;
const skipped = response.skipped_count || 0;
if (skipped > 0) {
alert(
`Imported ${created} players. Skipped ${skipped} (already exist).`
);
}
await fetchRoster();
closeInnerModals();
bulkImportText.value = '';
} catch (err) {
error.value = err.message || 'Failed to import players';
} finally {
formLoading.value = false;
}
};
// Create invite for a player
const createInvite = async player => {
try {
error.value = null;
const inviteData = {
invite_type: 'team_player',
team_id: props.teamId,
age_group_id: props.ageGroupId,
player_id: player.id,
};
const response = await authStore.apiRequest(
`${getApiBaseUrl()}/api/invites/team-manager/team-player`,
{
method: 'POST',
body: JSON.stringify(inviteData),
}
);
inviteCode.value = response.invite_code;
invitePlayer.value = player;
showInviteModal.value = true;
} catch (err) {
error.value = err.message || 'Failed to create invite';
}
};
// Copy invite code to clipboard
const copyInviteCode = async () => {
try {
await navigator.clipboard.writeText(inviteCode.value);
alert('Invite code copied!');
} catch (err) {
console.error('Failed to copy:', err);
}
};
// Modal helpers
const openEditModal = player => {
editingPlayer.value = player;
editForm.value = {
first_name: player.first_name || '',
last_name: player.last_name || '',
positions: player.positions ? [...player.positions] : [],
};
showEditModal.value = true;
};
const openChangeNumberModal = player => {
editingPlayer.value = player;
newJerseyNumber.value = player.jersey_number;
showChangeNumberModal.value = true;
};
const closeInnerModals = () => {
showAddModal.value = false;
showEditModal.value = false;
showChangeNumberModal.value = false;
showBulkImportModal.value = false;
showInviteModal.value = false;
editingPlayer.value = null;
newJerseyNumber.value = null;
};
const resetAddForm = () => {
addForm.value = {
jersey_number: null,
first_name: '',
last_name: '',
positions: [],
// Default to the age group currently being filtered/managed.
age_group_id: currentFilterAgeGroupId.value,
};
};
// Initialize
onMounted(() => {
fetchRoster();
fetchAgeGroups();
fetchSeasons();
});
return {
roster,
loading,
formLoading,
error,
showAddModal,
showEditModal,
showChangeNumberModal,
showBulkImportModal,
showInviteModal,
addForm,
editForm,
editingPlayer,
newJerseyNumber,
bulkImportText,
bulkImportAgeGroupId,
inviteCode,
invitePlayer,
seasons,
selectedSeasonId,
ageGroups,
ageGroupFilter,
ageGroupOptions,
filteredRoster,
selectedIds,
bulkAgeGroupId,
allSelected,
toggleSelectAll,
assignSelected,
quickAssign,
fetchRoster,
addPlayer,
updatePlayer,
changeJerseyNumber,
deletePlayer,
bulkImport,
createInvite,
copyInviteCode,
openEditModal,
openChangeNumberModal,
closeInnerModals,
};
},
};
</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;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background: rgb(var(--color-card));
border-radius: 8px;
max-width: 800px;
width: 95%;
max-height: 90vh;
overflow-y: auto;
}
.roster-modal {
max-width: 900px;
}
.inner-modal {
z-index: 1100;
}
.inner-modal-content {
max-width: 500px;
}
</style>
|