feat: statuses dnd editor for mobile
This commit is contained in:
@ -0,0 +1,86 @@
|
||||
"use client";
|
||||
|
||||
import React, { FC, ReactNode } from "react";
|
||||
import { IconChevronLeft, IconGripVertical } from "@tabler/icons-react";
|
||||
import { Box, Center, Divider, Drawer, Group, rem, Text } from "@mantine/core";
|
||||
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||
import { useStatusesContext } from "@/app/deals/contexts/StatusesContext";
|
||||
import CreateStatusButton from "@/app/deals/drawers/BoardStatusesEditorDrawer/components/CreateStatusButton";
|
||||
import StatusMobile from "@/app/deals/drawers/BoardStatusesEditorDrawer/components/StatusMobile";
|
||||
import SortableDnd from "@/components/dnd/SortableDnd";
|
||||
import { StatusSchema } from "@/lib/client";
|
||||
|
||||
const BoardStatusesEditorDrawer: FC = () => {
|
||||
const {
|
||||
statuses,
|
||||
onUpdateStatus,
|
||||
isEditorDrawerOpened,
|
||||
setIsEditorDrawerOpened,
|
||||
} = useStatusesContext();
|
||||
const { selectedBoard } = useBoardsContext();
|
||||
const onClose = () => setIsEditorDrawerOpened(false);
|
||||
|
||||
const renderDraggable = () => (
|
||||
<Box p={"xs"}>
|
||||
<IconGripVertical size={22} />
|
||||
</Box>
|
||||
);
|
||||
|
||||
const renderStatus = (
|
||||
status: StatusSchema,
|
||||
renderDraggable?: (item: StatusSchema) => ReactNode
|
||||
) => {
|
||||
return (
|
||||
<Group wrap={"nowrap"}>
|
||||
{renderDraggable && renderDraggable(status)}
|
||||
<StatusMobile status={status} />
|
||||
</Group>
|
||||
);
|
||||
};
|
||||
|
||||
const onDragEnd = (itemId: number, newLexorank: string) => {
|
||||
onUpdateStatus(itemId, { lexorank: newLexorank });
|
||||
};
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
size={"100%"}
|
||||
position={"right"}
|
||||
onClose={onClose}
|
||||
removeScrollProps={{ allowPinchZoom: true }}
|
||||
withCloseButton={false}
|
||||
opened={isEditorDrawerOpened}
|
||||
styles={{
|
||||
body: {
|
||||
height: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: rem(10),
|
||||
},
|
||||
}}>
|
||||
<Group justify={"space-between"}>
|
||||
<Box
|
||||
onClick={onClose}
|
||||
p={"xs"}>
|
||||
<IconChevronLeft />
|
||||
</Box>
|
||||
<Center>
|
||||
<Text>{selectedBoard?.name}</Text>
|
||||
</Center>
|
||||
<Box p={"lg"} />
|
||||
</Group>
|
||||
<Divider />
|
||||
<SortableDnd
|
||||
initialItems={statuses}
|
||||
onDragEnd={onDragEnd}
|
||||
renderItem={renderStatus}
|
||||
renderDraggable={renderDraggable}
|
||||
dragHandleStyle={{ width: "auto" }}
|
||||
vertical
|
||||
/>
|
||||
<CreateStatusButton />
|
||||
</Drawer>
|
||||
);
|
||||
};
|
||||
|
||||
export default BoardStatusesEditorDrawer;
|
||||
@ -0,0 +1,32 @@
|
||||
import { IconPlus } from "@tabler/icons-react";
|
||||
import { Box, Group, Text } from "@mantine/core";
|
||||
import { modals } from "@mantine/modals";
|
||||
import { useStatusesContext } from "@/app/deals/contexts/StatusesContext";
|
||||
|
||||
const CreateStatusButton = () => {
|
||||
const { onCreateStatus } = useStatusesContext();
|
||||
|
||||
const onStartCreating = () => {
|
||||
modals.openContextModal({
|
||||
modal: "enterNameModal",
|
||||
title: "Создание колонки",
|
||||
withCloseButton: true,
|
||||
innerProps: {
|
||||
onComplete: onCreateStatus,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Group
|
||||
ml={"xs"}
|
||||
onClick={onStartCreating}>
|
||||
<IconPlus />
|
||||
<Box mt={5}>
|
||||
<Text>Создать колонку</Text>
|
||||
</Box>
|
||||
</Group>
|
||||
);
|
||||
};
|
||||
|
||||
export default CreateStatusButton;
|
||||
@ -0,0 +1,46 @@
|
||||
import React, { FC } from "react";
|
||||
import { Box, Group, Text } from "@mantine/core";
|
||||
import { modals } from "@mantine/modals";
|
||||
import BoardMenu from "@/app/deals/components/Board/BoardMenu";
|
||||
import { useStatusesContext } from "@/app/deals/contexts/StatusesContext";
|
||||
import { StatusSchema } from "@/lib/client";
|
||||
|
||||
type Props = {
|
||||
status: StatusSchema;
|
||||
};
|
||||
|
||||
const StatusMobile: FC<Props> = ({ status }) => {
|
||||
const { onUpdateStatus } = useStatusesContext();
|
||||
|
||||
const startEditing = () => {
|
||||
modals.openContextModal({
|
||||
modal: "enterNameModal",
|
||||
title: "Редактирование статуса",
|
||||
withCloseButton: true,
|
||||
innerProps: {
|
||||
onComplete: name => onUpdateStatus(status.id, { name }),
|
||||
defaultValue: status.name,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Group
|
||||
w={"100%"}
|
||||
pr={"md"}
|
||||
py={"xs"}
|
||||
justify={"space-between"}
|
||||
wrap={"nowrap"}>
|
||||
<Box>
|
||||
<Text>{status.name}</Text>
|
||||
</Box>
|
||||
<BoardMenu
|
||||
board={status}
|
||||
startEditing={startEditing}
|
||||
menuIconSize={22}
|
||||
/>
|
||||
</Group>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatusMobile;
|
||||
3
src/app/deals/drawers/BoardStatusesEditorDrawer/index.ts
Normal file
3
src/app/deals/drawers/BoardStatusesEditorDrawer/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import BoardStatusesEditorDrawer from "@/app/deals/drawers/BoardStatusesEditorDrawer/BoardStatusesEditorDrawer";
|
||||
|
||||
export default BoardStatusesEditorDrawer;
|
||||
Reference in New Issue
Block a user