From c64a5a3d00e1bc02a25a2b0c6ff770f48f07392d Mon Sep 17 00:00:00 2001 From: Leon Serfaty G Date: Fri, 18 Jul 2025 04:41:27 +0000 Subject: [PATCH] onthis step, "No" is preselected and I have to click on that "No " optio --- .../cost-estimator/step-7-illustrations.tsx | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/components/cost-estimator/step-7-illustrations.tsx b/src/components/cost-estimator/step-7-illustrations.tsx index 2fd8fac..e87aa79 100644 --- a/src/components/cost-estimator/step-7-illustrations.tsx +++ b/src/components/cost-estimator/step-7-illustrations.tsx @@ -1,3 +1,4 @@ + "use client"; import type { FormData, IllustrationSelection } from './cost-estimator-form'; @@ -56,45 +57,55 @@ const calculateHours = ( export function Step7Illustrations({ onNext, onBack, onUpdateData, formData }: Step7Props) { const [selections, setSelections] = useState(formData.illustrations); - const [noIllustrations, setNoIllustrations] = useState(false); + const [noIllustrations, setNoIllustrations] = useState( + !formData.illustrations.has2d && !formData.illustrations.has3d + ); useEffect(() => { - const no2d = !selections.has2d || selections.is2dAnimated === null; - const no3d = !selections.has3d || selections.is3dAnimated === null; - const noIllustrationsSelected = !selections.has2d && !selections.has3d; - setNoIllustrations(noIllustrationsSelected); - }, [selections]); + onUpdateData({ illustrations: selections }); + }, [selections, onUpdateData]); - const handleUpdate = (newSelections: Partial) => { - const updated = { ...selections, ...newSelections }; - setSelections(updated); - onUpdateData({ illustrations: updated }); - if(updated.has2d || updated.has3d) { + const handle2dCheck = (checked: boolean) => { + setSelections(prev => ({ + ...prev, + has2d: checked, + is2dAnimated: checked ? prev.is2dAnimated || 'static' : null, + })); + if (checked) { + setNoIllustrations(false); + } + }; + + const handle3dCheck = (checked: boolean) => { + setSelections(prev => ({ + ...prev, + has3d: checked, + is3dAnimated: checked ? prev.is3dAnimated || 'static' : null, + })); + if (checked) { setNoIllustrations(false); } }; const handleNoIllustrationsChange = (checked: boolean) => { setNoIllustrations(checked); - if(checked) { - const resetSelections = { - has2d: false, - is2dAnimated: null, - has3d: false, - is3dAnimated: null, - }; - setSelections(resetSelections); - onUpdateData({ illustrations: resetSelections }); + if (checked) { + setSelections({ + has2d: false, + is2dAnimated: null, + has3d: false, + is3dAnimated: null, + }); } - } - - const handle2dCheck = (checked: boolean) => { - handleUpdate({ has2d: checked, is2dAnimated: checked ? selections.is2dAnimated || 'static' : null }); }; - const handle3dCheck = (checked: boolean) => { - handleUpdate({ has3d: checked, is3dAnimated: checked ? selections.is3dAnimated || 'static' : null }); - }; + const handleUpdateRadio = (type: '2d' | '3d', value: 'static' | 'animated') => { + if (type === '2d') { + setSelections(prev => ({...prev, is2dAnimated: value})); + } else { + setSelections(prev => ({...prev, is3dAnimated: value})); + } + } const estimatedHours = useMemo(() => { return calculateHours( @@ -115,13 +126,13 @@ export function Step7Illustrations({ onNext, onBack, onUpdateData, formData }: S
- +
{selections.has2d && ( handleUpdate({ is2dAnimated: value })} + onValueChange={(value: 'static' | 'animated') => handleUpdateRadio('2d', value)} className="ml-6 space-y-2" >
@@ -138,13 +149,13 @@ export function Step7Illustrations({ onNext, onBack, onUpdateData, formData }: S
- +
{selections.has3d && ( handleUpdate({ is3dAnimated: value })} + onValueChange={(value: 'static' | 'animated') => handleUpdateRadio('3d', value)} className="ml-6 space-y-2" >