refactor: using isDirty in forms

This commit is contained in:
2025-09-13 09:02:07 +04:00
parent c76304b7bc
commit f2746b8b65
4 changed files with 8 additions and 15 deletions

View File

@ -1,17 +1,14 @@
import { FC } from "react";
import { isEqual } from "lodash";
import { Button, Group } from "@mantine/core";
import { UseFormReturnType } from "@mantine/form";
import { DealForm } from "@/app/deals/drawers/DealEditorDrawer/tabs/GeneralTab/GeneralTab";
import { DealSchema } from "@/lib/client";
type Props = {
form: UseFormReturnType<DealForm>;
initialValues: Partial<DealSchema>;
onDelete: () => void;
};
const Footer: FC<Props> = ({ form, initialValues, onDelete }) => {
const Footer: FC<Props> = ({ form, onDelete }) => {
return (
<Group
justify={"space-between"}
@ -19,14 +16,14 @@ const Footer: FC<Props> = ({ form, initialValues, onDelete }) => {
<Group wrap={"nowrap"}>
<Button
type={"submit"}
disabled={isEqual(form.values, initialValues)}
disabled={!form.isDirty()}
variant={"filled"}>
Сохранить
</Button>
<Button
type={"reset"}
onClick={() => form.reset()}
disabled={isEqual(form.values, initialValues)}
disabled={!form.isDirty()}
variant={"default"}>
Отменить
</Button>

View File

@ -29,7 +29,7 @@ const GeneralTab: FC<Props> = ({ value, onDelete, onChange }) => {
});
const onSubmit = (values: DealForm) => {
form.setInitialValues(values);
form.resetDirty();
onChange({
...values,
board: values.board!,
@ -63,7 +63,6 @@ const GeneralTab: FC<Props> = ({ value, onDelete, onChange }) => {
/>
<Footer
form={form}
initialValues={value}
onDelete={() => onDelete(value)}
/>
</Stack>