feat: deal product services
This commit is contained in:
		@@ -2,19 +2,24 @@ import {ContextModalProps} from "@mantine/modals";
 | 
			
		||||
import BaseFormModal, {CreateEditFormProps} from "../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
 | 
			
		||||
import {DealServiceSchema} from "../../../client";
 | 
			
		||||
import {useForm} from "@mantine/form";
 | 
			
		||||
import {NumberInput} from "@mantine/core";
 | 
			
		||||
import ServiceSelect from "../../../components/ServiceSelect/ServiceSelect.tsx";
 | 
			
		||||
import {ComboboxItem, ComboboxItemGroup, NumberInput, OptionsFilter} from "@mantine/core";
 | 
			
		||||
import ServiceWithPriceInput from "../../../components/ServiceWithPriceInput/ServiceWithPriceInput.tsx";
 | 
			
		||||
import {ServiceType} from "../../../shared/enums/ServiceType.ts";
 | 
			
		||||
 | 
			
		||||
type Props = CreateEditFormProps<Partial<DealServiceSchema>>;
 | 
			
		||||
type RestProps = {
 | 
			
		||||
    serviceIds?: number[];
 | 
			
		||||
}
 | 
			
		||||
type Props = CreateEditFormProps<Partial<DealServiceSchema>> & RestProps;
 | 
			
		||||
const AddDealServiceModal = ({
 | 
			
		||||
                                 context,
 | 
			
		||||
                                 id,
 | 
			
		||||
                                 innerProps
 | 
			
		||||
                             }: ContextModalProps<Props>) => {
 | 
			
		||||
    const isEditing = 'element' in innerProps;
 | 
			
		||||
    const form = useForm<Partial<DealServiceSchema>>({
 | 
			
		||||
        initialValues: {
 | 
			
		||||
        initialValues: isEditing ? innerProps.element : {
 | 
			
		||||
            service: undefined,
 | 
			
		||||
            quantity: 0,
 | 
			
		||||
            quantity: 1,
 | 
			
		||||
        },
 | 
			
		||||
        validate: {
 | 
			
		||||
            service: (service?: DealServiceSchema['service']) => service !== undefined ? null : "Необходимо выбрать услугу",
 | 
			
		||||
@@ -25,6 +30,16 @@ const AddDealServiceModal = ({
 | 
			
		||||
        context.closeContextModal(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const serviceOptionsFilter = ({options}: { options: ComboboxItemGroup[] }) => {
 | 
			
		||||
        if (!innerProps.serviceIds) return options;
 | 
			
		||||
        const productServiceIds = innerProps.serviceIds;
 | 
			
		||||
        return (options as ComboboxItemGroup[]).map(({items, group}) => {
 | 
			
		||||
            return {
 | 
			
		||||
                group,
 | 
			
		||||
                items: items.filter(item => !productServiceIds.includes(parseInt((item as ComboboxItem).value)))
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
        <BaseFormModal
 | 
			
		||||
@@ -34,10 +49,27 @@ const AddDealServiceModal = ({
 | 
			
		||||
            onClose={onClose}>
 | 
			
		||||
            <BaseFormModal.Body>
 | 
			
		||||
                <>
 | 
			
		||||
                    <ServiceSelect
 | 
			
		||||
                        placeholder={"Выберите услугу"}
 | 
			
		||||
                        label={"Услуга"}
 | 
			
		||||
                        {...form.getInputProps('service')}
 | 
			
		||||
                    <ServiceWithPriceInput
 | 
			
		||||
                        serviceProps={{
 | 
			
		||||
                            ...form.getInputProps('service'),
 | 
			
		||||
                            label: "Услуга",
 | 
			
		||||
                            placeholder: "Выберите услугу",
 | 
			
		||||
                            style: {width: '100%'},
 | 
			
		||||
                            disabled: isEditing,
 | 
			
		||||
                            filter: serviceOptionsFilter as OptionsFilter
 | 
			
		||||
                        }}
 | 
			
		||||
                        priceProps={{
 | 
			
		||||
                            ...form.getInputProps('price'),
 | 
			
		||||
                            label: "Цена",
 | 
			
		||||
                            placeholder: "Введите цену",
 | 
			
		||||
                            style: {width: '100%'}
 | 
			
		||||
                        }}
 | 
			
		||||
                        quantity={form.values.quantity || 1}
 | 
			
		||||
                        containerProps={{
 | 
			
		||||
                            direction: "column",
 | 
			
		||||
                            style: {width: "100%"}
 | 
			
		||||
                        }}
 | 
			
		||||
                        filterType={ServiceType.DEAL_SERVICE}
 | 
			
		||||
                    />
 | 
			
		||||
                    <NumberInput
 | 
			
		||||
                        placeholder={"Введите количество"}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user