From 730f746e657728de0b48de42532d12c7c85fba77 Mon Sep 17 00:00:00 2001 From: ThomasDos Date: Thu, 29 Aug 2024 14:51:45 +0200 Subject: [PATCH] feat(admin): rework autocomplete flow in CandidateInformation - Enhanced the autocomplete functionality for address input. - Added a toggle to switch between manual address entry and autocomplete suggestions. --- .../_components/CandidateInformationForm.tsx | 80 +++++++++++-------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/summary/candidate-information/_components/CandidateInformationForm.tsx b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/summary/candidate-information/_components/CandidateInformationForm.tsx index afde519c3..038475a27 100644 --- a/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/summary/candidate-information/_components/CandidateInformationForm.tsx +++ b/packages/reva-admin-react/src/app/(aap)/candidacies/[candidacyId]/summary/candidate-information/_components/CandidateInformationForm.tsx @@ -42,11 +42,11 @@ const CandidateInformationForm = ({ useUpdateCandidateInformation(candidacyId); const candidate = candidacy?.candidate; - const isAddressAlreadyComplete = + const isAddressAlreadyCompleted = !!candidate?.street && !!candidate?.zip && !!candidate?.city; - const [completeAddressSelected, setCompleteAddressSelected] = useState( - isAddressAlreadyComplete, + const [manualAddressSelected, setManualAddress] = useState( + isAddressAlreadyCompleted, ); const franceId = countries?.find((c) => c.label === "France")?.id; @@ -195,7 +195,16 @@ const CandidateInformationForm = ({ setValue("street", street, { shouldDirty: true }); setValue("zip", zip, { shouldDirty: true }); setValue("city", city, { shouldDirty: true }); - setCompleteAddressSelected(false); + setManualAddress(false); + }; + + const handleToggleManualAddress = ( + e: React.ChangeEvent, + ) => { + setManualAddress(e.target.checked); + setValue("street", ""); + setValue("zip", ""); + setValue("city", ""); }; return ( @@ -322,10 +331,20 @@ const CandidateInformationForm = ({ Informations de contact
- + {manualAddressSelected ? ( + + ) : ( + + )} setCompleteAddressSelected(e.target.checked), + checked: manualAddressSelected, + onChange: handleToggleManualAddress, }, }, ]} className="mb-0" /> - {completeAddressSelected && ( -
- - - -
- )} +
+ + +