Skip to content

Commit

Permalink
fix : formData 가져오는 과정에서 worktime이 읽어지지 않는 문제 해결
Browse files Browse the repository at this point in the history
- worktime을 배열로 받아와서 쉼표로 자르는 부분을 추가함

ref : #18
  • Loading branch information
minseoKim-11 committed Nov 9, 2024
1 parent 5e1f370 commit 021494a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 50 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"start": "PORT=8080 react-scripts start"
},
"dependencies": {
"@reduxjs/toolkit": "^2.3.0",
Expand Down
3 changes: 2 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { verifyCEOAPI, signupUserAPI, signupCEOAPI } from "./signupAPI";
import { loginAPI } from "./loginAPI";
import{} from "./postingAPI";
import{ postJobPosting } from "./postingAPI";

export {
verifyCEOAPI, // 사업자 인증 API
signupUserAPI, // 일반유저 회원가입 API
signupCEOAPI, // 사업자유저 회원가입 API
loginAPI, // 로그인 API
postJobPosting,
};
78 changes: 37 additions & 41 deletions src/api/postingAPI.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,49 @@
import { privateAxios } from "../utils/customAxios";

export const postJobPosting = async (accessToken, dispatch, formData) => {
const { doName, siName, detailName } = formData.workLocation;
const [startHour, startMinute] = formData.workTime.start.split(":").map(Number);
const [endHour, endMinute] = formData.workTime.end.split(":").map(Number);
const workDays = formData.workDays.join(", ");
const { workLocation = "" } = formData;
const [doName = "", siName = "", detailName = ""] = workLocation.split(" ");
const { start = "09:00", end = "18:00" } = formData.workTime || {};

const [startHour, startMinute] = start.split(":").map(Number);
const [endHour, endMinute] = end.split(":").map(Number);
const body = {
postId: 0,
userId: 1,
storeName: formData.storeName,
postData: {
doName,
siName,
detailName,
workType: formData.workTags[0] || "기타",
title: formData.title,
content: formData.description,
pay: parseInt(formData.pay, 10),
workStartHour: startHour,
workStartMinute: startMinute,
workEndHour: endHour,
workEndTimeMinute: endMinute,
isNegotiable: formData.isNegotiable || false,
applyNumber: formData.applyNumber,
workDays,
isShortTermJob: formData.workPeriod === "단기",
payType: formData.payType,
isNumberPublic: formData.isNumberPublic,
imageList: [""], // 일단 이미지는 빈 배열로 냅둠
},
postId: 0,
userId: 1,
storeName: formData.storeName,
postData: {
doName,
siName,
detailName,
workType: Array.isArray(formData.workTags) && formData.workTags.length > 0 ? formData.workTags[0] : "기타",
title: formData.title,
content: formData.description,
pay: parseInt(formData.pay, 10),
workStartHour: startHour,
workStartMinute: startMinute,
workEndHour: endHour,
workEndTimeMinute: endMinute,
isNegotiable: formData.isNegotiable || false,
applyNumber: formData.applyNumber,
workDays: formData.workDays,
isShortTermJob: formData.workPeriod === "단기",
payType: formData.payType,
isNumberPublic: formData.isNumberPublic,
imageList: [""],
},
};

const response = {
isSuccess: false,
message: "",
};


const response = { isSuccess: false, message: "" };

try {
// 서버로 API 호출
const result = await privateAxios(accessToken, dispatch).post("/post", body);

if (result.status === 200) {
const result = await privateAxios(accessToken, dispatch).post("/post", body);
if (result.status === 200) {
response.isSuccess = true;
response.message = result.data.message;
}
}
} catch (error) {
response.message = error.message;
response.message = error.message;
}

return response;
};
};
2 changes: 1 addition & 1 deletion src/pages/home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function Home() {
<div className="header-icons">
<IconUserCircle onClick={() => navigate("/mypage")} />
{userType === "CEO" && (
<IconPencilPlus onClick={() => navigate("/post")} />
<IconPencilPlus onClick={() => navigate("/posting")} />
)}
</div>
</HeaderMenuContainer>
Expand Down
13 changes: 8 additions & 5 deletions src/pages/recruitment/Posting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {InputField,Tag,Toggle,WeekdayPicker,WorkTimePicker,PayPicker,AddressInpu
import "../../styles/posting/Posting.css";
import { POSTING_UPMU_TAG } from "../../constants";

import { postJobPosting } from "../../api";
import { getAccessToken } from "../../utils/getAccessToken";
import {postJobPosting} from "../../api";
import getAccessToken from "../../utils/getAccessToken";
import { useDispatch } from "react-redux";

const Posting = () => {
Expand Down Expand Up @@ -131,17 +131,20 @@ const Posting = () => {
};
const dispatch = useDispatch();
const accessToken = getAccessToken();

console.log("Access Token:", accessToken);

const handleSubmit = async () => {
const allValid = Object.values(validStates).every((isValid) => isValid);
if (!allValid) {
alert("모든 필드를 올바르게 입력해주세요.");
return;
}

const payload = createPayload(); // payload 생성
if (!validateForm(payload, formData)) return; // 유효성 검사 실패 시 중단

if (!validateForm(payload, formData)) return;
postJobPosting(accessToken, dispatch, formData).then((response) => {
});
// API 호출
const response = await postJobPosting(accessToken, dispatch, payload.postData);
if (response.isSuccess) {
Expand Down
5 changes: 4 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
server: {
port: 8080, // 원하는 포트 번호를 설정
},
})

0 comments on commit 021494a

Please sign in to comment.