42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { modals } from "@mantine/modals";
|
|
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
|
import { useDrawersContext } from "@/drawers/DrawersContext";
|
|
|
|
const useProjectActions = () => {
|
|
const { selectedProject, projectsCrud, refetchProjects } =
|
|
useProjectsContext();
|
|
const { openDrawer } = useDrawersContext();
|
|
|
|
const onCreateClick = () => {
|
|
modals.openContextModal({
|
|
modal: "enterNameModal",
|
|
title: "Создание проекта",
|
|
withCloseButton: true,
|
|
innerProps: {
|
|
onChange: projectsCrud.onCreate,
|
|
},
|
|
});
|
|
};
|
|
|
|
const onChangeClick = () => {
|
|
if (!selectedProject) return;
|
|
|
|
openDrawer({
|
|
key: "projectEditorDrawer",
|
|
props: {
|
|
value: selectedProject,
|
|
onChange: value => projectsCrud.onUpdate(value.id, value),
|
|
onDelete: projectsCrud.onDelete,
|
|
},
|
|
onClose: refetchProjects,
|
|
});
|
|
};
|
|
|
|
return {
|
|
onCreateClick,
|
|
onChangeClick,
|
|
};
|
|
};
|
|
|
|
export default useProjectActions;
|