generated from Team-INSERT/Repository-generator-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f1a9bd
commit 292e750
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import httpClient from "@/apis/httpClient"; | ||
import { ICalender } from "@/interfaces"; | ||
|
||
export const getCalenderList = async (month: number) => { | ||
const { data } = await httpClient.calender.get({ | ||
params: { | ||
year: new Date().getFullYear(), | ||
month, | ||
}, | ||
}); | ||
return data; | ||
}; | ||
|
||
export const createCalenderItem = async (calender: ICalender) => { | ||
const { data } = await httpClient.calender.post(calender); | ||
return data; | ||
}; | ||
|
||
export const deleteCalenderItem = async (id: number) => { | ||
const { data } = await httpClient.calender.deleteById({ params: { id } }); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { toast } from "react-toastify"; | ||
import useModal from "@/hooks/useModal"; | ||
import { KEY } from "@/constants"; | ||
import { ICalender } from "@/interfaces"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { createCalenderItem, deleteCalenderItem } from "./api.service"; | ||
|
||
export const useAddCalenderPlanMutation = () => { | ||
const { closeModal } = useModal(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation((calender: ICalender) => createCalenderItem(calender), { | ||
onSuccess: () => { | ||
toast.success("일정이 추가되었어요!"); | ||
queryClient.invalidateQueries([KEY.CALENDER]); | ||
closeModal(); | ||
}, | ||
}); | ||
}; | ||
|
||
export const useDeleteCalenderPlanMutation = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation((id: number) => deleteCalenderItem(id), { | ||
onSuccess: () => { | ||
toast.success("일정이 삭제되었어요!"); | ||
queryClient.invalidateQueries([KEY.CALENDER]); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { KEY } from "@/constants"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { getCalenderList } from "./api.service"; | ||
|
||
interface IUseCalenderListQueryProps { | ||
currentMonth: number; | ||
} | ||
|
||
export const useCalenderListQuery = ({ | ||
currentMonth, | ||
}: IUseCalenderListQueryProps) => { | ||
const { data, ...queryRest } = useQuery([KEY.CALENDER], async () => | ||
getCalenderList(currentMonth), | ||
); | ||
return { data, ...queryRest }; | ||
}; |