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: i18n 번역 데이터 작성, 폴더 및 코드 구조 리팩토링 #89

Merged
merged 8 commits into from
Nov 1, 2024
Prev Previous commit
Next Next commit
feat: 회사 등록 API 연결
  • Loading branch information
YIMSEBIN committed Oct 31, 2024
commit 096bc5c0e7081641ec0fd783aa7bef5c9564bff4
11 changes: 6 additions & 5 deletions src/apis/apiPath.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const BASE_URL = '/api';

export const APIPath = {
postNotice: '/api/recruitments',
allApplication: '/api/application/all',
signEmployeeContract: '/api/contract',
makeEmployerContract: '/api/categories',
downloadContract: '/api/contract/:applyId/download',
postNotice: `${BASE_URL}/recruitments`,
allApplication: `${BASE_URL}/application/all`,
signEmployeeContract: `${BASE_URL}/api/contract`,
makeEmployerContract: `${BASE_URL}/categories`,
downloadContract: `${BASE_URL}/contract/:applyId/download`,
registerSign: '/api/sign',
getMyCompanies: `${BASE_URL}/company`,
getMyRecruitments: `${BASE_URL}/recruitments/company/:companyId`,
getMyApplicants: `${BASE_URL}/application/:recruitmentId`,
getForeigner: `${BASE_URL}/visa/:userId`,
registerVisa: `${BASE_URL}/visa`,
registerCompany: `${BASE_URL}/company`,
apply: '/api/application/',
recruitmentsDetail: '/api/recruitments/:postId',
};
9 changes: 9 additions & 0 deletions src/apis/registerCompany/registerCompany.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { http, HttpResponse } from 'msw';
import { getPostCompanyPath } from './useRegisterCompany';

export const registerCompanyMockHandler = [
http.post(getPostCompanyPath(), async ({ request }) => {
const req = await request.json();
return HttpResponse.json(req, { status: 201 });
}),
];
23 changes: 23 additions & 0 deletions src/apis/registerCompany/useRegisterCompany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { APIPath } from '@/apis/apiPath';
import { clientInstance } from '@/apis/instance';
import { useMutation } from '@tanstack/react-query';

export type CompanyRequestData = {
name?: string;
industryOccupation?: string;
brand?: string;
revenuePerYear?: number;
logoImage?: string;
};

export const getPostCompanyPath = () => `${APIPath.registerCompany}`;

export const postCompany = async (req: CompanyRequestData) => {
const response = await clientInstance.post(getPostCompanyPath(), req);
return response.data;
};

export const useFetchPostCompany = () =>
useMutation({
mutationFn: postCompany,
});
2 changes: 2 additions & 0 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import { foreignerMockHandler } from '@/apis/applicants/mocks/foreignerMockHandl
import { visaMockHandler } from '@/apis/applicants/mocks/visaMockHandler';
import { postApplyMockHandler } from '@apis/apply/postApply.mock';
import { recruitmentsDetailMockHandler } from '@apis/recruitmentsDetail/recruitmentsDetailMockHandler';
import { registerCompanyMockHandler } from '@/apis/registerCompany/registerCompany.mock';

export const handlers = [
...recruitmentsMockHandler,
@@ -24,4 +25,5 @@ export const handlers = [
...visaMockHandler,
...postApplyMockHandler,
...recruitmentsDetailMockHandler,
...registerCompanyMockHandler,
];
50 changes: 45 additions & 5 deletions src/pages/registerCompany/RegisterCompany.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
import { useFetchPostCompany } from '@/apis/registerCompany/useRegisterCompany';
import { Button, Flex, Input, Typo } from '@/components/common';
import Layout from '@/features/layout';
import ROUTE_PATH from '@/routes/path';
import styled from '@emotion/styled';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';

export default function RegisterCompany() {
const mutation = useFetchPostCompany();
const navigate = useNavigate();

const [inputs, setInputs] = useState({
name: '',
industryOccupation: '',
brand: '',
revenuePerYear: 0,
logoImage: '',
});

const { name, industryOccupation, brand, revenuePerYear, logoImage } = inputs;

const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value, name } = e.target;
setInputs({
...inputs,
[name]: value,
});
};

const handlePostCompany = () => {
mutation.mutate(inputs, {
onSuccess: () => {
navigate(ROUTE_PATH.HOME);
},
onError: () => {
// 이부분 에러처리 결정해야함.
alert('값이 정상적으로 저장되지 않았습니다.');
},
});
};
return (
<Layout>
<section>
@@ -17,24 +53,26 @@ export default function RegisterCompany() {
<Input
label="회사 이미지 업로드(선택)"
type="file"
value={logoImage}
onChange={onChange}
// style={{ width: '570px', height: '48px' }}
></Input>
</InputContainer>
<InputContainer>
<Input label="회사명" style={{ width: '570px', height: '48px' }}></Input>
<Input label="회사명" value={name} onChange={onChange} style={InputStyle}></Input>
</InputContainer>
<InputContainer>
<Input label="업직종" style={{ width: '570px', height: '48px' }}></Input>
<Input label="업직종" value={industryOccupation} onChange={onChange} style={InputStyle}></Input>
</InputContainer>
<InputContainer>
<Input label="브랜드" style={{ width: '570px', height: '48px' }}></Input>
<Input label="브랜드" value={brand} onChange={onChange} style={InputStyle}></Input>
</InputContainer>
<InputContainer>
<Input label="연 평균 매출액" style={{ width: '570px', height: '48px' }}></Input>
<Input label="연 평균 매출액" value={revenuePerYear} onChange={onChange} style={InputStyle}></Input>
</InputContainer>
</InputWrapper>
<ButtonWrapper>
<Button design="default" style={{}}>
<Button design="default" onClick={handlePostCompany} style={{}}>
등록하기
</Button>
</ButtonWrapper>
@@ -72,3 +110,5 @@ const ButtonWrapper = styled.div`
justify-content: center;
margin-top: 52px;
`;

const InputStyle = { width: '570px', height: '48px' };