Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Collection50 committed Aug 28, 2024
2 parents 45811b1 + 144b1cd commit 4b7d459
Show file tree
Hide file tree
Showing 39 changed files with 2,041 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ yarn-error.log*

# local env files
.env*.local
.env

# vercel
.vercel
Expand Down
8 changes: 4 additions & 4 deletions src/apis/http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { serverErrorType } from '@/types/api';
import { isProductionEnv } from '@/utils/common';
import type {
AxiosError,
Expand Down Expand Up @@ -47,11 +46,11 @@ axiosInstance.interceptors.response.use(

async (error: AxiosError) => {
if (axios.isAxiosError(error)) {
const data = error.response?.data as serverErrorType;
const status = error.response?.status;
const refreshToken = getCookie('refreshToken');

if (refreshToken) {
if (data?.status === 'UNAUTHORIZED') {
if (status === 401) {
if (refreshToken) {
deleteCookie('accessToken');
deleteCookie('refreshToken');
try {
Expand All @@ -62,6 +61,7 @@ axiosInstance.interceptors.response.use(
window.location.href = '/login';
}
}
window.location.href = '/login';
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/useDeleteRecruit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { http } from '@/apis/http';
import { useMutation, useQueryClient } from '@tanstack/react-query';

const deleteRecruit = (id: string) => {
return http.delete({
url: `/recruits/${id}`,
});
};

export const useDeleteRecruit = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: deleteRecruit,
});
};
21 changes: 21 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/useGetAllTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { http } from '@/apis/http';
import { TagType } from '@/types';
import { useSuspenseQuery } from '@tanstack/react-query';

const getAllTags = () => {
return http.get<TagType[]>({
url: `/tags`,
});
};

export function useGetAllTags() {
const result = useSuspenseQuery({
queryKey: ['get-all-tags'],
queryFn: async () => {
const res = await getAllTags();
return res.data;
},
});

return result;
}
22 changes: 22 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/useGetCardCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { http } from '@/apis/http';
import { useSuspenseQuery } from '@tanstack/react-query';

type getCardCountType = Record<'서류_준비' | '과제_준비' | '인터뷰_준비', number>;

const getCardCount = (id: string) => {
return http.get<getCardCountType>({
url: `/recruits/${id}/cards/type-count`,
});
};

export function useGetCardCount(id: string) {
const result = useSuspenseQuery({
queryKey: ['get-progress-recruit'],
queryFn: async () => {
const res = await getCardCount(id);
return res.data;
},
});

return result;
}
35 changes: 35 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/useGetProgressRecruit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { http } from '@/apis/http';
import { useSuspenseQuery } from '@tanstack/react-query';

export interface NearestScheduleType {
id: number;
recruitScheduleStage: string;
deadLine: string;
}
export interface ProgressRecruitType {
id: number;
title: string;
season: string;
siteUrl: string;
recruitStatus: string;
createdDate: string;
nearestSchedule: NearestScheduleType | null;
}

const getProgressRecruit = () => {
return http.get<ProgressRecruitType[]>({
url: `/recruits/progressing`,
});
};

export function useGetProgressRecruit() {
const result = useSuspenseQuery({
queryKey: ['get-progress-recruit'],
queryFn: async () => {
const res = await getProgressRecruit();
return res.data;
},
});

return result;
}
28 changes: 28 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/useGetRecruitById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { http } from '@/apis/http';
import { useSuspenseQuery } from '@tanstack/react-query';

interface recruitByIdType {
id: number;
title: string;
season: string;
siteUrl: string;
recruitStatus: string;
}

const getRecruitById = (id: string) => {
return http.get<recruitByIdType>({
url: `/recruits/${id}`,
});
};

export function useGetRecruitById(id: string) {
const result = useSuspenseQuery({
queryKey: ['get-recruit-by-id', id],
queryFn: async () => {
const res = await getRecruitById(id);
return res.data;
},
});

return result;
}
28 changes: 28 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/useGetRecruitCards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { http } from '@/apis/http';
import { TagType } from '@/types';
import { useSuspenseQuery } from '@tanstack/react-query';

export type GetRecruitCardsType = {
id: number;
title: string;
updatedDate: string;
tagList: TagType[];
};

const getRecruitCards = ({ id, progress }: { id: string; progress: string }) => {
return http.get<GetRecruitCardsType[]>({
url: `recruits/${id}/cards?type=${progress}`,
});
};

export function useGetRecruitCards({ id, progress }: { id: string; progress: string }) {
const result = useSuspenseQuery({
queryKey: ['get-recruit-card-id', id, progress],
queryFn: async () => {
const res = await getRecruitCards({ id, progress });
return res.data;
},
});

return result;
}
24 changes: 24 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/useGetSeason.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { http } from '@/apis/http';
import { useSuspenseQuery } from '@tanstack/react-query';

export interface SeasonType {
name: string;
}

const getSeasons = () => {
return http.get<SeasonType[]>({
url: `/seasons`,
});
};

export function useGetSeasons() {
const result = useSuspenseQuery({
queryKey: ['get-seasons'],
queryFn: async () => {
const res = await getSeasons();
return res.data;
},
});

return result;
}
32 changes: 32 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/usePatchSeason.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { http } from '@/apis/http';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { ProgressRecruitType } from './useGetProgressRecruit';

interface PatchSeasonProps {
newSeason: string;
id: string;
}

const patchSeason = ({ newSeason, id }: PatchSeasonProps) => {
return http.patch<ProgressRecruitType>({
url: `/recruits/${id}/season`,
data: {
season: newSeason,
},
});
};

export const usePatchSeason = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({ newSeason, id }: PatchSeasonProps) => {
const res = await patchSeason({ newSeason, id });

return res.data;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['get-recruit-by-id'] });
},
});
};
32 changes: 32 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/usePatchSiteUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { http } from '@/apis/http';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { ProgressRecruitType } from './useGetProgressRecruit';

