|
1 | 1 | import { useJoinState } from '@/stores/joinStore';
|
2 |
| -import { useEffect } from 'react'; |
3 |
| -import { useLocation } from 'react-router-dom'; |
| 2 | +import { useEffect, useRef, useState } from 'react'; |
| 3 | +import Dialog from '../common/Dialog'; |
| 4 | +import { PersonalInfoPage, UseConditionPage } from '@/pages/Policy'; |
4 | 5 |
|
5 | 6 | const TermsCheckInput = () => {
|
6 |
| - const { useTermsCheck, privacyTermsCheck, useTermsCheckHandler, privacyTermsCheckHandler } = useJoinState(); |
7 |
| - const { privacyTerms, useTerms } = useLocation().state || {}; |
| 7 | + interface DialogElement { |
| 8 | + openModal: () => void; |
| 9 | + closeModal: () => void; |
| 10 | + } |
| 11 | + |
| 12 | + const [dialogMessage, setDialogMessage] = useState(''); |
| 13 | + const { useTermsCheck, privacyTermsCheck } = useJoinState(); |
| 14 | + const dialogRef = useRef<DialogElement | null>(null); |
| 15 | + |
| 16 | + const useTermsClick = () => { |
| 17 | + setDialogMessage('이용약관 동의'); |
| 18 | + dialogRef.current?.openModal(); |
| 19 | + }; |
| 20 | + |
| 21 | + const privacyTermsClick = () => { |
| 22 | + setDialogMessage('개인정보 수집, 이용 동의'); |
| 23 | + dialogRef.current?.openModal(); |
| 24 | + }; |
8 | 25 |
|
9 | 26 | useEffect(() => {
|
10 |
| - if (privacyTerms) privacyTermsCheckHandler; |
11 |
| - if (useTerms) useTermsCheckHandler; |
12 |
| - }, [privacyTerms, privacyTermsCheckHandler, useTerms, useTermsCheckHandler]); |
| 27 | + dialogRef.current?.closeModal(); |
| 28 | + }, [useTermsCheck, privacyTermsCheck]); |
13 | 29 |
|
14 | 30 | return (
|
15 |
| - <label className="form-control mb-9 mt-5 w-full"> |
16 |
| - <div className="flex flex-col"> |
17 |
| - <label className="font-bold">약관 동의</label> |
18 |
| - </div> |
19 |
| - <div className="mt-2 flex items-center justify-between"> |
20 |
| - <label className="hover:underline" htmlFor="termsOne"> |
21 |
| - <a href="/policy/usecondition">이용약관 동의 (필수)</a> |
22 |
| - </label> |
23 |
| - <input |
24 |
| - type="radio" |
25 |
| - className="radio-primary radio" |
26 |
| - checked={useTermsCheck} |
27 |
| - aria-label={'join-useTermsCheck-input'} |
28 |
| - readOnly |
29 |
| - /> |
30 |
| - </div> |
31 |
| - {!useTermsCheck ? <span className="text-red-500">이용약관에 동의해 주세요.</span> : <span className="h-6"></span>} |
32 |
| - <div className="mt-2 flex items-center justify-between"> |
33 |
| - <label className="hover:underline" htmlFor="termsTwo"> |
34 |
| - <a href="/policy/personalInfo">개인정보 수집, 이용 동의 (필수)</a> |
35 |
| - </label> |
36 |
| - <input |
37 |
| - type="radio" |
38 |
| - className="radio-primary radio" |
39 |
| - checked={privacyTermsCheck} |
40 |
| - aria-label={'join-privacyTermsCheck-input'} |
41 |
| - readOnly |
42 |
| - /> |
43 |
| - </div> |
44 |
| - {!privacyTermsCheck ? ( |
45 |
| - <span className="text-red-500">개인정보 수집, 이용에 동의해 주세요.</span> |
46 |
| - ) : ( |
47 |
| - <span className="h-6"></span> |
48 |
| - )} |
49 |
| - </label> |
| 31 | + <> |
| 32 | + <label className="form-control mb-9 mt-5 w-full"> |
| 33 | + <div className="flex flex-col"> |
| 34 | + <label className="font-bold">약관 동의</label> |
| 35 | + </div> |
| 36 | + <div className="mt-2 flex items-center justify-between"> |
| 37 | + <label className="hover:underline" htmlFor="termsOne" onClick={useTermsClick}> |
| 38 | + 이용약관 동의 (필수) |
| 39 | + </label> |
| 40 | + <input |
| 41 | + type="radio" |
| 42 | + className="radio-primary radio" |
| 43 | + checked={useTermsCheck} |
| 44 | + onClick={useTermsClick} |
| 45 | + aria-label={'join-useTermsCheck-input'} |
| 46 | + readOnly |
| 47 | + /> |
| 48 | + </div> |
| 49 | + {!useTermsCheck ? ( |
| 50 | + <span className="text-red-500">이용약관에 동의해 주세요.</span> |
| 51 | + ) : ( |
| 52 | + <span className="h-6"></span> |
| 53 | + )} |
| 54 | + <div className="mt-2 flex items-center justify-between"> |
| 55 | + <label className="hover:underline" htmlFor="termsTwo" onClick={privacyTermsClick}> |
| 56 | + 개인정보 수집, 이용 동의 (필수) |
| 57 | + </label> |
| 58 | + <input |
| 59 | + type="radio" |
| 60 | + className="radio-primary radio" |
| 61 | + checked={privacyTermsCheck} |
| 62 | + onClick={privacyTermsClick} |
| 63 | + aria-label={'join-privacyTermsCheck-input'} |
| 64 | + readOnly |
| 65 | + /> |
| 66 | + </div> |
| 67 | + {!privacyTermsCheck ? ( |
| 68 | + <span className="text-red-500">개인정보 수집, 이용에 동의해 주세요.</span> |
| 69 | + ) : ( |
| 70 | + <span className="h-6"></span> |
| 71 | + )} |
| 72 | + </label> |
| 73 | + <Dialog ref={dialogRef} desc={dialogMessage}> |
| 74 | + {dialogMessage === '이용약관 동의' ? <UseConditionPage /> : <PersonalInfoPage />} |
| 75 | + </Dialog> |
| 76 | + </> |
50 | 77 | );
|
51 | 78 | };
|
52 | 79 |
|
|
0 commit comments