Skip to content

Commit ba17e92

Browse files
committed
✨ feat:lazy-loading 적용
Issue Resolved: #
1 parent f60c1be commit ba17e92

File tree

7 files changed

+40
-30
lines changed

7 files changed

+40
-30
lines changed

front/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default tseslint.config(
2929
...reactHooks.configs.recommended.rules,
3030
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
3131
'prefer-const': ['off'],
32+
'react-refresh/only-export-components': ['off'],
3233
},
3334
},
3435
);

front/src/constants/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LOGIN_FAILED_MESSAGE = '아이디 또는 비밀번호가 일치하지 않습니다.';

front/src/pages/LoginPage/index.tsx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,37 @@ import { type CustomError } from '@/api/axios.ts';
44
import { type UserData, postLogin } from '@/api/user.ts';
55

66
import { useAuthContext } from '@/hooks/useAuthContext.tsx';
7-
import useForm, { type Validate } from '@/hooks/useForm';
7+
import useForm from '@/hooks/useForm';
88

99
import { toast } from '@/components/Toast/index.ts';
1010
import Button from '@/components/common/Button';
1111
import Field from '@/components/common/Field';
1212
import Icon from '@/components/common/Icon';
1313
import Input from '@/components/common/Input';
1414

15+
import { lengthValidate } from '@/pages/LoginPage/validate.ts';
16+
17+
import { LOGIN_FAILED_MESSAGE } from '@/constants/user.ts';
18+
import type { LoginForm } from '@/type/user.ts';
1519
import { useMutation } from '@tanstack/react-query';
1620
import { AxiosResponse } from 'axios';
1721

18-
type Form = {
19-
id: string;
20-
password: string;
21-
};
22-
type ResponseData = {
23-
loginId: string;
24-
};
25-
26-
const FAILED_MESSAGE = '아이디 또는 비밀번호가 일치하지 않습니다.';
2722
export default function LoginPage() {
23+
type ResponseData = {
24+
loginId: string;
25+
};
26+
2827
const {
2928
handleSubmit,
3029
register,
3130
formState: { errors },
32-
} = useForm<Form>();
31+
} = useForm<LoginForm>();
3332
const { login } = useAuthContext();
3433
const navigation = useNavigate();
3534
const { mutate, isPending, error } = useMutation<AxiosResponse<ResponseData>, CustomError, UserData>({
3635
mutationFn: postLogin,
3736
onError: () => {
38-
toast.error(`로그인 실패\n 사유 : ${FAILED_MESSAGE}`);
37+
toast.error(`로그인 실패\n 사유 : ${LOGIN_FAILED_MESSAGE}`);
3938
},
4039
onSuccess: (data) => {
4140
const { loginId } = data.data;
@@ -45,7 +44,7 @@ export default function LoginPage() {
4544
},
4645
});
4746

48-
const submit = async (data: Form) => {
47+
const submit = async (data: LoginForm) => {
4948
const { id, password } = data;
5049
mutate({ loginId: id, loginPassword: password });
5150
};
@@ -59,7 +58,7 @@ export default function LoginPage() {
5958
<Field
6059
label="Id"
6160
isValid={!errors.id && !error}
62-
errorMessage={errors.id ? errors.id : FAILED_MESSAGE}>
61+
errorMessage={errors.id ? errors.id : LOGIN_FAILED_MESSAGE}>
6362
<Input
6463
disabled={isPending}
6564
{...register('id', {
@@ -71,7 +70,7 @@ export default function LoginPage() {
7170
<Field
7271
label="Password"
7372
isValid={!errors.password && !error}
74-
errorMessage={errors.password ? errors.password : FAILED_MESSAGE}>
73+
errorMessage={errors.password ? errors.password : LOGIN_FAILED_MESSAGE}>
7574
<Input
7675
type="password"
7776
disabled={isPending}
@@ -96,9 +95,3 @@ export default function LoginPage() {
9695
</div>
9796
);
9897
}
99-
100-
const lengthValidate: Validate<Form> = ({ value }) => {
101-
const isRightLength = value.length >= 4 && value.length <= 12;
102-
if (!isRightLength) return '최소 4자리, 최대 12자리 입니다.';
103-
return null;
104-
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Validate } from '@/hooks/useForm.tsx';
2+
3+
import type { LoginForm } from '@/type/user.ts';
4+
5+
export const lengthValidate: Validate<LoginForm> = ({ value }) => {
6+
const isRightLength = value.length >= 4 && value.length <= 12;
7+
if (!isRightLength) return '최소 4자리, 최대 12자리 입니다.';
8+
return null;
9+
};

front/src/pages/NotFoundPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Link } from 'react-router-dom';
33
import Button from '@/components/common/Button.tsx';
44
import Icon from '@/components/common/Icon.tsx';
55

6-
export default function NotFondPage() {
6+
export default function NotFoundPage() {
77
return (
88
<div className="flex h-[100vh] w-full items-center justify-center">
99
<div className="flex w-[420px] flex-col items-center gap-8">

front/src/routes/index.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
import { lazy } from 'react';
12
import { Navigate, createBrowserRouter } from 'react-router-dom';
23

34
import WithLogin from '@/components/loaders/WithLogin';
45
import WithoutLogin from '@/components/loaders/WithoutLogin';
56

67
import AdminPage from '@/pages/AdminPage';
7-
import LoginPage from '@/pages/LoginPage';
8-
import NotFondPage from '@/pages/NotFoundPage.tsx';
9-
import ProgramDetailPage from '@/pages/ProgramDetailPage';
10-
import ProgramsPage from '@/pages/ProgramsPage';
8+
import NotFoundPage from '@/pages/NotFoundPage.tsx';
119
import ReservationPage from '@/pages/ReservationPage';
1210
import ReservationWaitingPage from '@/pages/ReservationWaitingPage';
13-
import SignUpPage from '@/pages/SignupPage';
1411
import WaitingQueuePage from '@/pages/WaitingQueuePage/index.tsx';
1512

1613
import { ROUTE_URL } from '@/constants/index.ts';
1714
import Layout from '@/layout/Layout';
1815

16+
const LoginPage = lazy(() => import('@/pages/LoginPage'));
17+
const SignUpPage = lazy(() => import('@/pages/SignupPage'));
18+
const ProgramsPage = lazy(() => import('@/pages/ProgramsPage'));
19+
const ProgramDetailPage = lazy(() => import('@/pages/ProgramDetailPage'));
20+
1921
//TODO lazyloading,suspene, fallback 적용, withLogin hoc접근 권한 설정, flat보다는 next 처럼 밑으로 최적화도 더 좋다
2022
const router = createBrowserRouter([
2123
{
2224
path: '/',
2325
element: <Layout />,
24-
errorElement: <NotFondPage />,
26+
errorElement: <NotFoundPage />,
2527
children: [
26-
{ path: '*', element: <NotFondPage /> },
28+
{ path: '*', element: <NotFoundPage /> },
2729
{ path: '', element: <Navigate to={ROUTE_URL.PROGRAM.DEFAULT} /> },
28-
2930
{ path: ROUTE_URL.PROGRAM.DEFAULT, element: <ProgramsPage /> },
3031
{ path: `${ROUTE_URL.PROGRAM.DEFAULT}/:programId`, element: <ProgramDetailPage /> },
3132
{

front/src/type/user.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
export interface UserInformation {
22
loginId: string;
33
}
4+
5+
export type LoginForm = {
6+
id: string;
7+
password: string;
8+
};

0 commit comments

Comments
 (0)