Skip to content

Commit

Permalink
fix: /programs request body, 항목 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
iOdiO89 committed Jul 1, 2024
1 parent 2548626 commit 188db7b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
4 changes: 3 additions & 1 deletion apis/admin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { CalendarDate } from "./calendar";
import client, { ResponseBody } from "./client";

export interface Program {
name: string;
dueDate: CalendarDate;
startDate: CalendarDate;
openDate: CalendarDate;
location: string;
category: string;
host: string;
schedule: string;
description: string;
Expand Down
8 changes: 7 additions & 1 deletion apis/hooks/admin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { useMutation } from "@tanstack/react-query";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { Program, postAttendanceCode, postProgram } from "../admin";
import { useRouter } from "next/router";

function usePostProgram() {
const router = useRouter();
const queryclient = useQueryClient();

const { mutate } = useMutation({
mutationKey: ["postProgram"],
mutationFn: (body: Program) => postProgram(body),
onSuccess: () => {
queryclient.invalidateQueries({
queryKey: ["getMyChallengeList"],
});
window.alert("프로그램이 성공적으로 등록되었습니다.");
router.push("/");
},
onError: () => router.push("/404"),
});

return { mutate };
Expand Down
16 changes: 13 additions & 3 deletions components/challenge/ChallengeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,19 @@ export default function ChallengeInput({
break;
case "dropdown":
return (
<FlexBox className="w-full justify-between gap-2 text-Black">
<Dropdown options={locationOptions} placeholder="지역" />
<Dropdown options={typeOptions} placeholder="종류" />
<FlexBox className="w-full justify-between gap-2 text-black">
<Dropdown
options={locationOptions}
placeholder="지역"
value={value}
onChange={(arg) => setValue(arg.value)}
/>
<Dropdown
options={typeOptions}
placeholder="분야"
value={value2}
onChange={(arg) => setValue2(arg.value)}
/>
</FlexBox>
);
break;
Expand Down
29 changes: 12 additions & 17 deletions pages/challenge/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ dayjs.locale("ko");

const AddChallenge: NextPage = () => {
const [name, setName] = useState<string>("");
const [location, setLocation] = useState<string>("");
const [phoneNum, setPhoneNum] = useState<string>("");
const [detail, setDetail] = useState<string>("");
const [startDate, setStartDate] = useState<string>("");
const [endDate, setEndDate] = useState<string>("");
const [location, setLocation] = useState<string>("");
const [category, setCategory] = useState<string>("");
const [host, setHost] = useState<string>("");
const [phoneNum, setPhoneNum] = useState<string>("");
const [detail, setDetail] = useState<string>("");

const { mutate } = usePostProgram();

Expand All @@ -30,13 +31,14 @@ const AddChallenge: NextPage = () => {
month: Number(dayjs(endDate).format("M")),
day: Number(dayjs(endDate).format("D")),
},
startDate: {
openDate: {
year: Number(dayjs(startDate).format("YYYY")),
month: Number(dayjs(startDate).format("M")),
day: Number(dayjs(startDate).format("D")),
},
location: location,
host: "임시host",
category: category,
host: host,
schedule: dayjs(endDate).format("ddd"),
description:
detail.trim().length === 0
Expand Down Expand Up @@ -67,22 +69,13 @@ const AddChallenge: NextPage = () => {
isError={false}
/>
<ChallengeInput
title="위치"
inputType="text"
value={location}
setValue={setLocation}
isError={false}
placeholder="기관명 또는 도로명주소"
/>
<ChallengeInput
title="태그"
title="지역 및 분야"
inputType="dropdown"
value={location}
setValue={setLocation}
value2={endDate}
setValue2={setEndDate}
value2={category}
setValue2={setCategory}
isError={false}
placeholder="기관명 또는 도로명주소"
/>
<ChallengeInput
title="주최 기관"
Expand Down Expand Up @@ -118,6 +111,8 @@ const AddChallenge: NextPage = () => {
startDate.length === 0 ||
endDate.length === 0 ||
location.length === 0 ||
category.length === 0 ||
host.length === 0 ||
phoneNum.length === 0
}
/>
Expand Down
2 changes: 1 addition & 1 deletion utils/atom.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { atom } from "jotai";

export const isAdminAtom = atom<boolean>(false);
export const isAdminAtom = atom<boolean>(true);

0 comments on commit 188db7b

Please sign in to comment.