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

feat: 회원가입 폼 api 연결 #127

Merged
merged 4 commits into from
Jan 3, 2024
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
25 changes: 25 additions & 0 deletions src/apis/oauth/signup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useMutation } from '@tanstack/react-query';

import client from '@apis/fetch';

interface SingnUpRequestDTO {
memberId: number;
nickname: string;
birth: string;
gender: string;
job: string;
}

const signup = (req: SingnUpRequestDTO) => {
return client.post({
path: '/auth/signup/profile',
body: req,
});
};

const useSignup = () => {
return useMutation({ mutationFn: signup });
};

export { useSignup };
export type { SingnUpRequestDTO };
4 changes: 2 additions & 2 deletions src/components/commons/RadioInput/RadioInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { RegisterOptions, useFormContext } from 'react-hook-form';
import { ConfigKeys } from 'src/constants/form';
import { ConfigKeys, InputType } from 'src/constants/form';
import { styled } from 'styled-components';

import { colors } from '@styles/theme';
Expand All @@ -15,7 +15,7 @@ interface RadioOption {
}

interface RadioInputProps {
id: ConfigKeys;
id: InputType;
options: RegisterOptions;
radioOptions: RadioOption[];
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/commons/SelectInput/SelectInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { RegisterOptions, useFormContext } from 'react-hook-form';
import { ConfigKeys } from 'src/constants/form';
import { ConfigKeys, InputType } from 'src/constants/form';
import { styled } from 'styled-components';

import { colors } from '@styles/theme';
Expand All @@ -16,7 +16,7 @@ interface SelectOption {
}

interface SelectInputProps {
id: ConfigKeys;
id: InputType;
options: RegisterOptions;
selectOptions: SelectOption[];
placeholder: string;
Expand Down
4 changes: 2 additions & 2 deletions src/components/commons/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { RegisterOptions, useFormContext } from 'react-hook-form';
import { ConfigKeys } from 'src/constants/form';
import { ConfigKeys, InputType } from 'src/constants/form';

import { colors } from '@styles/theme';

Expand All @@ -15,7 +15,7 @@ import {
} from './TextInput.styles';

interface TextInputProps {
id: ConfigKeys;
id: InputType;
options: RegisterOptions;
placeholder: string;
type?: React.HTMLInputTypeAttribute;
Expand Down
9 changes: 5 additions & 4 deletions src/constants/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ interface ConfigField {
}

export const INPUT_TYPE = {
NICKNAME: 'NICKNAME',
BIRTHDAY: 'BIRTHDAY',
GENDER: 'GENDER',
JOB: 'JOB',
NICKNAME: 'nickname',
BIRTHDAY: 'birth',
GENDER: 'gender',
JOB: 'job',
} as const;

export type ConfigKeys = keyof typeof INPUT_TYPE;
export type InputType = (typeof INPUT_TYPE)[keyof typeof INPUT_TYPE];

export const CONFIG: Record<ConfigKeys, ConfigField> = {
NICKNAME: {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Auth/signup/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Signup = () => {
return (
<Funnel>
<Funnel.Step name="정보입력">
<정보입력 />
<정보입력 memberId={state.memberId} />
</Funnel.Step>
<Funnel.Step name="가입성공">
<가입성공 />
Expand Down
17 changes: 7 additions & 10 deletions src/routes/Auth/signup/정보입력.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormProvider, SubmitHandler, useForm } from 'react-hook-form';
import { CONFIG, INPUT_TYPE } from 'src/constants/form';
import { GENDERS, JOBS } from 'src/constants/signup';

import { SingnUpRequestDTO, useSignup } from '@apis/oauth/signup';
import { Col } from '@components/commons/Flex/Flex';
import InputField from '@components/commons/InputField/InputField';
import Layout from '@components/commons/Layout/Layout';
Expand All @@ -15,15 +16,11 @@ import { colors } from '@styles/theme';

import { FormContainer, NextButton } from './정보입력.styles';

export interface SignUpForm {
NICKNAME: string;
BIRTHDAY: string;
GENDER: 'male' | 'female';
JOB: string;
}
type SignupForm = Omit<SingnUpRequestDTO, 'memberId'>;

const 정보입력 = () => {
const methods = useForm<SignUpForm>({ mode: 'onChange' });
const 정보입력 = ({ memberId }: { memberId: number }) => {
const methods = useForm<Omit<SingnUpRequestDTO, 'memberId'>>({ mode: 'onChange' });
const signupMutation = useSignup();

const birthdayInput = methods.watch(INPUT_TYPE.BIRTHDAY);
const nicknameProgress = methods.watch(INPUT_TYPE.NICKNAME)
Expand All @@ -39,8 +36,8 @@ const 정보입력 = () => {
}
};

const handleSubmitForm: SubmitHandler<SignUpForm> = (data) => {
console.log(data);
const handleSubmitForm: SubmitHandler<SignupForm> = (data) => {
signupMutation.mutate({ ...data, memberId });
};

useEffect(() => {
Expand Down