Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 17 additions & 0 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Icon } from '@/components/icon';
import { LoginForm } from '@/components/pages/login';
import { AuthSwitch } from '@/components/shared';

const LoginPage = () => {
return (
<div className='flex-col-center min-h-[calc(100dvh-113px)] gap-10 overflow-auto bg-gray-100 px-4 py-15'>
<div className='flex-col-center w-full gap-4'>
<Icon id='wego-logo' className='h-19.5 w-45' />
<LoginForm />
</div>
<AuthSwitch type='signup' />
</div>
);
};

export default LoginPage;
17 changes: 17 additions & 0 deletions src/app/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Icon } from '@/components/icon';
import { SignupForm } from '@/components/pages/signup';
import { AuthSwitch } from '@/components/shared';

const SignupPage = () => {
return (
<div className='flex-col-center min-h-[calc(100dvh-113px)] gap-10 overflow-auto bg-gray-100 px-4 py-15'>
<div className='flex-col-center w-full gap-4'>
<Icon id='wego-logo' className='h-19.5 w-45' />
<SignupForm />
</div>
<AuthSwitch type='login' />
</div>
);
};

export default SignupPage;
32 changes: 13 additions & 19 deletions src/components/pages/login/login-form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
'use client';

import { useForm } from '@tanstack/react-form';
import { type AnyFieldApi, useForm } from '@tanstack/react-form';

import { FormInput } from '@/components/shared';
import { Button } from '@/components/ui';
import { loginSchema } from '@/lib/schema/auth';

const getHintMessage = (errors: unknown[], isTouched: boolean, submissionAttempts: number) => {
const getHintMessage = (field: AnyFieldApi) => {
const {
meta: { errors, isTouched },
} = field.state;
const { submissionAttempts } = field.form.state;

Comment on lines +9 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍

const firstError = errors[0] as { message?: string } | undefined;
const showError = isTouched || submissionAttempts > 0;

Expand Down Expand Up @@ -40,10 +45,7 @@ export const LoginForm = () => {
<div className='flex-col-center w-full gap-4'>
<form.Field name='email'>
{(field) => {
const {
meta: { errors, isTouched },
} = field.state;
const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts);
const hintMessage = getHintMessage(field);

return (
<FormInput
Expand All @@ -63,10 +65,7 @@ export const LoginForm = () => {

<form.Field name='password'>
{(field) => {
const {
meta: { errors, isTouched },
} = field.state;
const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts);
const hintMessage = getHintMessage(field);

return (
<FormInput
Expand All @@ -88,19 +87,14 @@ export const LoginForm = () => {
selector={(state) => ({
canSubmit: state.canSubmit,
isSubmitting: state.isSubmitting,
isPristine: state.isPristine,
})}
>
{({ canSubmit, isSubmitting }) => {
const disabled = !canSubmit || isSubmitting;
{({ canSubmit, isSubmitting, isPristine }) => {
const disabled = !canSubmit || isSubmitting || isPristine;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPristine이 isDirty의 반대군요 신기하네요

isPristine 조건은 혹시 모를 상황을 대비해 넣으신거라고 이해하면 될까요??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그것도 있고, 맨 처음 페이지에 들어갔을 때 버튼이 비활성화 상태인게 고정되어 있었으면 해서 한 번 써봤습니다.


return (
<Button
className='border-none'
disabled={disabled}
size='md'
type='submit'
variant='primary'
>
<Button disabled={disabled} size='md' type='submit' variant='primary'>
로그인하기
</Button>
);
Expand Down
42 changes: 15 additions & 27 deletions src/components/pages/signup/signup-form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
'use client';

import { useForm } from '@tanstack/react-form';
import { type AnyFieldApi, useForm } from '@tanstack/react-form';

import { FormInput } from '@/components/shared';
import { Button } from '@/components/ui';
import { signupSchema } from '@/lib/schema/auth';

const getHintMessage = (errors: unknown[], isTouched: boolean, submissionAttempts: number) => {
const getHintMessage = (field: AnyFieldApi) => {
const {
meta: { errors, isTouched },
} = field.state;
const { submissionAttempts } = field.form.state;

const firstError = errors[0] as { message?: string } | undefined;
const showError = isTouched || submissionAttempts > 0;

Expand Down Expand Up @@ -42,10 +47,7 @@ export const SignupForm = () => {
<div className='flex-col-center w-full gap-4'>
<form.Field name='email'>
{(field) => {
const {
meta: { errors, isTouched },
} = field.state;
const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts);
const hintMessage = getHintMessage(field);

return (
<FormInput
Expand All @@ -64,10 +66,7 @@ export const SignupForm = () => {

<form.Field name='nickname'>
{(field) => {
const {
meta: { errors, isTouched },
} = field.state;
const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts);
const hintMessage = getHintMessage(field);

return (
<FormInput
Expand All @@ -85,10 +84,7 @@ export const SignupForm = () => {

<form.Field name='password'>
{(field) => {
const {
meta: { errors, isTouched },
} = field.state;
const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts);
const hintMessage = getHintMessage(field);

return (
<FormInput
Expand All @@ -107,10 +103,7 @@ export const SignupForm = () => {

<form.Field name='confirmPassword'>
{(field) => {
const {
meta: { errors, isTouched },
} = field.state;
const hintMessage = getHintMessage(errors, isTouched, form.state.submissionAttempts);
const hintMessage = getHintMessage(field);

return (
<FormInput
Expand All @@ -132,19 +125,14 @@ export const SignupForm = () => {
selector={(state) => ({
canSubmit: state.canSubmit,
isSubmitting: state.isSubmitting,
isPristine: state.isPristine,
})}
>
{({ canSubmit, isSubmitting }) => {
const disabled = !canSubmit || isSubmitting;
{({ canSubmit, isSubmitting, isPristine }) => {
const disabled = !canSubmit || isSubmitting || isPristine;

return (
<Button
className='border-none'
disabled={disabled}
size='md'
type='submit'
variant='primary'
>
<Button disabled={disabled} size='md' type='submit' variant='primary'>
회원가입하기
</Button>
);
Expand Down
33 changes: 33 additions & 0 deletions src/components/shared/auth-switch-link/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Link from 'next/link';

const authSwitchContent = {
login: {
description: '이미 회원이신가요?',
linkText: '로그인하기',
href: '/login',
},
signup: {
description: 'WEGO가 처음이신가요?',
linkText: '회원가입하기',
href: '/signup',
},
} as const;

type AuthSwitchType = keyof typeof authSwitchContent;

interface AuthSwitchProps {
type?: AuthSwitchType;
}

export const AuthSwitch = ({ type = 'login' }: AuthSwitchProps) => {
const content = authSwitchContent[type];

return (
<p className='flex-center bg-mono-white text-text-sm-medium gap-1 rounded-full px-4 py-2 text-gray-600'>
{content.description}
<Link href={content.href} className='text-mint-600 text-text-sm-semibold'>
{content.linkText}
</Link>
</p>
);
};
1 change: 1 addition & 0 deletions src/components/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { AuthSwitch } from './auth-switch-link';
export { FormInput } from './form-input';
export { SearchBar } from './search-bar';
export { TabNavigation } from './tab-navigation';