-
Notifications
You must be signed in to change notification settings - Fork 0
회원가입 기능 추가, safeFetch 정리 #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| 'use client'; | ||
|
|
||
| import Button from '@/components/basics/Button/Button'; | ||
| import Input from '@/components/basics/Input/Input'; | ||
| import Label from '@/components/basics/Label/Label'; | ||
| import { useSignupSubmit } from '@/hooks/server/useSignup'; | ||
|
|
||
| import { useSignupForm } from './useSignupForm'; | ||
|
|
||
| const SignupPage = () => { | ||
| const { | ||
| register, | ||
| handleSubmit, | ||
| formState: { errors, isValid, isSubmitting }, | ||
| } = useSignupForm(); | ||
|
|
||
| const { submit, isPending } = useSignupSubmit(); | ||
|
|
||
| return ( | ||
| <div className="flex h-screen w-screen flex-col items-center justify-center gap-10"> | ||
| <span className="font-title-md">회원가입</span> | ||
| <form onSubmit={handleSubmit(submit)} className="space-y-5"> | ||
| {/* 이메일 */} | ||
| <Label htmlFor="email">이메일</Label> | ||
| <div> | ||
| <Input | ||
| {...register('email')} | ||
| id="email" | ||
| type="email" | ||
| placeholder="이메일을 입력해주세요" | ||
| autoComplete="email" | ||
| className={errors.email && 'border-red500 focus:border-red-500'} | ||
| /> | ||
| {errors.email && <span className="text-red-500">{errors.email?.message}</span>} | ||
| </div> | ||
|
|
||
| {/* 비밀번호 */} | ||
| <Label htmlFor="password">비밀번호</Label> | ||
| <div> | ||
| <Input | ||
| {...register('password')} | ||
| id="password" | ||
| placeholder="8자 이상 입력해 주세요" | ||
| autoComplete="new-password" | ||
| className={errors.password && 'border-red500 focus:border-red-500'} | ||
| /> | ||
| {errors.password && <span className="text-red-500">{errors.password?.message}</span>} | ||
| </div> | ||
| <Button | ||
| className="mt-2" | ||
| type="submit" | ||
| label="회원가입하기" | ||
| disabled={!isValid || isSubmitting || isPending} | ||
| /> | ||
| </form> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SignupPage; | ||
|
Bangdayeon marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import SignupPage from './SignupPage'; | ||
|
|
||
| export default function Page() { | ||
| return <SignupPage />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 'use client'; | ||
|
|
||
| import { SignupFormValues, SignupSchema } from '@/types/api/authApi'; | ||
| import { zodResolver } from '@hookform/resolvers/zod'; | ||
| import { useForm } from 'react-hook-form'; | ||
|
|
||
| export const useSignupForm = () => { | ||
| const form = useForm<SignupFormValues>({ | ||
| resolver: zodResolver(SignupSchema), | ||
| mode: 'onChange', | ||
| defaultValues: { email: '', password: '' }, | ||
| }); | ||
|
|
||
| return form; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { handleApiError, parseJsonBody, safeFetch, validateRequest } from '@/hooks/util/api'; | ||
| import { SignupRequestSchema, SignupResponse } from '@/types/api/authApi'; | ||
| import { NextRequest } from 'next/server'; | ||
|
|
||
| const BASE_API_URL = process.env.NEXT_PUBLIC_BASE_API_URL; | ||
| if (!BASE_API_URL) { | ||
| throw new Error('Missing environment variable: NEXT_PUBLIC_BASE_API_URL'); | ||
| } | ||
| const BASE_URL = `${BASE_API_URL}/v1/member`; | ||
|
|
||
| export async function POST(req: NextRequest) { | ||
| try { | ||
| const body = await parseJsonBody(req); | ||
| const data = validateRequest(SignupRequestSchema, body); | ||
|
|
||
| const result = await safeFetch<SignupResponse>(`${BASE_URL}/signup`, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify(data), | ||
| }); | ||
|
|
||
| return Response.json(result, { status: 200 }); | ||
| } catch (err) { | ||
| return handleApiError(err); | ||
| } | ||
| } | ||
|
Bangdayeon marked this conversation as resolved.
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { tv } from 'tailwind-variants'; | ||
|
|
||
| export const style = tv({ | ||
| base: 'flex h-10 items-center px-3 text-gray-800 placeholder-gray-400', | ||
| variants: { | ||
| size: { | ||
| sm: 'w-32', | ||
| md: 'w-60', | ||
| lg: 'w-full', | ||
| }, | ||
| radius: { | ||
| none: 'rounded-none', | ||
| sm: 'rounded-sm', | ||
| md: 'rounded-md', | ||
| lg: 'rounded-full', | ||
| }, | ||
| variant: { | ||
| outline: 'border border-gray-300 bg-white focus-within:border-gray-600', | ||
| filled: 'bg-blue-200 focus-within:bg-blue-300', | ||
| }, | ||
| disabled: { | ||
| true: 'pointer-events-none opacity-50', | ||
| false: '', | ||
| }, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.