Skip to content

Commit

Permalink
export urls only for selected participants
Browse files Browse the repository at this point in the history
  • Loading branch information
buckhalt committed Jan 26, 2024
1 parent d64e38d commit c6ab595
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use client';

import { useEffect, useState } from 'react';

import { Button } from '~/components/ui/Button';
Expand All @@ -23,14 +21,19 @@ type ParticipantSelectionDropdownProps = {
export function ParticipantSelectionDropdown({
participants,
disabled,
setParticipantsToExport,
}: ParticipantSelectionDropdownProps) {
const [selectedParticipants, setSelectedParticipants] = useState<
Participant[]
>([]);

useEffect(() => {
setSelectedParticipants(participants);
}, [participants]);
}, [participants, setParticipantsToExport]);

useEffect(() => {
setParticipantsToExport(selectedParticipants);
}, [selectedParticipants, setParticipantsToExport]);

return (
<DropdownMenu>
Expand Down
13 changes: 11 additions & 2 deletions app/(dashboard)/dashboard/_components/RecruitmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const RecruitmentModal = ({
api.protocol.get.all.useQuery();
const [protocols, setProtocols] = useState<Protocol[]>([]);
const [participants, setParticipants] = useState<Participant[]>([]);
const [participantsToExport, setParticipantsToExport] = useState<
Participant[] | undefined
>([]);
const [selectedProtocol, setSelectedProtocol] = useState<Protocol>();

const { data: participantData, isLoading: isLoadingParticipants } =
Expand All @@ -50,6 +53,12 @@ export const RecruitmentModal = ({
}
}, [participantData]);

useEffect(() => {
if (!allowSelectParticipants) {
setParticipantsToExport(participants);
}
}, [allowSelectParticipants, participants]);

return (
<Dialog onOpenChange={() => setSelectedProtocol(undefined)}>
<DialogTrigger asChild>
Expand Down Expand Up @@ -89,13 +98,13 @@ export const RecruitmentModal = ({
<ParticipantSelectionDropdown
participants={participants}
disabled={!selectedProtocol}
setParticipantsToExport={setParticipants}
setParticipantsToExport={setParticipantsToExport}
/>
)}

<ExportCSVParticipants
protocolId={selectedProtocol?.id}
participants={participants}
participants={participantsToExport}
disabled={isLoadingParticipants || !selectedProtocol}
/>
</div>
Expand Down

0 comments on commit c6ab595

Please sign in to comment.