diff --git a/app/(dashboard)/dashboard/_components/ParticipantSelectionDropdown.tsx b/app/(dashboard)/dashboard/_components/ParticipantSelectionDropdown.tsx index 1734a1c5..300310d7 100644 --- a/app/(dashboard)/dashboard/_components/ParticipantSelectionDropdown.tsx +++ b/app/(dashboard)/dashboard/_components/ParticipantSelectionDropdown.tsx @@ -1,5 +1,3 @@ -'use client'; - import { useEffect, useState } from 'react'; import { Button } from '~/components/ui/Button'; @@ -23,6 +21,7 @@ type ParticipantSelectionDropdownProps = { export function ParticipantSelectionDropdown({ participants, disabled, + setParticipantsToExport, }: ParticipantSelectionDropdownProps) { const [selectedParticipants, setSelectedParticipants] = useState< Participant[] @@ -30,7 +29,11 @@ export function ParticipantSelectionDropdown({ useEffect(() => { setSelectedParticipants(participants); - }, [participants]); + }, [participants, setParticipantsToExport]); + + useEffect(() => { + setParticipantsToExport(selectedParticipants); + }, [selectedParticipants, setParticipantsToExport]); return ( diff --git a/app/(dashboard)/dashboard/_components/RecruitmentModal.tsx b/app/(dashboard)/dashboard/_components/RecruitmentModal.tsx index 76d4779d..4821ebf9 100644 --- a/app/(dashboard)/dashboard/_components/RecruitmentModal.tsx +++ b/app/(dashboard)/dashboard/_components/RecruitmentModal.tsx @@ -33,6 +33,9 @@ export const RecruitmentModal = ({ api.protocol.get.all.useQuery(); const [protocols, setProtocols] = useState([]); const [participants, setParticipants] = useState([]); + const [participantsToExport, setParticipantsToExport] = useState< + Participant[] | undefined + >([]); const [selectedProtocol, setSelectedProtocol] = useState(); const { data: participantData, isLoading: isLoadingParticipants } = @@ -50,6 +53,12 @@ export const RecruitmentModal = ({ } }, [participantData]); + useEffect(() => { + if (!allowSelectParticipants) { + setParticipantsToExport(participants); + } + }, [allowSelectParticipants, participants]); + return ( setSelectedProtocol(undefined)}> @@ -89,13 +98,13 @@ export const RecruitmentModal = ({ )}