feat: project editor
This commit is contained in:
@ -1,36 +0,0 @@
|
|||||||
import { IconPlus } from "@tabler/icons-react";
|
|
||||||
import { ActionIcon, Box } from "@mantine/core";
|
|
||||||
import { modals } from "@mantine/modals";
|
|
||||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
|
||||||
import style from "./CreateProjectButton.module.css";
|
|
||||||
|
|
||||||
const CreateProjectButton = () => {
|
|
||||||
const { projectsCrud } = useProjectsContext();
|
|
||||||
|
|
||||||
const onCreateClick = () => {
|
|
||||||
modals.openContextModal({
|
|
||||||
modal: "enterNameModal",
|
|
||||||
title: "Создание проекта",
|
|
||||||
withCloseButton: true,
|
|
||||||
innerProps: {
|
|
||||||
onComplete: (name: string) => {
|
|
||||||
projectsCrud.onCreate(name);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<ActionIcon
|
|
||||||
variant={"default"}
|
|
||||||
onClick={onCreateClick}
|
|
||||||
radius="lg"
|
|
||||||
className={style.container}>
|
|
||||||
<IconPlus />
|
|
||||||
</ActionIcon>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CreateProjectButton;
|
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
import { FC, PropsWithChildren } from "react";
|
||||||
|
import { ActionIcon, Box } from "@mantine/core";
|
||||||
|
import style from "./ProjectAction.module.css";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClick: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ProjectAction: FC<PropsWithChildren<Props>> = ({
|
||||||
|
onClick,
|
||||||
|
children,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<ActionIcon
|
||||||
|
variant={"default"}
|
||||||
|
onClick={onClick}
|
||||||
|
radius="lg"
|
||||||
|
className={style.container}>
|
||||||
|
{children}
|
||||||
|
</ActionIcon>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProjectAction;
|
||||||
@ -1,19 +1,43 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { IconEdit, IconPlus } from "@tabler/icons-react";
|
||||||
import { Flex, Group } from "@mantine/core";
|
import { Flex, Group } from "@mantine/core";
|
||||||
import CreateProjectButton from "@/app/deals/components/desktop/CreateProjectButton/CreateProjectButton";
|
import { modals } from "@mantine/modals";
|
||||||
|
import ProjectAction from "@/app/deals/components/desktop/ProjectAction/ProjectAction";
|
||||||
import ViewSelector from "@/app/deals/components/desktop/ViewSelector/ViewSelector";
|
import ViewSelector from "@/app/deals/components/desktop/ViewSelector/ViewSelector";
|
||||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
||||||
import ProjectSelect from "@/components/selects/ProjectSelect/ProjectSelect";
|
import ProjectSelect from "@/components/selects/ProjectSelect/ProjectSelect";
|
||||||
|
import { useDrawersContext } from "@/drawers/DrawersContext";
|
||||||
import useIsMobile from "@/hooks/utils/useIsMobile";
|
import useIsMobile from "@/hooks/utils/useIsMobile";
|
||||||
|
|
||||||
const TopToolPanel = () => {
|
const TopToolPanel = () => {
|
||||||
const { projects, setSelectedProjectId, selectedProject } =
|
const { projects, setSelectedProjectId, selectedProject, projectsCrud } =
|
||||||
useProjectsContext();
|
useProjectsContext();
|
||||||
|
const { openDrawer } = useDrawersContext();
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
if (isMobile) return;
|
if (isMobile) return;
|
||||||
|
|
||||||
|
const onCreateClick = () => {
|
||||||
|
modals.openContextModal({
|
||||||
|
modal: "enterNameModal",
|
||||||
|
title: "Создание проекта",
|
||||||
|
withCloseButton: true,
|
||||||
|
innerProps: {
|
||||||
|
onComplete: projectsCrud.onCreate,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEditClick = () => {
|
||||||
|
if (!selectedProject) return;
|
||||||
|
|
||||||
|
openDrawer({
|
||||||
|
key: "selectedProjectEditorDrawer",
|
||||||
|
props: { project: selectedProject, projectsCrud },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group justify={"space-between"}>
|
<Group justify={"space-between"}>
|
||||||
<ViewSelector />
|
<ViewSelector />
|
||||||
@ -21,7 +45,12 @@ const TopToolPanel = () => {
|
|||||||
wrap={"nowrap"}
|
wrap={"nowrap"}
|
||||||
align={"center"}
|
align={"center"}
|
||||||
gap={"sm"}>
|
gap={"sm"}>
|
||||||
<CreateProjectButton />
|
<ProjectAction onClick={onEditClick}>
|
||||||
|
<IconEdit />
|
||||||
|
</ProjectAction>
|
||||||
|
<ProjectAction onClick={onCreateClick}>
|
||||||
|
<IconPlus />
|
||||||
|
</ProjectAction>
|
||||||
<ProjectSelect
|
<ProjectSelect
|
||||||
data={projects}
|
data={projects}
|
||||||
value={selectedProject}
|
value={selectedProject}
|
||||||
|
|||||||
@ -1,33 +1,33 @@
|
|||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
import { Button, Group, Stack, Text, TextInput } from "@mantine/core";
|
import { Button, Group, Stack, TextInput } from "@mantine/core";
|
||||||
import { useForm } from "@mantine/form";
|
import { useForm } from "@mantine/form";
|
||||||
import { DealsCrud } from "@/hooks/cruds/useDealsCrud";
|
import { ProjectsCrud } from "@/hooks/cruds/useProjectsCrud";
|
||||||
import { DealSchema } from "@/lib/client";
|
import { ProjectSchema } from "@/lib/client";
|
||||||
import { utcDateTimeToLocalString } from "@/utils/datetime";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
dealsCrud: DealsCrud;
|
projectsCrud: ProjectsCrud;
|
||||||
deal: DealSchema;
|
project: ProjectSchema;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const GeneralTab: FC<Props> = ({ deal, dealsCrud, onClose }) => {
|
const GeneralTab: FC<Props> = ({ project, projectsCrud, onClose }) => {
|
||||||
const [initialValues, setInitialValues] = useState(deal);
|
const [initialValues, setInitialValues] = useState(project);
|
||||||
const form = useForm<DealSchema>({
|
const form = useForm<ProjectSchema>({
|
||||||
initialValues,
|
initialValues,
|
||||||
validate: {
|
validate: {
|
||||||
name: value => !value && "Введите название",
|
name: value => !value && "Введите название",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = (values: DealSchema) => {
|
const onSubmit = (values: ProjectSchema) => {
|
||||||
dealsCrud.onUpdate(deal.id, values);
|
projectsCrud.onUpdate(project.id, values);
|
||||||
setInitialValues(values);
|
setInitialValues(values);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDelete = () => {
|
const onDelete = () => {
|
||||||
dealsCrud.onDelete(deal, onClose);
|
projectsCrud.onDelete(project, onClose);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -37,7 +37,6 @@ const GeneralTab: FC<Props> = ({ deal, dealsCrud, onClose }) => {
|
|||||||
label={"Название"}
|
label={"Название"}
|
||||||
{...form.getInputProps("name")}
|
{...form.getInputProps("name")}
|
||||||
/>
|
/>
|
||||||
<Text>Создано: {utcDateTimeToLocalString(deal.createdAt)}</Text>
|
|
||||||
<Group
|
<Group
|
||||||
justify={"space-between"}
|
justify={"space-between"}
|
||||||
wrap={"nowrap"}>
|
wrap={"nowrap"}>
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
.tab {
|
||||||
|
border-bottom-width: 3px;
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { FC } from "react";
|
||||||
|
import { Drawer } from "@mantine/core";
|
||||||
|
import ProjectEditorBody from "@/app/deals/drawers/SelectedProjectEditorDrawer/components/ProjectEditorBody";
|
||||||
|
import { DrawerProps } from "@/drawers/types";
|
||||||
|
import { ProjectsCrud } from "@/hooks/cruds/useProjectsCrud";
|
||||||
|
import useIsMobile from "@/hooks/utils/useIsMobile";
|
||||||
|
import { ProjectSchema } from "@/lib/client";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
project: ProjectSchema;
|
||||||
|
projectsCrud: ProjectsCrud;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SelectedProjectEditorDrawer: FC<DrawerProps<Props>> = ({
|
||||||
|
opened,
|
||||||
|
onClose,
|
||||||
|
props,
|
||||||
|
}) => {
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Drawer
|
||||||
|
size={isMobile ? "100%" : "40%"}
|
||||||
|
position={"right"}
|
||||||
|
onClose={onClose}
|
||||||
|
removeScrollProps={{ allowPinchZoom: true }}
|
||||||
|
withCloseButton={false}
|
||||||
|
opened={opened}
|
||||||
|
trapFocus={false}
|
||||||
|
styles={{
|
||||||
|
body: {
|
||||||
|
height: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
padding: 0,
|
||||||
|
},
|
||||||
|
}}>
|
||||||
|
<ProjectEditorBody
|
||||||
|
{...props}
|
||||||
|
onClose={onClose}
|
||||||
|
/>
|
||||||
|
</Drawer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SelectedProjectEditorDrawer;
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
import { FC, useState } from "react";
|
||||||
|
import { isEqual } from "lodash";
|
||||||
|
import { Button, Group, Stack, Text, TextInput } from "@mantine/core";
|
||||||
|
import { useForm } from "@mantine/form";
|
||||||
|
import { DealsCrud } from "@/hooks/cruds/useDealsCrud";
|
||||||
|
import { DealSchema } from "@/lib/client";
|
||||||
|
import { utcDateTimeToLocalString } from "@/utils/datetime";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
dealsCrud: DealsCrud;
|
||||||
|
deal: DealSchema;
|
||||||
|
onClose: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const GeneralTab: FC<Props> = ({ deal, dealsCrud, onClose }) => {
|
||||||
|
const [initialValues, setInitialValues] = useState(deal);
|
||||||
|
const form = useForm<DealSchema>({
|
||||||
|
initialValues,
|
||||||
|
validate: {
|
||||||
|
name: value => !value && "Введите название",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const onSubmit = (values: DealSchema) => {
|
||||||
|
dealsCrud.onUpdate(deal.id, values);
|
||||||
|
setInitialValues(values);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDelete = () => {
|
||||||
|
dealsCrud.onDelete(deal, onClose);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={form.onSubmit(onSubmit)}>
|
||||||
|
<Stack p={"md"}>
|
||||||
|
<TextInput
|
||||||
|
label={"Название"}
|
||||||
|
{...form.getInputProps("name")}
|
||||||
|
/>
|
||||||
|
<Text>Создано: {utcDateTimeToLocalString(deal.createdAt)}</Text>
|
||||||
|
<Group
|
||||||
|
justify={"space-between"}
|
||||||
|
wrap={"nowrap"}>
|
||||||
|
<Group wrap={"nowrap"}>
|
||||||
|
<Button
|
||||||
|
type={"submit"}
|
||||||
|
disabled={isEqual(form.values, initialValues)}
|
||||||
|
variant={"filled"}>
|
||||||
|
Сохранить
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type={"reset"}
|
||||||
|
onClick={() => form.reset()}
|
||||||
|
disabled={isEqual(form.values, initialValues)}
|
||||||
|
variant={"default"}>
|
||||||
|
Отменить
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
<Button
|
||||||
|
onClick={onDelete}
|
||||||
|
color={"red"}
|
||||||
|
variant={"outline"}>
|
||||||
|
Удалить
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GeneralTab;
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
import { FC } from "react";
|
||||||
|
import { IconEdit } from "@tabler/icons-react";
|
||||||
|
import { Tabs } from "@mantine/core";
|
||||||
|
import GeneralTab from "@/app/deals/drawers/DealEditorDrawer/components/GeneralTab";
|
||||||
|
import { ProjectsCrud } from "@/hooks/cruds/useProjectsCrud";
|
||||||
|
import { ProjectSchema } from "@/lib/client";
|
||||||
|
import styles from "../DealEditorDrawer.module.css";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
projectsCrud: ProjectsCrud;
|
||||||
|
project: ProjectSchema;
|
||||||
|
onClose: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ProjectEditorBody: FC<Props> = ({ projectsCrud, project, onClose }) => {
|
||||||
|
return (
|
||||||
|
<Tabs
|
||||||
|
defaultValue="general"
|
||||||
|
classNames={{ tab: styles.tab }}>
|
||||||
|
<Tabs.List>
|
||||||
|
<Tabs.Tab
|
||||||
|
value="general"
|
||||||
|
leftSection={<IconEdit />}>
|
||||||
|
Общая информация
|
||||||
|
</Tabs.Tab>
|
||||||
|
</Tabs.List>
|
||||||
|
<Tabs.Panel value="general">
|
||||||
|
<GeneralTab
|
||||||
|
projectsCrud={projectsCrud}
|
||||||
|
project={project}
|
||||||
|
onClose={onClose}
|
||||||
|
/>
|
||||||
|
</Tabs.Panel>
|
||||||
|
</Tabs>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProjectEditorBody;
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import SelectedProjectEditorDrawer from "@/app/deals/drawers/SelectedProjectEditorDrawer/SelectedProjectEditorDrawer";
|
||||||
|
|
||||||
|
export default SelectedProjectEditorDrawer;
|
||||||
@ -2,12 +2,14 @@ import BoardStatusesEditorDrawer from "@/app/deals/drawers/BoardStatusesEditorDr
|
|||||||
import DealEditorDrawer from "@/app/deals/drawers/DealEditorDrawer/DealEditorDrawer";
|
import DealEditorDrawer from "@/app/deals/drawers/DealEditorDrawer/DealEditorDrawer";
|
||||||
import ProjectBoardsEditorDrawer from "@/app/deals/drawers/ProjectBoardsEditorDrawer";
|
import ProjectBoardsEditorDrawer from "@/app/deals/drawers/ProjectBoardsEditorDrawer";
|
||||||
import ProjectsEditorDrawer from "@/app/deals/drawers/ProjectsEditorDrawer";
|
import ProjectsEditorDrawer from "@/app/deals/drawers/ProjectsEditorDrawer";
|
||||||
|
import SelectedProjectEditorDrawer from "@/app/deals/drawers/SelectedProjectEditorDrawer";
|
||||||
|
|
||||||
const drawerRegistry = {
|
const drawerRegistry = {
|
||||||
projectsEditorDrawer: ProjectsEditorDrawer,
|
projectsEditorDrawer: ProjectsEditorDrawer,
|
||||||
boardStatusesEditorDrawer: BoardStatusesEditorDrawer,
|
boardStatusesEditorDrawer: BoardStatusesEditorDrawer,
|
||||||
projectBoardsEditorDrawer: ProjectBoardsEditorDrawer,
|
projectBoardsEditorDrawer: ProjectBoardsEditorDrawer,
|
||||||
dealEditorDrawer: DealEditorDrawer,
|
dealEditorDrawer: DealEditorDrawer,
|
||||||
|
selectedProjectEditorDrawer: SelectedProjectEditorDrawer,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default drawerRegistry;
|
export default drawerRegistry;
|
||||||
|
|||||||
@ -17,7 +17,7 @@ type Props = {
|
|||||||
export type ProjectsCrud = {
|
export type ProjectsCrud = {
|
||||||
onCreate: (name: string) => void;
|
onCreate: (name: string) => void;
|
||||||
onUpdate: (projectId: number, project: UpdateProjectSchema) => void;
|
onUpdate: (projectId: number, project: UpdateProjectSchema) => void;
|
||||||
onDelete: (project: ProjectSchema) => void;
|
onDelete: (project: ProjectSchema, onSuccess?: () => void) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useProjectsCrud = ({ queryKey }: Props): ProjectsCrud => {
|
export const useProjectsCrud = ({ queryKey }: Props): ProjectsCrud => {
|
||||||
|
|||||||
Reference in New Issue
Block a user