feat: crappy reordering

This commit is contained in:
2024-10-08 00:03:43 +03:00
parent 223ed0577a
commit dea1221016
6 changed files with 92 additions and 11 deletions

View File

@@ -150,6 +150,38 @@ const ServicesTable: FC<Props> = ({
);
},
},
"mrt-row-actions": {
AggregatedCell: ({ row }) => editMode && (
<Tooltip label={"Редактировать категорию"}>
<ActionIcon onClick={() => {
modals.openContextModal({
modal: "createServiceCategory",
title: "Создание категории",
withCloseButton: false,
innerProps: {
element: row.original.category,
onChange: newCategory => {
ServiceService.updateServiceCategory({ requestBody: { category: newCategory } }).then(({
ok,
message,
}) => {
notifications.guess(ok, { message });
if (!ok) return;
queryClient.invalidateQueries({
queryKey: ["getAllServices"],
}).then(() => {
});
},
);
},
},
});
}} variant={"default"}>
<IconEdit />
</ActionIcon>
</Tooltip>
),
},
},
enableRowActions: true,
renderRowActions: ({ row }) => (

View File

@@ -2,19 +2,18 @@ import { ServiceCategorySchema } from "../../../client";
import { Button, Flex, rem, TextInput } from "@mantine/core";
import { useForm } from "@mantine/form";
import { ContextModalProps } from "@mantine/modals";
import { CreateEditFormProps } from "../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
type Props = {
onCreate: (category: ServiceCategorySchema) => void;
};
type Props = CreateEditFormProps<ServiceCategorySchema>;
const CreateServiceCategoryModal = ({
context,
id,
innerProps,
}: ContextModalProps<Props>) => {
context,
id,
innerProps,
}: ContextModalProps<Props>) => {
const isEditing = "onChange" in innerProps;
const initialValues = isEditing ? innerProps.element : { name: "" };
const form = useForm({
initialValues: {
name: "",
},
initialValues,
validate: {
name: name =>
name.trim() !== ""
@@ -23,7 +22,15 @@ const CreateServiceCategoryModal = ({
},
});
const onSubmit = (values: { name: string }) => {
innerProps.onCreate({ name: values.name, id: -1 });
if (isEditing) {
innerProps.onChange({ ...innerProps.element, ...values });
} else {
innerProps.onCreate({
...values,
dealServiceRank: "",
productServiceRank: "", id: -1,
});
}
context.closeContextModal(id);
};
const onCancelClick = () => {