Skip to content
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

REV-400/회원가입 페이지 디자인 수정 #108

Merged
merged 4 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 2 additions & 8 deletions src/apis/hooks/useSignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ interface User {
password: string
}

interface SignUpSuccess {
interface SignUp {
success: boolean
}

interface SignUpFail {
status: string
errorCode: string
message: string
}

const useSignUp = () => {
const signUp = async (user: User) => {
return await apiClient.post<SignUpSuccess | SignUpFail>('/sign-up', user)
return await apiClient.post<SignUp>('/sign-up', user)
}

return useMutation({ mutationFn: signUp })
Expand Down
6 changes: 3 additions & 3 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const Input = ({

return (
<div
className={`flex ${className} ${w} max-w-xs flex-col justify-center gap-[0.44rem] rounded-md border border-gray-100 bg-main-yellow px-[0.63rem] pb-[0.69rem] pt-[0.31rem] focus-within:border-black dark:bg-main-red-200 dark:focus-within:border-white`}
className={`flex ${className} ${w} max-w-xs flex-col justify-center gap-[0.44rem] rounded-md border border-gray-100 bg-main-yellow px-[0.63rem] pb-[0.69rem] pt-[0.31rem] focus-within:border-black dark:border-gray-300 dark:bg-main-red-200 dark:focus-within:border-white`}
>
<div className="flex flex-row justify-between">
<div className="h-4 text-xs text-gray-100 md:text-sm">
<div className="h-4 text-xs text-gray-200 dark:text-gray-100 md:text-sm">
{INPUT_TYPE[type].TITLE}
</div>
{message && (
Expand All @@ -46,7 +46,7 @@ const Input = ({
<input
value={value}
{...register}
className="h-4 flex-1 border-0 bg-transparent text-sm text-black focus:outline-none dark:text-white md:text-lg"
className="h-4 flex-1 border-0 bg-transparent text-sm text-black placeholder:text-gray-100 focus:outline-none dark:text-white md:text-lg"
placeholder={placeholder}
disabled={disabled}
onChange={onChange}
Expand Down
27 changes: 14 additions & 13 deletions src/pages/SignUpPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Input, Header } from '@/components'
import { useSignUp } from '@/apis/hooks'
import { LogoColIcon } from '@/assets/icons'
import { rangers } from '@/assets/images'
import { SignUpFail } from './types'

const SingUpPage = () => {
const navigate = useNavigate()
Expand All @@ -16,8 +17,8 @@ const SingUpPage = () => {
useNameCheck()
const {
password,
passwordConfirm,
passwordFailMessage,
passwordConfirm,
passwordConfirmFailMessage,
handlePasswordChange,
handlePasswordConfirmChange,
Expand All @@ -27,6 +28,10 @@ const SingUpPage = () => {
e.preventDefault()

if (
!name ||
!email ||
!password ||
!passwordConfirm ||
emailFailMessage ||
nameFailMessage ||
passwordFailMessage ||
Expand All @@ -38,19 +43,16 @@ const SingUpPage = () => {
signUp(
{ email, name, password },
{
onSuccess: ({ data }) => {
if ('status' in data && data.status === 'CONFLICT') {
if (data.errorCode === 'EXIST_SAME_NAME') {
setNameFailMessage(data.message)
}
if (data.errorCode === 'EXIST_SAME_EMAIL') {
setEmailFailMessage(data.message)
onSuccess: () => navigate('/'),
onError: (error) => {
if ('response' in error) {
const message = (error.response as SignUpFail).data.message
if (message.includes('이메일')) {
setEmailFailMessage(message)
} else {
setNameFailMessage(message)
}

return
}

navigate('/')
},
},
)
Expand Down Expand Up @@ -91,7 +93,6 @@ const SingUpPage = () => {
message={passwordConfirmFailMessage}
/>
<button
disabled={!email || !name || !password || !passwordConfirm}
className="h-14 w-80 max-w-xs rounded-xl bg-active-orange text-lg text-white hover:border hover:border-black disabled:bg-opacity-50 dark:text-black md:text-xl"
onClick={handleSignUpButtonClick}
>
Expand Down
5 changes: 5 additions & 0 deletions src/pages/SignUpPage/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface SignUpFail {
data: {
message: string
}
}
Loading