feat: total price in product services table

This commit is contained in:
2025-09-16 19:27:00 +04:00
parent d927da46df
commit 681c2c3bc8

View File

@ -1,8 +1,8 @@
import { useMemo } from "react";
import { DataTableColumn } from "mantine-datatable";
import { ProductServiceSchema } from "@/lib/client";
import { ActionIcon, Flex, Tooltip } from "@mantine/core";
import { IconEdit, IconTrash } from "@tabler/icons-react";
import { DataTableColumn } from "mantine-datatable";
import { ActionIcon, Box, Flex, Text, Tooltip } from "@mantine/core";
import { ProductServiceSchema } from "@/lib/client";
type Props = {
data: ProductServiceSchema[];
@ -11,7 +11,12 @@ type Props = {
onDelete: (dealProductService: ProductServiceSchema) => void;
};
const useProductServicesTableColumns = ({ data, quantity, onChange, onDelete }: Props) => {
const useProductServicesTableColumns = ({
data,
quantity,
onChange,
onDelete,
}: Props) => {
const totalPrice = useMemo(
() => data.reduce((acc, row) => acc + row.price * quantity, 0),
[data, quantity]
@ -60,7 +65,13 @@ const useProductServicesTableColumns = ({ data, quantity, onChange, onDelete }:
{
accessor: "price",
title: "Цена",
Footer: () => <>Итог: {totalPrice.toLocaleString("ru")}</>,
footer: (
<Box h={"100%"}>
<Text fw={700}>
Итог: {totalPrice.toLocaleString("ru")}
</Text>
</Box>
),
},
] as DataTableColumn<ProductServiceSchema>[],
[totalPrice]