interface patchSiteProps {
newSiteUrl: string;
id: string;
}

const patchSiteUrl = ({ newSiteUrl, id }: patchSiteProps) => {
return http.patch<ProgressRecruitType>({
url: `/recruits/${id}/siteUrl`,
data: {
siteUrl: newSiteUrl,
},
});
};

export const usePatchSiteUrl = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({ newSiteUrl, id }: patchSiteProps) => {
const res = await patchSiteUrl({ newSiteUrl, id });

return res.data;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['get-recruit-by-id'] });
},
});
};
37 changes: 37 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/usePatchStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { http } from '@/apis/http';
import { useMutation, useQueryClient } from '@tanstack/react-query';

interface PatchStatusResponse {
status: string;
}

interface patchStatusProps {
newStatus: string;
id: string;
}

const patchStatus = ({ newStatus, id }: patchStatusProps) => {
return http.patch<PatchStatusResponse>({
url: `/recruits/${id}/status`,
data: {
recruitStatus: newStatus,
},
});
};

export const usePatchStatus = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({ newStatus, id }: patchStatusProps) => {
const res = await patchStatus({ newStatus, id });

console.log(res);

return res.data;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['get-recruit-by-id'] });
},
});
};
35 changes: 35 additions & 0 deletions src/app/(sidebar)/my-recruit/[id]/api/usePatchTitle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { http } from '@/apis/http';
import { useMutation, useQueryClient } from '@tanstack/react-query';

interface PatchTitleResponse {
title: string;
}

interface patchTitleProps {
newTitle: string;
id: string;
}

const patchTitle = ({ newTitle, id }: patchTitleProps) => {
return http.patch<PatchTitleResponse>({
url: `/recruits/${id}/title`,
data: {
title: newTitle,
},
});
};

export const usePatchTitle = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({ newTitle, id }: patchTitleProps) => {
const res = await patchTitle({ newTitle, id });

return res.data;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['get-recruit-by-id'] });
},
});
};
Loading

0 comments on commit 4b7d459

Please sign in to comment.