Skip to content

Commit

Permalink
feat: login, signup modal을 auth modal로 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
june-by committed Nov 15, 2023
1 parent e66e96e commit b032e5f
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 82 deletions.
2 changes: 1 addition & 1 deletion client/components/Header/AuthButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const AuthButton = ({ isLoggedIn }: AuthButtonProps) => {
if (isLoggedIn) {
logoutMutate();
} else {
openOverlay(OVERLAYS.LOGIN_MODAL);
openOverlay(OVERLAYS.AUTH_MODAL, { type: "LOGIN" });
}
};

Expand Down
44 changes: 44 additions & 0 deletions client/components/shared/Overlays/AuthModal/AuthModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import ModalView from "@components/shared/ModalView";
import SwitchCase from "@components/shared/SwitchCase";
import React, { useState } from "react";
import LoginForm from "./LoginForm";
import SignUpForm from "./SignUpForm";
import { SocialLoginArea } from "@components/shared/SocialLoginArea";

interface Props {
type: "LOGIN" | "SIGN_UP";
onExit: (time: number) => void;
}

const AuthModal = ({ type, onExit }: Props) => {
const [mode, setMode] = useState(type);
const [isClose, setIsClose] = useState(false);

const closeWithAnimation = () => {
setIsClose(true);
onExit(500);
};
return (
<ModalView
title={mode === "LOGIN" ? "로그인" : "회원가입"}
onClose={closeWithAnimation}
isClose={isClose}
>
<SwitchCase
value={mode}
caseBy={{
LOGIN: (
<LoginForm
onClose={closeWithAnimation}
openSignUpModal={() => setMode("SIGN_UP")}
/>
),
SIGN_UP: <SignUpForm onClose={closeWithAnimation} />,
}}
/>
<SocialLoginArea />
</ModalView>
);
};

export default AuthModal;
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import React, { useState, type FormEventHandler } from "react";
import React, { FormEventHandler } from "react";
import styles from "./styles.module.scss";
import { useInput } from "@hooks";
import { useLogin } from "@hooks/query";
import { toast } from "react-toastify";
import { MESSAGE } from "@constants";
import { SocialLoginArea } from "@components/shared/SocialLoginArea";
import { useOverlay, useInput } from "@hooks";
import { OVERLAYS } from "../Overlays";
import ModalView from "@components/shared/ModalView";

interface Props {
onClose: () => void;
onExit: (time: number) => void;
openSignUpModal: () => void;
}

