-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: 공통 모달 컴포넌트 구현 및 약관 동의 UI 구현 (#17)
* feat: 약관 동의 스키마 및 타입 작성 * feat: 모달 렌더링용 루트 div 생성 * chore: 필요 아이콘 추가 * style: 테일윈드 변수 및 컴포넌트 스타일 최신화 * refactor: 응답 데이터에 맞는 상수 변환 * refactor: 타이머훅 파라미터 사용 * feat: 모달 컨텍스트, 컴포넌트 로직 작성 * feat: 약관 동의 모달 작성 및 체크박스 구현 * feat: 모달 적용 * design: 인증코드 받기 버튼 스타일 변경 * feat: 버셀 레이아웃 경로 재설정 * feat: 랜딩페이지 index 형태로 재설정 * feat: gender 타입 및 스키마 변경 * refactor: 모달 겹치는 로직 통합 * refactor: 반복되는 로직 매핑 * feat: 인증번호 요청 시 이메일 데이터 동봉 * feat: 상수 파일 추가 * fix: gender 선택시 value 오류 문제 해결
- Loading branch information
Showing
22 changed files
with
379 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Controller, Control, FieldValues, Path } from 'react-hook-form'; | ||
|
||
interface BaseCheckboxProps { | ||
label?: string; | ||
} | ||
|
||
interface ControlledCheckboxProps<T extends FieldValues> | ||
extends BaseCheckboxProps { | ||
control: Control<T>; | ||
name: Path<T>; | ||
onChange?: never; | ||
checked?: never; | ||
} | ||
|
||
interface UncontrolledCheckboxProps extends BaseCheckboxProps { | ||
control?: never; | ||
name?: never; | ||
onChange: (checked: boolean) => void; | ||
checked: boolean; | ||
} | ||
|
||
type CheckboxProps<T extends FieldValues> = | ||
| ControlledCheckboxProps<T> | ||
| UncontrolledCheckboxProps; | ||
|
||
function Checkbox<T extends FieldValues>(props: CheckboxProps<T>) { | ||
const CheckboxContent = ({ | ||
checked, | ||
onChange, | ||
}: { | ||
checked: boolean; | ||
onChange: (value: boolean) => void; | ||
}) => ( | ||
<label | ||
className="flex items-center cursor-pointer gap-2 w-full" | ||
onClick={() => onChange(!checked)} | ||
> | ||
<div className="w-5 h-5 border-2 rounded-full flex items-center justify-center"> | ||
{checked && <div className="w-4 h-4 bg-primary rounded-full" />} | ||
</div> | ||
{props.label && ( | ||
<span | ||
className={`${'control' in props ? 'font-medium text-body' : 'font-semibold text-captionHeader'}`} | ||
> | ||
{props.label} | ||
</span> | ||
)} | ||
</label> | ||
); | ||
|
||
if ('control' in props && props.control) { | ||
return ( | ||
<Controller | ||
control={props.control} | ||
name={props.name} | ||
render={({ field }) => ( | ||
<CheckboxContent checked={field.value} onChange={field.onChange} /> | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
return <CheckboxContent checked={props.checked} onChange={props.onChange} />; | ||
} | ||
|
||
export default Checkbox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import Modal from '@/components/modal'; | ||
import Button from '../commons/Button'; | ||
import Checkbox from '../commons/Checkbox'; | ||
import AgreeLinkIcon from '../../../src/assets/icon/agreeLinkIcon.svg?react'; | ||
import { AgreementsTypes } from 'gachTaxi-types'; | ||
import { useForm, SubmitHandler } from 'react-hook-form'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { agreementsSchema } from '@/libs/schemas/auth'; | ||
import { z } from 'zod'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useModal } from '@/contexts/ModalContext'; | ||
import { AGREE_VALUES } from '@/constants'; | ||
|
||
const AgreementModal = () => { | ||
const navigate = useNavigate(); | ||
const { closeModal } = useModal(); | ||
|
||
const agreementForm = useForm<z.infer<typeof agreementsSchema>>({ | ||
resolver: zodResolver(agreementsSchema), | ||
defaultValues: { | ||
termsAgreement: false, | ||
privacyAgreement: false, | ||
marketingAgreement: false, | ||
}, | ||
mode: 'onSubmit', | ||
}); | ||
|
||
const agreements = agreementForm.watch([ | ||
'termsAgreement', | ||
'privacyAgreement', | ||
'marketingAgreement', | ||
]); | ||
|
||
const isAllAgreed = agreements.every(Boolean); | ||
|
||
const handleAllAgree = (checked: boolean) => { | ||
agreementForm.setValue('termsAgreement', checked); | ||
agreementForm.setValue('privacyAgreement', checked); | ||
agreementForm.setValue('marketingAgreement', checked); | ||
}; | ||
|
||
const handleSubmitToAgreement: SubmitHandler<AgreementsTypes> = ( | ||
data: AgreementsTypes, | ||
) => { | ||
console.log(data); | ||
navigate('/signup/user-info'); | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Modal.Header className="mt-vertical"> | ||
<h1 className="text-header font-bold"> | ||
가치 택시를 이용하기 위해 <br /> 약관에 동의해주세요 | ||
</h1> | ||
</Modal.Header> | ||
<Modal.Content className="mb-0"> | ||
<form | ||
onSubmit={agreementForm.handleSubmit(handleSubmitToAgreement)} | ||
className="flex flex-col gap-4" | ||
> | ||
<div className="p-3 border rounded-common flex items-center gap-2"> | ||
<Checkbox | ||
checked={isAllAgreed} | ||
onChange={handleAllAgree} | ||
label="약관 모두 동의" | ||
/> | ||
</div> | ||
{AGREE_VALUES.map((values) => { | ||
return ( | ||
<div | ||
key={values.name} | ||
className="flex items-center justify-between" | ||
> | ||
<Checkbox | ||
control={agreementForm.control} | ||
name={values.name} | ||
label={values.label} | ||
/> | ||
<Button variant="icon"> | ||
<AgreeLinkIcon /> | ||
</Button> | ||
</div> | ||
); | ||
})} | ||
{(agreementForm.formState.errors.privacyAgreement || | ||
agreementForm.formState.errors.termsAgreement) && ( | ||
<p className="text-red-500">필수 약관에 동의해주세요!</p> | ||
)} | ||
<Button className="w-full mt-vertical" type="submit"> | ||
시작하기 | ||
</Button> | ||
</form> | ||
</Modal.Content> | ||
</> | ||
); | ||
}; | ||
|
||
export default AgreementModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ReactNode } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
interface ModalProps { | ||
children: ReactNode; | ||
} | ||
|
||
export const Modal = ({ children }: ModalProps) => { | ||
return createPortal( | ||
<div | ||
role="dialog" | ||
className={`flex flex-col gap-[16px] p-[16px] h-fit max-w-[360px] w-full z-[1000] bg-secondary absolute left-1/2 -translate-x-1/2 bottom-0 rounded-t-modal text-white`} | ||
> | ||
{children} | ||
</div>, | ||
(document.getElementById('modal-root') as Element) || document.body, | ||
); | ||
}; | ||
|
||
Modal.Overlay = ({ onClose }: { onClose: () => void }) => { | ||
return ( | ||
<div | ||
className="fixed inset-0 bg-black bg-opacity-50 z-[999] h-full w-screen" | ||
onClick={onClose} | ||
></div> | ||
); | ||
}; | ||
|
||
Modal.Section = ({ | ||
children, | ||
className, | ||
}: { | ||
children: React.ReactNode; | ||
className?: string; | ||
}) => ( | ||
<div className={`w-full h-fit mb-vertical ${className || ''}`}> | ||
{children} | ||
</div> | ||
); | ||
|
||
Modal.Header = Modal.Section; | ||
Modal.Content = Modal.Section; | ||
Modal.Footer = Modal.Section; | ||
|
||
export default Modal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.