Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/f-lab-edu/eungeori into โ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆfeat/calender
  • Loading branch information
Jetom88 committed Nov 16, 2024
2 parents 95ef937 + 6f6f24f commit ac09210
Show file tree
Hide file tree
Showing 51 changed files with 3,862 additions and 1,948 deletions.
4,659 changes: 3,087 additions & 1,572 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
30 changes: 30 additions & 0 deletions src/app/auth/common/inputUI.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { inputStyle } from "@/app/components/common/input.css";
import { pink80 } from "@/app/styles/colors.css";
import { caption, regular } from "@/app/styles/font.css";
import { paddingSprinkles } from "@/app/styles/padding.css";
import { HTMLInputTypeAttribute } from "react";
import { UseFormRegister } from "react-hook-form";

type InputUiProps = {
text: string;
type?: HTMLInputTypeAttribute;
maxLegnth: number;
register: ReturnType<UseFormRegister<any>>;
errorMessage: string | undefined;
};

const FormInputUI = ({ text, type, maxLegnth, register, errorMessage }: InputUiProps) => {
return (
<div>
<p className={`${caption} ${regular} ${paddingSprinkles({ paddingBottom: "s4" })}`}>
{text}
<span className={`${pink80}`}>*</span>
</p>
<input placeholder={text} className={inputStyle} {...register} maxLength={maxLegnth} type={type} />

<p className={`${paddingSprinkles({ paddingTop: "s4" })} ${caption} ${pink80}`}>{errorMessage}</p>
</div>
);
};

export default FormInputUI;
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { flexSprinklesFc } from "@/app/components/common/utils/flex";
import { gray300, pink80 } from "@/app/styles/colors.css";
import { inputStyle } from "@/app/styles/common/input.css";
import { caption, caption2 } from "@/app/styles/font.css";
import { paddingSprinkles } from "@/app/styles/padding.css";
import { gray300 } from "@/app/styles/colors.css";
import { caption2 } from "@/app/styles/font.css";
import { formBox } from "../styles/login.css";
import { useRouter } from "next/navigation";

Expand All @@ -12,11 +10,12 @@ import { useForm } from "react-hook-form";
import { z } from "zod";
import { pointer, buttonOutLine } from "@/app/styles/global.css";

import { useAuth } from "../hook";
import { useLogin } from "../hook";
import FormInputUI from "../../common/inputUI";

