import {FC} from "react"; import styles from './ProductAndServiceTab.module.css'; import ProductView from "./components/ProductView/ProductView.tsx"; import {Button, Flex, ScrollArea, Title} from "@mantine/core"; import DealServicesTable from "./components/DealServicesTable/DealServicesTable.tsx"; import useDealProductAndServiceTabState from "./hooks/useProductAndServiceTabState.tsx"; import {modals} from "@mantine/modals"; const ProductAndServiceTab: FC = () => { const {dealState, dealServicesState, dealProductsState} = useDealProductAndServiceTabState(); const onCreateProductClick = () => { if (!dealProductsState.onCreate || !dealState.deal) return; const productIds = dealState.deal.products.map(product => product.product.id); modals.openContextModal({ modal: "addDealProduct", innerProps: { onCreate: dealProductsState.onCreate, clientId: dealState.deal.clientId, productIds: productIds }, withCloseButton: false }) } const getTotalPrice = () => { if (!dealState.deal) return 0 const productServicesPrice = dealState.deal.products.reduce((acc, row) => acc + row.services.reduce((acc2, row2) => acc2 + row2.price * row.quantity, 0), 0); const dealServicesPrice = dealState.deal.services.reduce((acc, row) => acc + row.price * row.quantity, 0); return dealServicesPrice + productServicesPrice; } return (