feat: deal product comments

This commit is contained in:
2024-11-07 21:39:02 +04:00
parent a4f4d467e9
commit 7f769f84fb
2 changed files with 28 additions and 12 deletions

View File

@@ -8,5 +8,6 @@ export type DealProductSchema = {
product: ProductSchema; product: ProductSchema;
services: Array<DealProductServiceSchema>; services: Array<DealProductServiceSchema>;
quantity: number; quantity: number;
comment?: string;
}; };

View File

@@ -1,4 +1,4 @@
import { FC } from "react"; import { FC, useEffect, useState } from "react";
import { import {
DealProductSchema, DealProductSchema,
DealProductServiceSchema, DealProductServiceSchema,
@@ -6,23 +6,14 @@ import {
ProductSchema, ProductSchema,
} from "../../../../../../client"; } from "../../../../../../client";
import styles from "./ProductView.module.css"; import styles from "./ProductView.module.css";
import { import { ActionIcon, Box, Flex, Image, NumberInput, rem, Text, Textarea, Title, Tooltip } from "@mantine/core";
ActionIcon,
Box,
Flex,
Image,
NumberInput,
rem,
Text,
Title,
Tooltip,
} from "@mantine/core";
import ProductServicesTable from "../ProductServicesTable/ProductServicesTable.tsx"; import ProductServicesTable from "../ProductServicesTable/ProductServicesTable.tsx";
import { isNil, isNumber } from "lodash"; import { isNil, isNumber } from "lodash";
import { IconBarcode, IconEdit, IconTrash } from "@tabler/icons-react"; import { IconBarcode, IconEdit, IconTrash } from "@tabler/icons-react";
import { modals } from "@mantine/modals"; import { modals } from "@mantine/modals";
import { ServiceType } from "../../../../../../shared/enums/ServiceType.ts"; import { ServiceType } from "../../../../../../shared/enums/ServiceType.ts";
import useDealProductAndServiceTabState from "../../hooks/useProductAndServiceTabState.tsx"; import useDealProductAndServiceTabState from "../../hooks/useProductAndServiceTabState.tsx";
import { useDebouncedValue } from "@mantine/hooks";
type Props = { type Props = {
product: DealProductSchema; product: DealProductSchema;
@@ -53,11 +44,23 @@ const ProductView: FC<Props> = ({
}) => { }) => {
const { dealState } = useDealProductAndServiceTabState(); const { dealState } = useDealProductAndServiceTabState();
const isLocked = Boolean(dealState.deal?.billRequest); const isLocked = Boolean(dealState.deal?.billRequest);
const [productComment, setProductComment] = useState(product.comment);
const [debouncedProductComment] = useDebouncedValue(productComment, 600);
const onDeleteClick = () => { const onDeleteClick = () => {
if (!onDelete) return; if (!onDelete) return;
onDelete(product); onDelete(product);
}; };
useEffect(() => {
if (!onChange || debouncedProductComment === product.comment) return;
onChange({
...product,
comment: debouncedProductComment,
})
}, [debouncedProductComment]);
const onServiceDelete = (item: DealProductServiceSchema) => { const onServiceDelete = (item: DealProductServiceSchema) => {
if (!onChange) return; if (!onChange) return;
onChange({ onChange({
@@ -167,6 +170,18 @@ const ProductView: FC<Props> = ({
} }
placeholder={"Введите количество товара"} placeholder={"Введите количество товара"}
/> />
<Textarea
mih={rem(140)}
styles={{
wrapper: {height:'90%'},
input: {height:'90%'}
}}
my={rem(10)}
disabled={isLocked}
value={productComment}
onChange={event => setProductComment(event.target.value)}
placeholder={"Введите комментарий для товара"}
/>
</div> </div>
<div className={styles["services-container"]}> <div className={styles["services-container"]}>