Skip to content

Commit

Permalink
Bring back waiting list (#9901)
Browse files Browse the repository at this point in the history
* bring back waiting list code

* correctly sort users

* remove span

* remove unnecessary cell in footer
  • Loading branch information
FinnIckler authored Sep 4, 2024
1 parent 03bc485 commit 7317dea
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function RegistrationActions({
const anyRejectable = pending.length < selectedCount;
const anyApprovable = accepted.length < selectedCount;
const anyCancellable = cancelled.length < selectedCount;
// const anyWaitlistable = waiting.length < selectedCount;
const anyWaitlistable = waiting.length < selectedCount;

const selectedEmails = [...pending, ...accepted, ...cancelled, ...waiting]
.map((userId) => userEmailMap[userId])
Expand Down Expand Up @@ -139,18 +139,18 @@ export default function RegistrationActions({
</Button>
)}

{/* {anyWaitlistable && ( */}
{/* <Button */}
{/* color="yellow" */}
{/* onClick={() => changeStatus( */}
{/* [...pending, ...cancelled, ...accepted], */}
{/* 'waiting_list', */}
{/* )} */}
{/* > */}
{/* <Icon name="hourglass" /> */}
{/* {i18n.t('competitions.registration_v2.update.move_waiting')} */}
{/* </Button> */}
{/* )} */}
{anyWaitlistable && (
<Button
color="yellow"
onClick={() => changeStatus(
[...pending, ...cancelled, ...accepted],
'waiting_list',
)}
>
<Icon name="hourglass" />
{i18n.t('competitions.registration_v2.update.move_waiting')}
</Button>
)}

{anyCancellable && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function RegistrationAdministrationList({ competitionInfo }) {

const queryClient = useQueryClient();

// const [editable, setEditable] = useCheckboxState(false);
const [editable, setEditable] = useCheckboxState(false);

const dispatchStore = useDispatch();

Expand All @@ -137,6 +137,7 @@ export default function RegistrationAdministrationList({ competitionInfo }) {
const {
isLoading: isRegistrationsLoading,
data: registrations,
refetch,
} = useQuery({
queryKey: ['registrations-admin', competitionInfo.id],
queryFn: () => getAllRegistrations(competitionInfo.id),
Expand Down Expand Up @@ -274,26 +275,25 @@ export default function RegistrationAdministrationList({ competitionInfo }) {
),
[registrationsWithUser],
);

// const handleOnDragEnd = async (result) => {
// if (!result.destination) return;
// if (result.destination.index === result.source.index) return;
//
// updateRegistrationMutation({
// competition_id: competitionInfo.id,
// requests: [{
// user_id: waiting[result.source.index].user_id,
// competing: {
// waiting_list_position: waiting[result.destination.index].competing.waiting_list_position,
// },
// }],
// }, {
// onSuccess: () => {
// // We need to get the information for all Competitors if you change the waiting list position
// refetch();
// },
// });
// };
const handleOnDragEnd = useMemo(() => async (result) => {
if (!result.destination) return;
if (result.destination.index === result.source.index) return;
const waitingSorted = waiting.toSorted((a, b) => a.competing.waiting_list_position - b.competing.waiting_list_position);
updateRegistrationMutation({
competition_id: competitionInfo.id,
requests: [{
user_id: waitingSorted[result.source.index].user_id,
competing: {
waiting_list_position: waitingSorted[result.destination.index].competing.waiting_list_position,
},
}],
}, {
onSuccess: () => {
// We need to get the information for all Competitors if you change the waiting list position
refetch();
},
});
}, [competitionInfo.id, refetch, updateRegistrationMutation, waiting]);

return isRegistrationsLoading || infoLoading ? (
<Loading />
Expand Down Expand Up @@ -373,34 +373,33 @@ export default function RegistrationAdministrationList({ competitionInfo }) {
sortColumn={sortColumn}
competitionInfo={competitionInfo}
/>
{/* Disable Waiting List Administration until we fix moving people around on the waitinglist */}
{/* <Header> */}
{/* {i18n.t('registrations.list.waiting_list')} */}
{/* {' '} */}
{/* ( */}
{/* {waiting.length} */}
{/* ) */}
{/* </Header> */}

{/* <Checkbox toggle value={editable} onChange={setEditable} label="Enable Waiting List Edit Mode" /> */}

{/* <RegistrationAdministrationTable */}
{/* columnsExpanded={expandedColumns} */}
{/* selected={partitionedSelected.waiting} */}
{/* select={select} */}
{/* unselect={unselect} */}
{/* competition_id={competitionInfo.id} */}
{/* changeSortColumn={changeSortColumn} */}
{/* sortDirection={sortDirection} */}
{/* sortColumn={sortColumn} */}
{/* competitionInfo={competitionInfo} */}
{/* registrations={waiting.toSorted( */}
{/* (a, b) => a.competing.waiting_list_position - b.competing.waiting_list_position, */}
{/* )} */}
{/* handleOnDragEnd={handleOnDragEnd} */}
{/* draggable={editable} */}
{/* sortable={false} */}
{/* /> */}
<Header>
{i18n.t('registrations.list.waiting_list')}
{' '}
(
{waiting.length}
)
</Header>

<Checkbox toggle value={editable} onChange={setEditable} label="Enable Waiting List Edit Mode" />

<RegistrationAdministrationTable
columnsExpanded={expandedColumns}
selected={partitionedSelected.waiting}
select={select}
unselect={unselect}
competition_id={competitionInfo.id}
changeSortColumn={changeSortColumn}
sortDirection={sortDirection}
sortColumn={sortColumn}
competitionInfo={competitionInfo}
registrations={waiting.toSorted(
(a, b) => a.competing.waiting_list_position - b.competing.waiting_list_position,
)}
handleOnDragEnd={handleOnDragEnd}
draggable={editable}
sortable={false}
/>

<Header>
{i18n.t('registrations.list.deleted_registrations')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export default function RegistrationAdministrationTableFooter({
<Table.Cell />
<Table.Cell />
<Table.Cell />
<Table.Cell />
</Table.Row>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ export default function RegistrationEditor({ competitor, competitionInfo }) {
disabled={registrationEditDeadlinePassed}
onChange={(event, data) => setStatus(data.value)}
/>
{/* <Form.Checkbox */}
{/* radio */}
{/* label="Waiting List" */}
{/* name="checkboxRadioGroup" */}
{/* value="waiting_list" */}
{/* checked={status === 'waiting_list'} */}
{/* disabled={registrationEditDeadlinePassed} */}
{/* onChange={(event, data) => setStatus(data.value)} */}
{/* /> */}
<Form.Checkbox
radio
label="Waiting List"
name="checkboxRadioGroup"
value="waiting_list"
checked={status === 'waiting_list'}
disabled={registrationEditDeadlinePassed}
onChange={(event, data) => setStatus(data.value)}
/>
<Form.Checkbox
radio
label="Cancelled"
Expand Down

0 comments on commit 7317dea

Please sign in to comment.