Skip to content

Commit

Permalink
feat :: 재지원 API 및 반려사유 API
Browse files Browse the repository at this point in the history
  • Loading branch information
KANGYONGSU23 committed Dec 5, 2023
1 parent 582551d commit 7f4b672
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
68 changes: 65 additions & 3 deletions src/apis/applications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { useToastStore } from "@team-return/design-system";
import { AxiosError } from "axios";
import { useRouter } from "next/navigation";
import { instance } from "../axios";
import { ApplicationsResponseType, ApplyRequestItmeType } from "./type";
import {
ApplicationsResponseType,
ApplyRequestItmeType,
RejectionResponseType,
} from "./type";

const router = "/applications";

export default function useApplyToCompany(recruitmentId: string) {
export function useApplyToCompany(recruitmentId: string) {
const navigator = useRouter();
const { append } = useToastStore();
return useMutation(
Expand Down Expand Up @@ -52,7 +56,6 @@ export default function useApplyToCompany(recruitmentId: string) {
);
}


export function useGetApplications() {
return useQuery(["GetApplications"], async () => {
const { data } = await instance.get<ApplicationsResponseType>(
Expand All @@ -61,3 +64,62 @@ export function useGetApplications() {
return data;
});
}

export function useReapply(applicationId: string | null) {
const navigator = useRouter();
const { append } = useToastStore();
return useMutation(
async (body: ApplyRequestItmeType[]) =>
await instance.put(`${router}/${applicationId}`, {
attachments: body,
}),
{
onSuccess: () => {
navigator.push("/mypage");
},
onError: (error: AxiosError) => {
switch (error.response?.status) {
case 400:
append({
title: "",
message: "승인요청또는 반려상태가 아닙니다.",
type: "RED",
});
case 401:
append({
title: "",
message: "3학년이 아닌 학생은 지원할 수 없습니다.",
type: "RED",
});
break;
case 404:
append({
title: "",
message: "모집의뢰서가 존재하지 않습니다.",
type: "RED",
});
break;
case 409:
append({
title: "",
message:
"이미 해당 모집의뢰에 지원했거나 승인된 지원요청이 존재합니다.",
type: "RED",
});

default:
break;
}
},
}
);
}

export function useGetRejectionReason(applicationid: string) {
return useQuery(["GetRejectionReason"], async () => {
const { data } = await instance.get<RejectionResponseType>(
`${router}/rejection/${applicationid}`
);
return data;
});
}
9 changes: 7 additions & 2 deletions src/apis/applications/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ApplicationsStatusType =
| "REJECTED";

export interface ApplicationItemType {
recruitment_id: number;
application_id: number;
company: string;
attachments: ApplyRequestItmeType[];
Expand All @@ -21,9 +22,13 @@ export interface ApplicationItemType {

export interface ApplicationsResponseType {
applications: ApplicationItemType[];
count: number
count: number;
}

export interface ApplyRequestBody {
attachments: ApplyRequestItmeType[];
}
}

export interface RejectionResponseType {
rejection_reason: string;
}

0 comments on commit 7f4b672

Please sign in to comment.