feat: total price in product services table
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
import { useMemo } from "react";
|
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 { 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 = {
|
type Props = {
|
||||||
data: ProductServiceSchema[];
|
data: ProductServiceSchema[];
|
||||||
@ -11,7 +11,12 @@ type Props = {
|
|||||||
onDelete: (dealProductService: ProductServiceSchema) => void;
|
onDelete: (dealProductService: ProductServiceSchema) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useProductServicesTableColumns = ({ data, quantity, onChange, onDelete }: Props) => {
|
const useProductServicesTableColumns = ({
|
||||||
|
data,
|
||||||
|
quantity,
|
||||||
|
onChange,
|
||||||
|
onDelete,
|
||||||
|
}: Props) => {
|
||||||
const totalPrice = useMemo(
|
const totalPrice = useMemo(
|
||||||
() => data.reduce((acc, row) => acc + row.price * quantity, 0),
|
() => data.reduce((acc, row) => acc + row.price * quantity, 0),
|
||||||
[data, quantity]
|
[data, quantity]
|
||||||
@ -60,7 +65,13 @@ const useProductServicesTableColumns = ({ data, quantity, onChange, onDelete }:
|
|||||||
{
|
{
|
||||||
accessor: "price",
|
accessor: "price",
|
||||||
title: "Цена",
|
title: "Цена",
|
||||||
Footer: () => <>Итог: {totalPrice.toLocaleString("ru")}₽</>,
|
footer: (
|
||||||
|
<Box h={"100%"}>
|
||||||
|
<Text fw={700}>
|
||||||
|
Итог: {totalPrice.toLocaleString("ru")}₽
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
] as DataTableColumn<ProductServiceSchema>[],
|
] as DataTableColumn<ProductServiceSchema>[],
|
||||||
[totalPrice]
|
[totalPrice]
|
||||||
|
|||||||
Reference in New Issue
Block a user