-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunnel.tsx
78 lines (68 loc) · 1.88 KB
/
Funnel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { FormProvider, useForm } from "react-hook-form";
import { useFunnel } from "@/hooks/useFunnel";
import FirstForm from "@/components/Funnel/FirstForm";
import SecondForm from "@/components/Funnel/SecondForm";
import ThirdForm from "@/components/Funnel/ThirdForm";
import { useNavigate } from "react-router";
export type FunnelFormValues = {
name: string;
age: string;
sex: string;
religion: string;
directInput: string;
};
const FunnelPage = () => {
const navigate = useNavigate();
const [Funnel, setStep] = useFunnel(
["개인정보1", "개인정보2", "개인정보3"] as const,
{
initialStep: "개인정보1",
}
);
const methods = useForm<FunnelFormValues>({
mode: "all",
defaultValues: {
name: "",
age: "",
sex: "",
religion: "",
directInput: "",
},
});
const handleSubmitFunnelForm = ({
name,
age,
sex,
religion,
directInput,
}: FunnelFormValues) => {
religion !== "직접입력"
? alert(`최종 제출: ${name}, ${age}, ${sex}, ${religion}`)
: alert(`최종 제출: ${name}, ${age}, ${sex}, ${directInput}`);
return navigate("/");
};
return (
<FormProvider {...methods}>
<form>
<Funnel>
<Funnel.Step name="개인정보1">
<FirstForm setNextStep={() => setStep("개인정보2")} />
</Funnel.Step>
<Funnel.Step name="개인정보2">
<SecondForm
setNextStep={() => setStep("개인정보3")}
setPrevStep={() => setStep("개인정보1")}
/>
</Funnel.Step>
<Funnel.Step name="개인정보3">
<ThirdForm
setPrevStep={() => setStep("개인정보2")}
onSubmit={handleSubmitFunnelForm}
/>
</Funnel.Step>
</Funnel>
</form>
</FormProvider>
);
};
export default FunnelPage;