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(my-recruit): 내 공고 뽀각 페이지 api 연결 #28

Merged
merged 5 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"react-dom": "^18",
"tailwind-merge": "^2.4.0",
"tailwind-variants": "^0.2.1",
"tailwindcss-animate": "^1.0.7"
"tailwindcss-animate": "^1.0.7",
"ts-pattern": "^5.3.1"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.6.1",
Expand Down
15 changes: 15 additions & 0 deletions src/app/(sidebar)/my-recruit/api/useDeleteRecruit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { http } from '@/apis/http';
import { useMutation } from '@tanstack/react-query';

export const DELETE_RECRUIT_KEY = 'delete-recruit';

export const deleteRecruit = (recruitId: number) =>
http.delete({
url: `/recruits/${recruitId}`,
});

export const useDeleteRecruit = () =>
useMutation({
mutationKey: [DELETE_RECRUIT_KEY],
mutationFn: (recruitId: number) => deleteRecruit(recruitId),
});
27 changes: 27 additions & 0 deletions src/app/(sidebar)/my-recruit/api/useGetAllRecruits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { http } from '@/apis/http';
import { useSuspenseQuery } from '@tanstack/react-query';
import { RecruitCard } from '@/app/(sidebar)/my-recruit/type';
import { ALL_RECRUITMENT } from '@/app/(sidebar)/my-recruit/containers/components/SeasonDropdownContent';

type Request = { season: string };

type Response = { data: RecruitCard[] };

export const GET_RECRUITS = 'recruits';

function getAllRecruits() {
return http.get({ url: '/recruits' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return http.get({ url: '/recruits' });
return http.get<Response>({ url: '/recruits' });

이렇게 사용하면 tanstack-query의 반환값 타입을 명시하지 않아도 가능해요

}

function getRecruitsBySeason({ season }: Request) {
return http.get({ url: '/recruits/bySeason', params: { season } });
}

export function useGetAllRecruits({ season }: Request) {
const result = useSuspenseQuery({
queryKey: [GET_RECRUITS, season],
queryFn: season === ALL_RECRUITMENT ? getAllRecruits : () => getRecruitsBySeason({ season }),
});

return result.data as unknown as Response;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useDeleteRecruit.ts에 있는 함수랑 선언 방법을 통일하면 좋을 것 같아요

28 changes: 28 additions & 0 deletions src/app/(sidebar)/my-recruit/api/useGetCards.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';
import { TagType } from '@/types/info';

interface Props {
type: string;
}

interface Response {
data: Array<{
id: number;
title: string;
updatedDate: string;
tagList: Array<TagType>;
}>;
}

export const GET_CARDS = 'cards';

function getCards({ type }: Props) {
return http.get({ url: '/cards', params: { type } });
}

export function useGetCards({ type }: Props) {
const result = useSuspenseQuery({ queryKey: [GET_CARDS, type], queryFn: () => getCards({ type }) });

return result.data as unknown as Response;
}
20 changes: 20 additions & 0 deletions src/app/(sidebar)/my-recruit/api/useGetProgressingRecruits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { http } from '@/apis/http';
import { useSuspenseQuery } from '@tanstack/react-query';
import { RecruitCard } from '@/app/(sidebar)/my-recruit/type';

type Response = { data: RecruitCard[] };

export const GET_PROGRESSING_RECRUITS_KEY = 'recruits-progressing';

function getProgressingRecruits() {
return http.get({ url: '/recruits/progressing' });
}

export function useGetProgressingRecruits() {
const result = useSuspenseQuery({
queryKey: [GET_PROGRESSING_RECRUITS_KEY],
queryFn: getProgressingRecruits,
});

return result.data as unknown as Response;
}
22 changes: 22 additions & 0 deletions src/app/(sidebar)/my-recruit/api/useGetRecruitsBySeason.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';
import { RecruitCard } from '@/app/(sidebar)/my-recruit/type';

type Request = { season: string };

type Response = { data: RecruitCard[] };

export const GET_RECRUIT_BY_SEASON_KEY = 'recruits-by-season';

function getRecruitsBySeason({ season }: Request) {
return http.get({ url: '/recruits/bySeason', params: { season } });
}

export function useGetRecruitsBySeason({ season }: Request) {
const result = useSuspenseQuery({
queryKey: [GET_RECRUIT_BY_SEASON_KEY, season],
queryFn: () => getRecruitsBySeason({ season }),
});

return result.data as unknown as Response;
}
20 changes: 20 additions & 0 deletions src/app/(sidebar)/my-recruit/api/useGetSeasons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useSuspenseQuery } from '@tanstack/react-query';
import { http } from '@/apis/http';

type Response = {
data: Array<{
name: string;
}>;
};

export const GET_SEASONS_KEY = 'seasons';

function getSeasons() {
return http.get({ url: '/seasons' });
}

export function useGetSeasons() {
const result = useSuspenseQuery({ queryKey: [GET_SEASONS_KEY], queryFn: getSeasons });

return result.data as unknown as Response;
}
22 changes: 22 additions & 0 deletions src/app/(sidebar)/my-recruit/api/usePatchRecruitStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { http } from '@/apis/http';
import { useMutation } from '@tanstack/react-query';

interface Request {
id: number;
recruitStatus: string;
}

export const PATCH_RECRUIT_STATUS_KEY = 'put-recruit-status';

function patchRecruitStatus({ id, recruitStatus }: Request) {
return http.patch({ url: `/recruits/${id}/status`, data: { recruitStatus } });
}

export function usePatchRecruitStatus() {
const mutate = useMutation({
mutationKey: [PATCH_RECRUIT_STATUS_KEY],
mutationFn: (data: Request) => patchRecruitStatus(data),
});

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

interface Request {
recruitId: number;
cardId: number;
}

export const POST_CARD_TO_RECRUIT_KEY = 'post-card-to-recruit';

function postCardToRecruit({ recruitId, cardId }: Request) {
return http.post({ url: `/api/v1/recruits/${recruitId}/cards/${cardId}` });
}

export function usePostCardToRecruit() {
const mutate = useMutation({
mutationKey: [POST_CARD_TO_RECRUIT_KEY],
mutationFn: (data: Request) => postCardToRecruit(data),
});

return mutate;
}
27 changes: 27 additions & 0 deletions src/app/(sidebar)/my-recruit/api/usePostRecruit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { http } from '@/apis/http';
import { useMutation, useQueryClient } from '@tanstack/react-query';

export interface Request {
title: string;
season: string;
siteUrl: string;
recruitScheduleStage: string;
deadline: string | null;
}

export const POST_RECRUIT_KEY = 'post-recruit';

function postRecruit(data: Request) {
return http.post({ url: '/recruits', data });
}

export function usePostRecruit() {
const { invalidateQueries } = useQueryClient();

const mutate = useMutation({
mutationKey: [POST_RECRUIT_KEY],
mutationFn: (data: Request) => postRecruit(data),
});

return mutate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Props extends ComponentProps<'input'> {

export function InputField({ required = false, right, value, ...inputProps }: Props) {
return (
<div className="w-full flex justify-between items-center p-12 bg-neutral-1 border-neutral-20 rounded-[8px] border-[1px]">
<div className="w-full flex justify-between items-center px-16 py-12 bg-neutral-1 border-neutral-20 rounded-[8px] border-[1px]">
<If condition={required}>
<div className="text-mint-40 text-label1">*</div>
</If>
Expand Down
Loading
Loading