const LoginForm = () => {
const router = useRouter();
const { onLoginSubmit } = useAuth();
const { onLoginSubmit } = useLogin();

const {
register,
Expand All @@ -35,26 +34,20 @@ const LoginForm = () => {
<>
<form className={formBox} onSubmit={handleSubmit(onLoginSubmit)}>
<div className={flexSprinklesFc({ flexDirection: "column", gap: "8px" })} style={{ width: "95%" }}>
<div>
<input className={inputStyle} placeholder="์•„์ด๋””" {...register("id")} maxLength={10} />
<FormInputUI
text="์•„์ด๋””"
maxLegnth={10}
register={register("id")}
errorMessage={errors.id?.message}
/>

<p className={`${paddingSprinkles({ paddingTop: "s4" })} ${caption} ${pink80}`}>
{errors.id?.message}
</p>
</div>

<div>
<input
className={inputStyle}
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ"
{...register("password")}
type="password"
maxLength={12}
/>
<p className={`${paddingSprinkles({ paddingTop: "s4" })} ${caption} ${pink80}`}>
{errors.password?.message}
</p>
</div>
<FormInputUI
text="๋น„๋ฐ€๋ฒˆํ˜ธ"
type="password"
maxLegnth={12}
register={register("password")}
errorMessage={errors.password?.message}
/>
</div>
</form>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Button from "@/app/components/common/Button";
import Popup from "@/app/components/common/Popup";
import { useLoginUiStore } from "@/app/store/login/loginStore";
import { usePopupStore } from "@/app/store/popup/PopupStore";
import { colors } from "@/app/styles/colors.css";

const LoginPopup = () => {
const { setLoginMessage, setIsLoginPopup } = useLoginUiStore();
const loginMessageState = useLoginUiStore((state) => state.loginMessage);
const isLoginPopupState = useLoginUiStore((state) => state.isLoginPopup);
const { setIsPopup, setMessage } = usePopupStore();
const loginMessageState = usePopupStore((state) => state.message);
const isLoginPopupState = usePopupStore((state) => state.isPopup);
return (
<>
{isLoginPopupState && (
Expand All @@ -16,8 +16,8 @@ const LoginPopup = () => {
background={colors.primary}
color={colors.white}
onClick={() => {
setIsLoginPopup(false);
setLoginMessage("");
setIsPopup(false);
setMessage("");
}}
/>
</Popup>
Expand Down
1 change: 1 addition & 0 deletions src/app/auth/login/hook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useLogin } from "./useLogin";
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { useLoginUiStore } from "@/app/store/login/loginStore";
import { usePopupStore } from "@/app/store/popup/PopupStore";
import { LocalStorage } from "@/app/types/localStorageSchema";
import { signinSchema } from "@/app/types/signinSchema";
import { useRouter } from "next/navigation";
import { z } from "zod";

export const useAuth = () => {
export const useLogin = () => {
const router = useRouter();

const { setLoginMessage, setIsLoginPopup } = useLoginUiStore();
const setIsPopupState = usePopupStore((state) => state.setIsPopup);
const setMessageState = usePopupStore((state) => state.setMessage);

const onLoginSubmit = (data: z.infer<typeof signinSchema>) => {
if (!data) {
setLoginMessage("๊ฐ€์ž…๋œ ์ •๋ณด๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.");
setIsLoginPopup(true);
setMessageState("๊ฐ€์ž…๋œ ์ •๋ณด๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.");
setIsPopupState(true);
return;
}

Expand All @@ -22,14 +23,14 @@ export const useAuth = () => {
const getAuthInfo = signupStorage.get();

if (!getAuthInfo) {
setLoginMessage("ํšŒ์›๊ฐ€์ž…์„ ์ง„ํ–‰ํ•ด์ฃผ์„ธ์š”.");
setIsLoginPopup(true);
setMessageState("ํšŒ์›๊ฐ€์ž…์„ ์ง„ํ–‰ํ•ด์ฃผ์„ธ์š”.");
setIsPopupState(true);
return;
}

if (getAuthInfo.id !== data.id || getAuthInfo.password !== data.password) {
setLoginMessage("์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.");
setIsLoginPopup(true);
setMessageState("์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.");
setIsPopupState(true);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import Image from "next/image";
import Logo from "@svgs/logo.svg";
import { flexSprinklesFc } from "../components/common/utils/flex";
import { loginWrapper, loginLogo, loginTextBox, loginHeading, loginCaption } from "./styles/login.css";
import LoginForm from "./components/loginForm";
import LoginPopup from "./components/loginPopup";
import { flexSprinklesFc } from "@/app/components/common/utils/flex";

export default function LoginPage() {
const logoClassName = flexSprinklesFc({
Expand Down
File renamed without changes.
80 changes: 80 additions & 0 deletions src/app/auth/signup/components/signupForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Button from "@/app/components/common/Button";
import { flexSprinklesFc } from "@/app/components/common/utils/flex";
import { colors } from "@/app/styles/colors.css";
import { signupSchema } from "@/app/types/signupSchema";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { useSignup } from "../hook";
import FormInputUI from "../../common/inputUI";

const SignupForm = () => {
const {
register,
handleSubmit,
formState: { errors, isValid },
} = useForm<z.infer<typeof signupSchema>>({
resolver: zodResolver(signupSchema),
mode: "onChange",
defaultValues: {
id: "",
password: "",
confirmPassword: "",
nickname: "",
},
});

const { onSignupSubmit } = useSignup();

return (
<form
onSubmit={handleSubmit(onSignupSubmit)}
className={flexSprinklesFc({ flexDirection: "column", gap: "32px" })}
>
<div className={flexSprinklesFc({ flexDirection: "column", gap: "8px" })}>
<FormInputUI
text="์•„์ด๋””"
maxLegnth={10}
register={register("id")}
errorMessage={errors.id?.message}
/>

<FormInputUI
text="๋น„๋ฐ€๋ฒˆํ˜ธ"
type="password"
maxLegnth={12}
register={register("password")}
errorMessage={errors.password?.message}
/>

<FormInputUI
text="๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"
type="password"
maxLegnth={12}
register={register("confirmPassword")}
errorMessage={errors.confirmPassword?.message}
/>

<FormInputUI
text="๋‹‰๋„ค์ž„"
maxLegnth={12}
register={register("nickname")}
errorMessage={errors.nickname?.message}
/>
</div>

<div>
<Button
text="๊ฐ€์ž…ํ•˜๊ธฐ"
width="100%"
background={isValid ? colors.point : colors.gray200}
color={colors.white}
fontSize="12px"
disabled={!isValid}
/>
</div>
</form>
);
};

export default SignupForm;
46 changes: 46 additions & 0 deletions src/app/auth/signup/components/signupPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Button from "@/app/components/common/Button";
import Popup from "@/app/components/common/Popup";
import { usePopupStore } from "@/app/store/popup/PopupStore";
import { colors } from "@/app/styles/colors.css";
import { useRouter } from "next/navigation";

const messageRoute: Record<string, string | null> = {
"์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํšŒ์›์ž…๋‹ˆ๋‹ค.": null,
"์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๋‹‰๋„ค์ž„์ž…๋‹ˆ๋‹ค.": null,
"ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๋์Šต๋‹ˆ๋‹ค.": "/",
};

const SignupPopup = () => {
const router = useRouter();
const signupMessageState = usePopupStore((state) => state.message);
const signupPopupState = usePopupStore((state) => state.isPopup);
const setSignupPopupState = usePopupStore((state) => state.setIsPopup);

const onClick = () => {
const route = signupMessageState ? messageRoute[signupMessageState] : null;

if (route) {
setSignupPopupState(false);
router.push(route);
} else {
setSignupPopupState(false);
}
};
return (
<div>
{signupPopupState && (
<Popup text={signupMessageState}>
<Button
width="115px"
text="ํ™•์ธ"
onClick={onClick}
color={colors.white}
background={colors.primary}
/>
</Popup>
)}
</div>
);
};

export default SignupPopup;
1 change: 1 addition & 0 deletions src/app/auth/signup/hook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useSignup } from "./useSignup";
33 changes: 33 additions & 0 deletions src/app/auth/signup/hook/useSignup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { usePopupStore } from "@/app/store/popup/PopupStore";
import { LocalStorage } from "@/app/types/localStorageSchema";
import { signupSchema } from "@/app/types/signupSchema";
import { z } from "zod";

export const useSignup = () => {
const setIsPopupState = usePopupStore((state) => state.setIsPopup);
const setMessageState = usePopupStore((state) => state.setMessage);

const onSignupSubmit = (data: z.infer<typeof signupSchema>) => {
const signupStorage = new LocalStorage("signup");

if (data.id === signupStorage.get()?.id) {
setIsPopupState(true);
setMessageState("์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํšŒ์›์ž…๋‹ˆ๋‹ค.");
return;
}

if (data.nickname === signupStorage.get()?.nickname) {
setIsPopupState(true);
setMessageState("์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๋‹‰๋„ค์ž„์ž…๋‹ˆ๋‹ค.");
return;
}

if (data) {
setIsPopupState(true);
setMessageState("ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๋์Šต๋‹ˆ๋‹ค.");
signupStorage.set(data);
}
};

return { onSignupSubmit };
};
Loading

0 comments on commit ac09210

Please sign in to comment.