feat: navbar buttons depended on selected project
This commit is contained in:
39
src/components/layout/Navbar/hooks/useProjectActions.tsx
Normal file
39
src/components/layout/Navbar/hooks/useProjectActions.tsx
Normal file
@ -0,0 +1,39 @@
|
||||
import { modals } from "@mantine/modals";
|
||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
||||
import { useDrawersContext } from "@/drawers/DrawersContext";
|
||||
|
||||
const useProjectActions = () => {
|
||||
const { selectedProject, projectsCrud } = 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,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
onCreateClick,
|
||||
onChangeClick,
|
||||
};
|
||||
};
|
||||
|
||||
export default useProjectActions;
|
||||
Reference in New Issue
Block a user