-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventOrganizerInfoPage.tsx
More file actions
63 lines (56 loc) · 1.81 KB
/
EventOrganizerInfoPage.tsx
File metadata and controls
63 lines (56 loc) · 1.81 KB
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
import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import UnderlineTextField from '../../../../design-system/ui/textFields/UnderlineTextField';
import { useFunnelState } from '../../../features/event-manage/event-create/model/FunnelContext';
import { OrganizerFormData, organizerZodValidation } from '../../../shared/lib/formValidation';
interface EventOrganizerInfoPageProps {
onValidationChange?: (isValid: boolean) => void;
}
const EventOrganizerInfoPage = ({ onValidationChange }: EventOrganizerInfoPageProps) => {
const { eventState, setEventState } = useFunnelState();
const {
register,
watch,
formState: { errors, isValid },
} = useForm<OrganizerFormData>({
mode: 'onChange',
defaultValues: {
email: eventState.organizerEmail || '',
phone: eventState.organizerPhoneNumber || '',
},
...organizerZodValidation,
});
const phoneValue = watch('phone');
const emailValue = watch('email');
useEffect(() => {
onValidationChange?.(isValid);
}, [isValid, onValidationChange]);
useEffect(() => {
setEventState(prev => ({
...prev,
organizerEmail: emailValue,
organizerPhoneNumber: phoneValue,
}));
}, [emailValue, phoneValue, setEventState]);
return (
<div className="flex flex-col gap-6 md:gap-7 p-5">
<UnderlineTextField
label="이메일"
placeholder="이메일"
type="email"
errorMessage={errors.email?.message}
className="w-full"
{...register('email')}
/>
<UnderlineTextField
label="전화번호"
placeholder={`"-"를 포함하여 입력해주세요`}
type="tel"
errorMessage={errors.phone?.message}
className="w-full"
{...register('phone')}
/>
</div>
);
};
export default EventOrganizerInfoPage;