const LoginModal = ({ onClose, onExit }: Props) => {
const [isClose, setIsClose] = useState(false);
const { openOverlay } = useOverlay();
const LoginForm = ({ onClose, openSignUpModal }: Props) => {
const [email, , onChangeEmail] = useInput("");
const [password, , onChangePassword] = useInput("");

const closeWithAnimation = () => {
setIsClose(true);
onExit(500);
};

const { mutate: loginMutate } = useLogin({
onSuccess: () => {
toast.success(MESSAGE.LOGIN_SUCCESS);
closeWithAnimation();
onClose();
},
onError: (error) => {
toast.error(error.message);
Expand All @@ -48,7 +38,7 @@ const LoginModal = ({ onClose, onExit }: Props) => {
};

return (
<ModalView title="로그인" onClose={closeWithAnimation} isClose={isClose}>
<>
<form className={styles.Form} onSubmit={onSubmit}>
<input
value={email}
Expand All @@ -65,18 +55,11 @@ const LoginModal = ({ onClose, onExit }: Props) => {
/>
<button>로그인</button>
</form>
<button
className={styles.SignUpButton}
onClick={() => {
onClose();
openOverlay(OVERLAYS.SIGNUP_MODAL);
}}
>
<button className={styles.SignUpButton} onClick={openSignUpModal}>
회원가입
</button>
<SocialLoginArea />
</ModalView>
</>
);
};

export default LoginModal;
export default LoginForm;
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import React, { FormEventHandler, useState } from "react";
import styles from "./styles.module.scss";
import React, { FormEventHandler } from "react";
import { useInput } from "@hooks";
import { StateUpdater } from "@Types/utils";
import { SocialLoginArea } from "@components/shared/SocialLoginArea";
import styles from "./styles.module.scss";
import { useSignUp } from "@hooks/query";
import { toast } from "react-toastify";
import { MESSAGE } from "@constants";
import ModalView from "@components/shared/ModalView";

interface Props {
onClose: () => void;
onExit: (time: number) => void;
}

const SignUpModal = ({ onClose, onExit }: Props) => {
const [isClose, setIsClose] = useState(false);
const SignUpForm = ({ onClose }: Props) => {
const [email, , onChangeEmail] = useInput("");
const [password, , onChangePassword] = useInput("");
const [passwordCheck, , onChangePasswordCheck] = useInput("");
const [nickname, , onChangeNickname] = useInput("");

const closeWithAnimation = () => {
setIsClose(true);
onExit(500);
};

const { mutate: signUpMutate } = useSignUp({
onSuccess: () => {
closeWithAnimation();
onClose();
toast.success(MESSAGE.SIGHUP_SUCCESS);
},
onError: (error) => {
Expand All @@ -46,7 +36,7 @@ const SignUpModal = ({ onClose, onExit }: Props) => {
};

return (
<ModalView title="회원가입" onClose={closeWithAnimation} isClose={isClose}>
<>
<form className={styles.Form} onSubmit={onSubmit}>
<input
value={email}
Expand Down Expand Up @@ -76,9 +66,8 @@ const SignUpModal = ({ onClose, onExit }: Props) => {
/>
<button>회원가입</button>
</form>
<SocialLoginArea />
</ModalView>
</>
);
};

export default SignUpModal;
export default SignUpForm;
1 change: 1 addition & 0 deletions client/components/shared/Overlays/AuthModal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./AuthModal";
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,3 @@
color: var(--primary1);
}
}

.Overlay {
background-color: rgba(0, 0, 0, 0.6);
width: 100%;
height: 100%;
position: absolute;
cursor: pointer;
}
1 change: 0 additions & 1 deletion client/components/shared/Overlays/LoginModal/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions client/components/shared/Overlays/MobileMenu/MobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const MobileMenu = ({ onClose, onExit }: Props) => {

const handleClickLoginButton = () => {
onClose();
openOverlay(OVERLAYS.LOGIN_MODAL);
openOverlay(OVERLAYS.AUTH_MODAL, { type: "LOGIN" });
};

const handleClickSignUpButton = () => {
onClose();
openOverlay(OVERLAYS.SIGNUP_MODAL);
openOverlay(OVERLAYS.AUTH_MODAL, { type: "SIGN_UP" });
};

return (
Expand Down
9 changes: 2 additions & 7 deletions client/components/shared/Overlays/Overlays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { useOverlay } from "@hooks";
import React from "react";
import dynamic from "next/dynamic";

const LoginModal = dynamic(() => import("./LoginModal"), {
ssr: false,
});

const SignUpModal = dynamic(() => import("./SignUpModal"), {
const AuthModal = dynamic(() => import("./AuthModal"), {
ssr: false,
});

Expand All @@ -22,8 +18,7 @@ const MobileMenuModal = dynamic(() => import("./MobileMenu"), {
});

export const OVERLAYS = {
LOGIN_MODAL: LoginModal,
SIGNUP_MODAL: SignUpModal,
AUTH_MODAL: AuthModal,
SERIES_FORM_MODAL: SeriesFormModal,
MOBILE_MENU: MobileMenuModal,
};
Expand Down
1 change: 0 additions & 1 deletion client/components/shared/Overlays/SignUpModal/index.ts

This file was deleted.

18 changes: 0 additions & 18 deletions client/components/shared/Overlays/SignUpModal/styles.module.scss

This file was deleted.

0 comments on commit b032e5f

Please sign in to comment.