diff --git a/src/pages/home/event/EventPage.tsx b/src/pages/home/event/EventPage.tsx new file mode 100644 index 00000000..e99fe686 --- /dev/null +++ b/src/pages/home/event/EventPage.tsx @@ -0,0 +1,196 @@ +import styled from '@emotion/styled'; +import { observer } from 'mobx-react-lite'; +import { useEffect } from 'react'; +import { useForm } from 'react-hook-form'; +import { useHistory } from 'react-router-dom'; + +import { PageUiStoreImpl } from './EventPageUiStore'; + +import { + BodyScreen, + ErrorMessage, + Header, + Input, + PageBody, + PageFooter, + PageStoreHOC, + PasswordInput, + NavButton, +} from '@/components'; +import { PAGE_URL } from '@/configs/path'; +import { useAuthRedirect, usePageUiStore } from '@/hooks'; +import { useRootStore } from '@/stores'; +import { passwordReg, emailReg } from '@/utils'; + +const EventPage: React.FC = observer(() => { + const { replace } = useHistory(); + const { + ui: { alert }, + } = useRootStore(); + const { submitDisabled, isDuplicatedEmail, chekedEmail, signUp } = + usePageUiStore(); + const { + control, + handleSubmit, + watch, + formState: { errors }, + trigger, + } = useForm(); + const password = watch('password'); + const onSubmit = async (body: User.CreateDto) => { + body.profileImage = null; + const { success, message } = (await signUp(body)) as unknown as StoreAPI; + + if (success) { + replace(PAGE_URL.SignIn); + alert({ message: '회원가입 되었습니다. 로그인 후 학부인증을 진행하세요.' }); + } else if (message) { + alert({ message }); + } + }; + + useEffect(() => { + if (isDuplicatedEmail) trigger('email'); + }, [isDuplicatedEmail]); + + useAuthRedirect(); + + return ( + <> +
+ + +
+ { + // 이메일 유효성 검사는 진행했고, + if (isDuplicatedEmail === true) { + // 검사했던 이메일과 지금 입력된 이메일이 같은 경우 에러 + if (chekedEmail === value) return '중복된 이메일입니다.'; + else return true; + } + return true; + }, + pattern: { + value: emailReg, + message: '이메일 형식에 맞게 입력하세요.', + }, + }} + /> + {errors.email ? {errors.email?.message} : null} + + (영어 + 숫자 + 특수문자)', + }, + }} + /> + {errors.password ? ( + + ) : null} + + value === password || '비밀번호가 일치하지 않습니다.', + }} + /> + {errors.passwordConfirm ? ( + {errors.passwordConfirm?.message} + ) : null} + + + {errors.name ? {errors.name?.message} : null} + + + {errors.admissionYear ? ( + {errors.admissionYear?.message} + ) : null} + + + {errors.studentId ? {errors.studentId?.message} : null} +
+
+ + + 회원가입 이후 로그인과 학부인증을 하셔야
서비스를 이용할 수 있습니다 +
+ + 가입하기 + +
+ + ); +}); + +export const Message = styled.div` + text-align: right; + color: #ff7473; + font-size: 12px; + line-height: 21px; +`; + +export default PageStoreHOC(, { store: PageUiStoreImpl }); diff --git a/src/pages/home/event/EventPageUiStore.ts b/src/pages/home/event/EventPageUiStore.ts new file mode 100644 index 00000000..e29cdcfa --- /dev/null +++ b/src/pages/home/event/EventPageUiStore.ts @@ -0,0 +1,32 @@ +import { makeAutoObservable } from 'mobx'; + +import { AuthRepoImpl as Repo } from '@/stores/repositories/AuthRepo'; + +export class EventPageUiStore { + submitDisabled = false; + chekedEmail = ''; + isDuplicatedEmail?: boolean; + + constructor() { + makeAutoObservable(this, {}, { autoBind: true }); + } + + *signUp(body: User.CreateDto): Generator { + this.submitDisabled = true; + + try { + // 이메일 중복 검사 + this.chekedEmail = body.email; + this.isDuplicatedEmail = (yield Repo.isDuplicatedEmail(body.email)) as boolean; + + yield Repo.signUp(body); + return { success: true }; + } catch (error) { + return error; + } finally { + this.submitDisabled = false; + } + } +} + +export const PageUiStoreImpl = new SignUpPageUiStore(); diff --git a/src/pages/home/event/components/EventBlock.tsx b/src/pages/home/event/components/EventBlock.tsx new file mode 100644 index 00000000..e69de29b