Skip to content

Commit

Permalink
Merge pull request #127 from team-offonoff/feat/signup-api
Browse files Browse the repository at this point in the history
feat: 회원가입 폼 api 연결
  • Loading branch information
Jinho1011 authored Jan 3, 2024
2 parents 77ff4ca + 3c2c253 commit 3b99084
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
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

0 comments on commit 3b99084

Please sign in to comment.