Skip to content

Commit

Permalink
Merge pull request #1316 from 42organization/Feat/party-room-admin-페이…
Browse files Browse the repository at this point in the history
…지-구현-#1247

[Hotfix] category, template api 리스트에 키값 추가
  • Loading branch information
izone00 authored Mar 21, 2024
2 parents 92fb416 + 1927742 commit f03273a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 6 additions & 2 deletions hooks/party/usePartyCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { PartyCategory } from 'types/partyTypes';
import { instance, instanceInPartyManage } from 'utils/axios';
import { toastState } from 'utils/recoil/toast';

type categoryResponse = {
categoryList: PartyCategory[];
};

export default function usePartyCategory() {
const queryClient = useQueryClient();
const setSnackBar = useSetRecoilState(toastState);
Expand All @@ -12,8 +16,8 @@ export default function usePartyCategory() {
queryKey: 'partyCategory',
queryFn: () =>
instance
.get('/party/categories')
.then(({ data }: { data: PartyCategory[] }) => data),
.get<categoryResponse>('/party/categories')
.then(({ data }) => data.categoryList),
onError: () => {
setSnackBar({
toastName: 'GET request',
Expand Down
19 changes: 11 additions & 8 deletions hooks/party/usePartyTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { PartyGameTemplate, PartyTemplateForm } from 'types/partyTypes';
import { instance, instanceInPartyManage } from 'utils/axios';
import { toastState } from 'utils/recoil/toast';

type templateResponse = {
templateList: PartyGameTemplate[];
};

export function usePartyTemplate(categoryId?: number) {
const queryClient = useQueryClient();
const setSnackBar = useSetRecoilState(toastState);
Expand All @@ -12,12 +16,8 @@ export function usePartyTemplate(categoryId?: number) {
queryKey: 'partyGameTemplate',
queryFn: () =>
instance
.get('/party/templates')
.then(({ data }: { data: PartyGameTemplate[] }) => {
return categoryId
? data.filter((d) => d.categoryId === categoryId)
: data;
}),
.get<templateResponse>('/party/templates')
.then(({ data }) => data.templateList),
onError: () => {
setSnackBar({
toastName: 'GET request',
Expand Down Expand Up @@ -58,9 +58,12 @@ export function usePartyTemplate(categoryId?: number) {
},
}
);

return {
templates: data ?? [], // undefind 대신 []을 이용해 에러 처리
templates: data
? categoryId
? data.filter((d) => d.categoryId === categoryId)
: data
: [], // undefind 대신 []을 이용해 에러 처리
createTemplate: (template: PartyTemplateForm) =>
createMutation.mutate(template),
updateTemplate: (template: PartyGameTemplate) =>
Expand Down

0 comments on commit f03273a

Please sign in to comment.