-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathAddFolder.tsx
45 lines (41 loc) · 1.39 KB
/
AddFolder.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { ModalInput } from "../ModalElements/ModalInput";
import Modal from "../Modal";
import { BaseModalProps } from "../ModalProp";
import { PrimaryButton } from "@styles/common/PrimaryButton";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useInputValue } from "@hooks/useInputValue";
import { MouseEvent } from "react";
import { postNewFolder } from "@data-access/postNewFolder";
export function AddFolder({ handleCloseModal }: BaseModalProps) {
const { insertValue, onChange } = useInputValue();
const queryClient = useQueryClient();
const createFolderMutation = useMutation({
mutationFn: (createFolderName: string) =>
postNewFolder({ folderName: createFolderName }),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ["folderList"],
});
},
});
const handleCreateNewFolder = async (
event: MouseEvent<HTMLButtonElement>
) => {
const createFolderName = insertValue;
createFolderMutation.mutate(createFolderName);
handleCloseModal(event);
};
return (
<Modal title={"폴더 추가"} handleCloseModal={handleCloseModal}>
<ModalInput
value={insertValue}
onChange={onChange}
placeholder="내용 입력"
type="text"
></ModalInput>
<PrimaryButton type="button" onClick={handleCreateNewFolder}>
추가하기
</PrimaryButton>
</Modal>
);
}