Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions apps/graduate/src/pages/login/api/submitLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useSubmitLogin = ({
onError,
}: {
onSuccess?: () => void;
onError?: () => void;
onError?: (errorCode: string) => void;
}) => {
return useMutation({
mutationFn: submitLogin,
Expand All @@ -29,8 +29,10 @@ export const useSubmitLogin = ({
setRole(response.role);
onSuccess?.();
},
onError: () => {
onError?.();
onError: (error: unknown) => {
const errorMessage =
error instanceof Error ? error.message : '로그인에 실패했습니다';
onError?.(errorMessage);
},
});
};
14 changes: 14 additions & 0 deletions apps/graduate/src/pages/login/ui/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState, useEffect } from 'react';
import { useForm } from 'react-hook-form';

import { Button } from '~/shared/components';
Expand All @@ -7,6 +8,8 @@ import type { LoginFormData } from '../model/login';
import * as styles from '../styles/loginForm.css';

export default function LoginForm() {
const [loginError, setLoginError] = useState<string | null>(null);

const {
register,
handleSubmit,
Expand All @@ -18,13 +21,23 @@ export default function LoginForm() {
},
});

useEffect(() => {
if (errors.userId || errors.password) {
setLoginError(null);
}
}, [errors.userId, errors.password]);

const { mutate: submitLogin, isPending } = useSubmitLogin({
onSuccess: () => {
window.location.reload();
},
onError: errorCode => {
setLoginError(errorCode);
},
});

const onSubmit = (data: LoginFormData) => {
setLoginError(null);
submitLogin(data);
};

Expand Down Expand Up @@ -56,6 +69,7 @@ export default function LoginForm() {
<p className={styles.errorMessage}>{errors.password.message}</p>
)}
</div>
{loginError && <p className={styles.errorMessage}>{loginError}</p>}
<Button
size='md'
type='submit'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { style } from '@vanilla-extract/css';
import { style, globalStyle } from '@vanilla-extract/css';

import { vars } from '~/vars.css';

Expand Down Expand Up @@ -28,6 +28,10 @@ export const quillEditor = style({
borderRadius: vars.radius.sm,
});

globalStyle(`${quillEditor} .ql-editor`, {
minHeight: '200px',
});

export const saveButtonWrapper = style({
display: 'flex',
justifyContent: 'flex-end',
Expand Down
1 change: 1 addition & 0 deletions apps/graduate/src/shared/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ERROR_CODE_MESSAGES: Record<string, string> = {
GRADUATION_USER_ID_DUPLICATED: '이미 등록된 학번입니다.',
USER_ID_NOT_FOUND: '유저 목록에 없는 학번입니다.',
USER_NOT_FOUND: '유저 목록에 없는 학번입니다.',
INVALID_PASSWORD: '비밀번호가 올바르지 않습니다.',
};

function getDefaultMessage(statusCode?: number): string {
Expand Down
Loading