feat: board and status selects in deal editor

This commit is contained in:
2025-09-02 14:41:28 +04:00
parent a6d8948e9d
commit 72ed69db24
13 changed files with 192 additions and 121 deletions

View File

@ -0,0 +1,71 @@
import { FC, useState } from "react";
import { Stack, Text, TextInput } from "@mantine/core";
import { useForm } from "@mantine/form";
import Footer from "@/app/deals/drawers/DealEditorDrawer/tabs/GeneralTab/Footer";
import BoardSelect from "@/components/selects/BoardSelect/BoardSelect";
import StatusSelect from "@/components/selects/StatusSelect/StatusSelect";
import { DealsCrud } from "@/hooks/cruds/useDealsCrud";
import { DealSchema, ProjectSchema } from "@/lib/client";
import { utcDateTimeToLocalString } from "@/utils/datetime";
type Props = {
project: ProjectSchema;
dealsCrud: DealsCrud;
deal: DealSchema;
onClose: () => void;
};
const GeneralTab: FC<Props> = ({ project, deal, dealsCrud, onClose }) => {
const [initialValues, setInitialValues] =
useState<Partial<DealSchema>>(deal);
const form = useForm<Partial<DealSchema>>({
initialValues,
validate: {
name: value => !value && "Введите название",
board: value => !value && "Выберите доску",
status: value => !value && "Выберите статус",
},
});
const onSubmit = (values: Partial<DealSchema>) => {
dealsCrud.onUpdate(deal.id, {
...values,
boardId: values.board?.id,
statusId: values.status?.id,
});
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>
<BoardSelect
label={"Доска"}
{...form.getInputProps("board")}
projectId={project?.id}
/>
<StatusSelect
label={"Статус"}
{...form.getInputProps("status")}
boardId={form.values.board?.id}
/>
<Footer
form={form}
initialValues={initialValues}
onDelete={onDelete}
/>
</Stack>
</form>
);
};
export default GeneralTab;