feat: prettier
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
import {ContextModalProps} from "@mantine/modals";
|
||||
import {Button, Flex, rem, TextInput} from "@mantine/core";
|
||||
import {useEffect, useState} from "react";
|
||||
import {ProductService} from "../../client";
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
import { Button, Flex, rem, TextInput } from "@mantine/core";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ProductService } from "../../client";
|
||||
|
||||
type Props = {
|
||||
productId: number;
|
||||
onSubmit: (barcode: string) => void;
|
||||
}
|
||||
};
|
||||
const PrintBarcodeModal = ({
|
||||
id,
|
||||
context,
|
||||
innerProps
|
||||
}: ContextModalProps<Props>) => {
|
||||
const {productId, onSubmit} = innerProps;
|
||||
id,
|
||||
context,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
const { productId, onSubmit } = innerProps;
|
||||
const [barcode, setBarcode] = useState<string | undefined>();
|
||||
const [isBarcodeExist, setIsBarcodeExist] = useState<boolean>(true);
|
||||
|
||||
@@ -20,44 +20,41 @@ const PrintBarcodeModal = ({
|
||||
if (!barcode) return "Штрихкод не может быть пустым";
|
||||
if (isBarcodeExist) return "Штрихкод уже существует";
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!barcode) return;
|
||||
ProductService.existsProductBarcode({
|
||||
productId: innerProps.productId,
|
||||
barcode: barcode.trim()
|
||||
}).then((response) => {
|
||||
barcode: barcode.trim(),
|
||||
}).then(response => {
|
||||
setIsBarcodeExist(response.exists);
|
||||
})
|
||||
});
|
||||
}, [productId, barcode]);
|
||||
|
||||
const onSubmitClick = () => {
|
||||
if (!barcode || isBarcodeExist) return;
|
||||
onSubmit(barcode.trim());
|
||||
context.closeModal(id);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Flex
|
||||
gap={rem(10)}
|
||||
direction={"column"}
|
||||
>
|
||||
direction={"column"}>
|
||||
<TextInput
|
||||
required
|
||||
error={getErrorMessage()}
|
||||
label={"Штрихкод"}
|
||||
placeholder={"Введите или отсканируйте штрихкод"}
|
||||
value={barcode}
|
||||
onChange={(event) => setBarcode(event.currentTarget.value)}
|
||||
|
||||
onChange={event => setBarcode(event.currentTarget.value)}
|
||||
/>
|
||||
<Button
|
||||
onClick={onSubmitClick}
|
||||
disabled={!barcode || isBarcodeExist}
|
||||
>
|
||||
disabled={!barcode || isBarcodeExist}>
|
||||
Добавить
|
||||
</Button>
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default PrintBarcodeModal;
|
||||
export default PrintBarcodeModal;
|
||||
|
||||
@@ -1,67 +1,68 @@
|
||||
import {UserSchema} from "../../client";
|
||||
import {ObjectSelectProps} from "../../components/ObjectSelect/ObjectSelect.tsx";
|
||||
import {ContextModalProps} from "@mantine/modals";
|
||||
import {Button, Flex, rem} from "@mantine/core";
|
||||
import {useState} from "react";
|
||||
import { UserSchema } from "../../client";
|
||||
import { ObjectSelectProps } from "../../components/ObjectSelect/ObjectSelect.tsx";
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
import { Button, Flex, rem } from "@mantine/core";
|
||||
import { useState } from "react";
|
||||
import UserSelect from "../../components/Selects/UserSelect/UserSelect.tsx";
|
||||
import {notifications} from "../../shared/lib/notifications.ts";
|
||||
import { notifications } from "../../shared/lib/notifications.ts";
|
||||
|
||||
type SelectProps = Omit<ObjectSelectProps<UserSchema>, 'data' | 'getValueFn' | 'getLabelFn' | 'onChange'>;
|
||||
type SelectProps = Omit<
|
||||
ObjectSelectProps<UserSchema>,
|
||||
"data" | "getValueFn" | "getLabelFn" | "onChange"
|
||||
>;
|
||||
type Props = {
|
||||
onSelect: (user: UserSchema) => void
|
||||
onSelect: (user: UserSchema) => void;
|
||||
selectProps?: SelectProps;
|
||||
}
|
||||
};
|
||||
|
||||
const EmployeeSelectModal = ({
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
const [innerValue, setInnerValue] = useState<UserSchema | undefined>();
|
||||
|
||||
const closeSelf = () => {
|
||||
context.closeContextModal(id);
|
||||
}
|
||||
};
|
||||
|
||||
const onSelectClick = () => {
|
||||
if (!innerValue) {
|
||||
notifications.error({message: "Необходимо выбрать сотрудника"})
|
||||
notifications.error({ message: "Необходимо выбрать сотрудника" });
|
||||
return;
|
||||
}
|
||||
innerProps.onSelect(innerValue);
|
||||
closeSelf();
|
||||
}
|
||||
};
|
||||
const onCloseClick = () => {
|
||||
closeSelf();
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Flex direction={"column"}
|
||||
gap={rem(10)}
|
||||
>
|
||||
<Flex
|
||||
direction={"column"}
|
||||
gap={rem(10)}>
|
||||
<Flex w={"100%"}>
|
||||
<UserSelect
|
||||
onChange={setInnerValue}
|
||||
w={"100%"}
|
||||
placeholder={"Выберите сотрудника"}
|
||||
{...innerProps.selectProps}
|
||||
|
||||
/>
|
||||
</Flex>
|
||||
<Flex justify={"flex-end"} gap={rem(10)}>
|
||||
<Flex
|
||||
justify={"flex-end"}
|
||||
gap={rem(10)}>
|
||||
<Button
|
||||
variant={"default"}
|
||||
onClick={() => onCloseClick()}
|
||||
>
|
||||
onClick={() => onCloseClick()}>
|
||||
Отменить
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => onSelectClick()}
|
||||
>
|
||||
<Button onClick={() => onSelectClick()}>
|
||||
Выбрать сотрудника
|
||||
</Button>
|
||||
</Flex>
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default EmployeeSelectModal
|
||||
export default EmployeeSelectModal;
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
import SimpleUsersTable from "../../pages/LeadsPage/components/SimpleUsersTable/SimpleUsersTable.tsx";
|
||||
import {ContextModalProps} from "@mantine/modals";
|
||||
import {Flex, rem} from "@mantine/core";
|
||||
import {UserSchema} from "../../client";
|
||||
import {MutableRefObject, useEffect} from "react";
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
import { Flex, rem } from "@mantine/core";
|
||||
import { UserSchema } from "../../client";
|
||||
import { MutableRefObject, useEffect } from "react";
|
||||
|
||||
type Props = {
|
||||
items: MutableRefObject<UserSchema[]>
|
||||
items: MutableRefObject<UserSchema[]>;
|
||||
onChange: (items: UserSchema[]) => void;
|
||||
};
|
||||
|
||||
const EmployeeTableModal = ({
|
||||
innerProps
|
||||
}: ContextModalProps<Props>) => {
|
||||
useEffect(() => {
|
||||
}, [innerProps.items.current])
|
||||
const EmployeeTableModal = ({ innerProps }: ContextModalProps<Props>) => {
|
||||
useEffect(() => {}, [innerProps.items.current]);
|
||||
return (
|
||||
<Flex direction={"column"} gap={rem(10)}>
|
||||
<Flex
|
||||
direction={"column"}
|
||||
gap={rem(10)}>
|
||||
<SimpleUsersTable
|
||||
items={innerProps.items.current}
|
||||
onChange={(event) => {
|
||||
onChange={event => {
|
||||
innerProps.onChange(event);
|
||||
}}
|
||||
/>
|
||||
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
export default EmployeeTableModal;
|
||||
);
|
||||
};
|
||||
export default EmployeeTableModal;
|
||||
|
||||
@@ -1,81 +1,83 @@
|
||||
import {ContextModalProps} from "@mantine/modals";
|
||||
import {Button, Flex, rem, Textarea} from "@mantine/core";
|
||||
import {DateTimePicker, DateValue} from "@mantine/dates";
|
||||
import {useForm} from "@mantine/form";
|
||||
import {DealSummaryReorderRequest} from "../../client";
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
import { Button, Flex, rem, Textarea } from "@mantine/core";
|
||||
import { DateTimePicker, DateValue } from "@mantine/dates";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { DealSummaryReorderRequest } from "../../client";
|
||||
|
||||
import {dateWithoutTimezone} from "../../shared/lib/date.ts";
|
||||
import { dateWithoutTimezone } from "../../shared/lib/date.ts";
|
||||
|
||||
type Deadline = {
|
||||
deadline: DateValue,
|
||||
comment: string
|
||||
}
|
||||
deadline: DateValue;
|
||||
comment: string;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
request: Partial<DealSummaryReorderRequest>,
|
||||
onSubmit: (
|
||||
request: DealSummaryReorderRequest,
|
||||
) => void;
|
||||
}
|
||||
request: Partial<DealSummaryReorderRequest>;
|
||||
onSubmit: (request: DealSummaryReorderRequest) => void;
|
||||
};
|
||||
|
||||
const EnterDeadlineModal = ({
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
const form = useForm<Deadline>({
|
||||
initialValues: {
|
||||
deadline: null,
|
||||
comment: '',
|
||||
comment: "",
|
||||
},
|
||||
validate: {
|
||||
deadline: (datetime) => datetime !== null ? null : 'Необходимо ввести дедлайн',
|
||||
}
|
||||
})
|
||||
deadline: datetime =>
|
||||
datetime !== null ? null : "Необходимо ввести дедлайн",
|
||||
},
|
||||
});
|
||||
const onCancelClick = () => {
|
||||
context.closeModal(id);
|
||||
}
|
||||
};
|
||||
const onSubmit = (values: Deadline) => {
|
||||
const {deadline, comment} = values;
|
||||
const { deadline, comment } = values;
|
||||
if (!deadline) return;
|
||||
innerProps.onSubmit({
|
||||
...innerProps.request,
|
||||
deadline: dateWithoutTimezone(deadline),
|
||||
comment
|
||||
comment,
|
||||
} as unknown as DealSummaryReorderRequest);
|
||||
context.closeModal(id);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<form onSubmit={form.onSubmit((values) => onSubmit(values))}>
|
||||
|
||||
<Flex direction={'column'} gap={10}>
|
||||
<Flex direction={'column'} gap={rem(10)}>
|
||||
<form onSubmit={form.onSubmit(values => onSubmit(values))}>
|
||||
<Flex
|
||||
direction={"column"}
|
||||
gap={10}>
|
||||
<Flex
|
||||
direction={"column"}
|
||||
gap={rem(10)}>
|
||||
<DateTimePicker
|
||||
required
|
||||
label={'Дата и время'}
|
||||
placeholder={'Введите дату и время'}
|
||||
label={"Дата и время"}
|
||||
placeholder={"Введите дату и время"}
|
||||
minDate={new Date()}
|
||||
{...form.getInputProps('deadline')}
|
||||
{...form.getInputProps("deadline")}
|
||||
/>
|
||||
<Textarea
|
||||
label={'Коментарий'}
|
||||
placeholder={'Введите коментарий'}
|
||||
{...form.getInputProps('comment')}
|
||||
label={"Коментарий"}
|
||||
placeholder={"Введите коментарий"}
|
||||
{...form.getInputProps("comment")}
|
||||
/>
|
||||
</Flex>
|
||||
|
||||
<Flex justify={'flex-end'} gap={rem(10)}>
|
||||
<Flex
|
||||
justify={"flex-end"}
|
||||
gap={rem(10)}>
|
||||
<Button
|
||||
variant={'default'}
|
||||
onClick={onCancelClick}
|
||||
>Отменить</Button>
|
||||
<Button
|
||||
type={'submit'}
|
||||
>Сохранить</Button>
|
||||
variant={"default"}
|
||||
onClick={onCancelClick}>
|
||||
Отменить
|
||||
</Button>
|
||||
<Button type={"submit"}>Сохранить</Button>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</form>
|
||||
|
||||
)
|
||||
);
|
||||
};
|
||||
export default EnterDeadlineModal;
|
||||
export default EnterDeadlineModal;
|
||||
|
||||
@@ -1,31 +1,38 @@
|
||||
import BaseFormModal, {CreateEditFormProps} from "../../pages/ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
|
||||
import {PositionSchema} from "../../client";
|
||||
import {ContextModalProps} from "@mantine/modals";
|
||||
import {useForm} from "@mantine/form";
|
||||
import {Flex, rem, TextInput} from "@mantine/core";
|
||||
import {useEffect} from "react";
|
||||
import CyrillicToTranslit from 'cyrillic-to-translit-js';
|
||||
import BaseFormModal, {
|
||||
CreateEditFormProps,
|
||||
} from "../../pages/ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
|
||||
import { PositionSchema } from "../../client";
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { Flex, rem, TextInput } from "@mantine/core";
|
||||
import { useEffect } from "react";
|
||||
import CyrillicToTranslit from "cyrillic-to-translit-js";
|
||||
|
||||
type Props = CreateEditFormProps<PositionSchema>;
|
||||
|
||||
const PositionFormModal = ({
|
||||
id,
|
||||
context,
|
||||
innerProps
|
||||
}: ContextModalProps<Props>) => {
|
||||
const translit = CyrillicToTranslit({preset: "ru"})
|
||||
const isEditing = 'element' in innerProps;
|
||||
const initialValues: PositionSchema = isEditing ? innerProps.element : {
|
||||
key: "",
|
||||
name: ""
|
||||
}
|
||||
id,
|
||||
context,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
const translit = CyrillicToTranslit({ preset: "ru" });
|
||||
const isEditing = "element" in innerProps;
|
||||
const initialValues: PositionSchema = isEditing
|
||||
? innerProps.element
|
||||
: {
|
||||
key: "",
|
||||
name: "",
|
||||
};
|
||||
const form = useForm<PositionSchema>({
|
||||
initialValues: initialValues
|
||||
})
|
||||
initialValues: initialValues,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (isEditing) return;
|
||||
form.setFieldValue("key", translit.transform(form.values.name).toLowerCase());
|
||||
form.setFieldValue(
|
||||
"key",
|
||||
translit.transform(form.values.name).toLowerCase()
|
||||
);
|
||||
}, [form.values.name]);
|
||||
|
||||
return (
|
||||
@@ -33,13 +40,11 @@ const PositionFormModal = ({
|
||||
closeOnSubmit
|
||||
form={form}
|
||||
onClose={() => context.closeContextModal(id)}
|
||||
{...innerProps}
|
||||
>
|
||||
{...innerProps}>
|
||||
<BaseFormModal.Body>
|
||||
<Flex
|
||||
direction={"column"}
|
||||
gap={rem(10)}
|
||||
>
|
||||
gap={rem(10)}>
|
||||
<TextInput
|
||||
label={"Название"}
|
||||
placeholder={"Введите название должности"}
|
||||
@@ -53,7 +58,7 @@ const PositionFormModal = ({
|
||||
</Flex>
|
||||
</BaseFormModal.Body>
|
||||
</BaseFormModal>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default PositionFormModal;
|
||||
export default PositionFormModal;
|
||||
|
||||
@@ -1,72 +1,88 @@
|
||||
import {BarcodeAttributeSchema} from "../../client";
|
||||
import {forwardRef} from "react";
|
||||
import { BarcodeAttributeSchema } from "../../client";
|
||||
import { forwardRef } from "react";
|
||||
import styles from "./PrintBarcodeModal.module.css";
|
||||
import {Flex, Text} from "@mantine/core";
|
||||
import { Flex, Text } from "@mantine/core";
|
||||
import Barcode from "react-barcode";
|
||||
|
||||
type Props = {
|
||||
attributes: BarcodeAttributeSchema[]
|
||||
attributes: BarcodeAttributeSchema[];
|
||||
barcode?: string;
|
||||
quantity: number;
|
||||
additionalField?: string | null;
|
||||
}
|
||||
};
|
||||
type Ref = HTMLDivElement;
|
||||
const PrintBarcodeContainer = forwardRef<Ref, Props>(function PrintBarcodeContainer(props: Props, ref) {
|
||||
const {attributes, barcode, quantity, additionalField} = props;
|
||||
const PrintBarcodeContainer = forwardRef<Ref, Props>(
|
||||
function PrintBarcodeContainer(props: Props, ref) {
|
||||
const { attributes, barcode, quantity, additionalField } = props;
|
||||
|
||||
const MAX_ATTRIBUTES = additionalField && additionalField.length > 0 ? 5 : 6;
|
||||
const MIN_BARCODE_SIZE = 30;
|
||||
const MAX_BARCODE_SIZE = 100;
|
||||
const STEP = (MAX_BARCODE_SIZE - MIN_BARCODE_SIZE) / MAX_ATTRIBUTES;
|
||||
const MAX_ATTRIBUTE_LENGTH = 35;
|
||||
const MAX_ATTRIBUTES =
|
||||
additionalField && additionalField.length > 0 ? 5 : 6;
|
||||
const MIN_BARCODE_SIZE = 30;
|
||||
const MAX_BARCODE_SIZE = 100;
|
||||
const STEP = (MAX_BARCODE_SIZE - MIN_BARCODE_SIZE) / MAX_ATTRIBUTES;
|
||||
const MAX_ATTRIBUTE_LENGTH = 35;
|
||||
|
||||
const getBarcodeHeight = () => {
|
||||
return MIN_BARCODE_SIZE + (MAX_ATTRIBUTES - attributes.length) * STEP;
|
||||
}
|
||||
const getAttributeText = (attribute: BarcodeAttributeSchema) => {
|
||||
let result = `${attribute.name}: ${attribute.value}`;
|
||||
if (result.length > MAX_ATTRIBUTE_LENGTH) {
|
||||
result = result.slice(0, MAX_ATTRIBUTE_LENGTH - 1) + ".";
|
||||
}
|
||||
return result;
|
||||
const getBarcodeHeight = () => {
|
||||
return (
|
||||
MIN_BARCODE_SIZE + (MAX_ATTRIBUTES - attributes.length) * STEP
|
||||
);
|
||||
};
|
||||
const getAttributeText = (attribute: BarcodeAttributeSchema) => {
|
||||
let result = `${attribute.name}: ${attribute.value}`;
|
||||
if (result.length > MAX_ATTRIBUTE_LENGTH) {
|
||||
result = result.slice(0, MAX_ATTRIBUTE_LENGTH - 1) + ".";
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={styles["print-only"]}
|
||||
ref={ref}>
|
||||
{barcode &&
|
||||
Array.from({ length: quantity }).map((_, index) => (
|
||||
<>
|
||||
<Flex
|
||||
className={styles["barcode-container"]}
|
||||
key={index}
|
||||
justify={"center"}
|
||||
direction={"column"}>
|
||||
<Flex
|
||||
align={"center"}
|
||||
justify={"center"}>
|
||||
<Barcode
|
||||
margin={0}
|
||||
height={getBarcodeHeight()}
|
||||
value={barcode}
|
||||
/>
|
||||
</Flex>
|
||||
{attributes
|
||||
.slice(0, MAX_ATTRIBUTES)
|
||||
.map(attr => (
|
||||
<Text
|
||||
key={attr.name}
|
||||
className={
|
||||
styles["barcode-attribute-text"]
|
||||
}
|
||||
size={"xs"}>
|
||||
{getAttributeText(attr)}
|
||||
</Text>
|
||||
))}
|
||||
{props.additionalField && (
|
||||
<Text
|
||||
className={
|
||||
styles["barcode-attribute-text"]
|
||||
}
|
||||
size={"xs"}>
|
||||
{props.additionalField}
|
||||
</Text>
|
||||
)}
|
||||
</Flex>
|
||||
</>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={styles['print-only']} ref={ref}>
|
||||
{barcode && Array.from({length: quantity}).map((_, index) => (
|
||||
<>
|
||||
<Flex
|
||||
className={styles['barcode-container']}
|
||||
key={index}
|
||||
justify={"center"}
|
||||
direction={"column"}
|
||||
>
|
||||
<Flex align={"center"} justify={"center"}>
|
||||
<Barcode margin={0} height={getBarcodeHeight()} value={barcode}/>
|
||||
</Flex>
|
||||
{attributes.slice(0, MAX_ATTRIBUTES).map((attr) => (
|
||||
<Text
|
||||
key={attr.name}
|
||||
className={styles['barcode-attribute-text']}
|
||||
size={"xs"}
|
||||
>
|
||||
{getAttributeText(attr)}
|
||||
</Text>
|
||||
))}
|
||||
{props.additionalField && (
|
||||
<Text
|
||||
className={styles['barcode-attribute-text']}
|
||||
size={"xs"}
|
||||
>
|
||||
{props.additionalField}
|
||||
</Text>
|
||||
)}
|
||||
</Flex>
|
||||
</>
|
||||
))}
|
||||
</div>
|
||||
|
||||
)
|
||||
});
|
||||
|
||||
export default PrintBarcodeContainer;
|
||||
export default PrintBarcodeContainer;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
.barcode-container {
|
||||
max-height: 1.45in;
|
||||
text-align: left;
|
||||
@@ -19,4 +18,4 @@
|
||||
.barcode-attribute-text {
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
import {ContextModalProps, modals} from "@mantine/modals";
|
||||
import {Button, Divider, Flex, NumberInput, rem, Select} from "@mantine/core";
|
||||
import {useEffect, useRef, useState} from "react";
|
||||
import {BarcodeSchema, ProductService} from "../../client";
|
||||
import {useGetProductById} from "../../api/product/useGetProductById.tsx";
|
||||
import {notifications} from "../../shared/lib/notifications.ts";
|
||||
import { ContextModalProps, modals } from "@mantine/modals";
|
||||
import { Button, Divider, Flex, NumberInput, rem, Select } from "@mantine/core";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { BarcodeSchema, ProductService } from "../../client";
|
||||
import { useGetProductById } from "../../api/product/useGetProductById.tsx";
|
||||
import { notifications } from "../../shared/lib/notifications.ts";
|
||||
import PrintBarcodeContainer from "./PrintBarcodeContainer.tsx";
|
||||
import {base64ToBlob} from "../../shared/lib/utils.ts";
|
||||
import { base64ToBlob } from "../../shared/lib/utils.ts";
|
||||
|
||||
type Props = {
|
||||
productId: number;
|
||||
defaultQuantity?: number;
|
||||
}
|
||||
const PrintBarcodeModal = ({
|
||||
innerProps
|
||||
}: ContextModalProps<Props>) => {
|
||||
const {productId, defaultQuantity = 1} = innerProps;
|
||||
};
|
||||
const PrintBarcodeModal = ({ innerProps }: ContextModalProps<Props>) => {
|
||||
const { productId, defaultQuantity = 1 } = innerProps;
|
||||
const [quantity, setQuantity] = useState(defaultQuantity);
|
||||
const [barcode, setBarcode] = useState<string | undefined>()
|
||||
const [barcode, setBarcode] = useState<string | undefined>();
|
||||
const [barcodeData, setBarcodeData] = useState<BarcodeSchema | undefined>();
|
||||
|
||||
const {product, refetch} = useGetProductById(productId);
|
||||
const { product, refetch } = useGetProductById(productId);
|
||||
|
||||
const barcodeRef = useRef(null);
|
||||
// const handlePrint = useReactToPrint({
|
||||
@@ -27,47 +25,47 @@ const PrintBarcodeModal = ({
|
||||
// });
|
||||
|
||||
const onAdd = (newBarcode: string) => {
|
||||
ProductService.addProductBarcode({requestBody: {productId, barcode: newBarcode}})
|
||||
.then(async ({ok, message}) => {
|
||||
notifications.guess(ok, {message});
|
||||
})
|
||||
}
|
||||
ProductService.addProductBarcode({
|
||||
requestBody: { productId, barcode: newBarcode },
|
||||
}).then(async ({ ok, message }) => {
|
||||
notifications.guess(ok, { message });
|
||||
});
|
||||
};
|
||||
const onAddClick = () => {
|
||||
if (!product) return;
|
||||
modals.openContextModal({
|
||||
modal: "addBarcode",
|
||||
title: 'Добавление штрихкода',
|
||||
title: "Добавление штрихкода",
|
||||
withCloseButton: true,
|
||||
innerProps: {
|
||||
productId: product.id,
|
||||
onSubmit: onAdd
|
||||
}
|
||||
})
|
||||
}
|
||||
onSubmit: onAdd,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const onGenerateClick = () => {
|
||||
if (!product) return;
|
||||
ProductService.generateProductBarcode({requestBody: {productId}})
|
||||
.then(async ({ok, message, barcode}) => {
|
||||
notifications.guess(ok, {message});
|
||||
if (!ok) return;
|
||||
await refetch();
|
||||
setBarcode(barcode);
|
||||
})
|
||||
}
|
||||
ProductService.generateProductBarcode({
|
||||
requestBody: { productId },
|
||||
}).then(async ({ ok, message, barcode }) => {
|
||||
notifications.guess(ok, { message });
|
||||
if (!ok) return;
|
||||
await refetch();
|
||||
setBarcode(barcode);
|
||||
});
|
||||
};
|
||||
const fetchBarcodeData = () => {
|
||||
if (!barcode) return;
|
||||
ProductService.getProductBarcode({
|
||||
requestBody:
|
||||
{barcode, productId}
|
||||
}).then(({barcode}) => {
|
||||
requestBody: { barcode, productId },
|
||||
}).then(({ barcode }) => {
|
||||
setBarcodeData(barcode);
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
useEffect(() => {
|
||||
if (!product) return;
|
||||
if (product.barcodes.length === 1)
|
||||
setBarcode(product.barcodes[0]);
|
||||
if (product.barcodes.length === 1) setBarcode(product.barcodes[0]);
|
||||
}, [product]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -79,11 +77,10 @@ const PrintBarcodeModal = ({
|
||||
<>
|
||||
<Flex
|
||||
gap={rem(10)}
|
||||
direction={"column"}
|
||||
>
|
||||
direction={"column"}>
|
||||
<Select
|
||||
value={barcode}
|
||||
onChange={(value) => setBarcode(value || undefined)}
|
||||
onChange={value => setBarcode(value || undefined)}
|
||||
data={product?.barcodes}
|
||||
label={"Штрихкод"}
|
||||
placeholder={"Выберите штрихкод"}
|
||||
@@ -92,14 +89,16 @@ const PrintBarcodeModal = ({
|
||||
label={"Количество копий"}
|
||||
placeholder={"Введите количество копий"}
|
||||
value={quantity}
|
||||
onChange={(value) => typeof value === "number" && setQuantity(value)}
|
||||
onChange={value =>
|
||||
typeof value === "number" && setQuantity(value)
|
||||
}
|
||||
min={1}
|
||||
/>
|
||||
|
||||
<Divider
|
||||
my={rem(10)}
|
||||
/>
|
||||
<Flex direction={"column"} gap={rem(10)}>
|
||||
<Divider my={rem(10)} />
|
||||
<Flex
|
||||
direction={"column"}
|
||||
gap={rem(10)}>
|
||||
<Flex gap={rem(10)}>
|
||||
<Button
|
||||
onClick={() => onAddClick()}
|
||||
@@ -119,25 +118,30 @@ const PrintBarcodeModal = ({
|
||||
disabled={!barcode}
|
||||
onClick={async () => {
|
||||
if (!barcode) return;
|
||||
const response = await ProductService.getProductBarcodePdf({
|
||||
requestBody: {
|
||||
productId,
|
||||
barcode,
|
||||
quantity
|
||||
}
|
||||
});
|
||||
const pdfBlob = base64ToBlob(response.base64String, response.mimeType);
|
||||
const response =
|
||||
await ProductService.getProductBarcodePdf({
|
||||
requestBody: {
|
||||
productId,
|
||||
barcode,
|
||||
quantity,
|
||||
},
|
||||
});
|
||||
const pdfBlob = base64ToBlob(
|
||||
response.base64String,
|
||||
response.mimeType
|
||||
);
|
||||
const pdfUrl = URL.createObjectURL(pdfBlob);
|
||||
const pdfWindow = window.open(pdfUrl);
|
||||
if (!pdfWindow) {
|
||||
notifications.error({message: "Ошибка"});
|
||||
return
|
||||
notifications.error({ message: "Ошибка" });
|
||||
return;
|
||||
}
|
||||
pdfWindow.onload = () => {
|
||||
pdfWindow.print();
|
||||
}
|
||||
}}
|
||||
>Печать</Button>
|
||||
};
|
||||
}}>
|
||||
Печать
|
||||
</Button>
|
||||
</Flex>
|
||||
</Flex>
|
||||
<PrintBarcodeContainer
|
||||
@@ -148,7 +152,7 @@ const PrintBarcodeModal = ({
|
||||
additionalField={barcodeData?.additionalField}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default PrintBarcodeModal;
|
||||
export default PrintBarcodeModal;
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import {GetServiceKitSchema} from "../../client";
|
||||
import {ContextModalProps} from "@mantine/modals";
|
||||
import {useState} from "react";
|
||||
import {Button, Flex, rem} from "@mantine/core";
|
||||
import { GetServiceKitSchema } from "../../client";
|
||||
import { ContextModalProps } from "@mantine/modals";
|
||||
import { useState } from "react";
|
||||
import { Button, Flex, rem } from "@mantine/core";
|
||||
import ServicesKitSelect from "../../components/Selects/ServicesKitSelect/ServicesKitSelect.tsx";
|
||||
import {notifications} from "../../shared/lib/notifications.ts";
|
||||
import { notifications } from "../../shared/lib/notifications.ts";
|
||||
|
||||
type Props = {
|
||||
onSelect: (kit: GetServiceKitSchema) => void;
|
||||
serviceType: number;
|
||||
}
|
||||
};
|
||||
|
||||
const ServicesKitSelectModal = ({
|
||||
context,
|
||||
id,
|
||||
innerProps
|
||||
}: ContextModalProps<Props>) => {
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<Props>) => {
|
||||
const [kit, setKit] = useState<GetServiceKitSchema | undefined>();
|
||||
const onSelectClick = () => {
|
||||
if (!kit) {
|
||||
notifications.error({message: "Выберите набор услуг"});
|
||||
notifications.error({ message: "Выберите набор услуг" });
|
||||
return;
|
||||
}
|
||||
innerProps.onSelect(kit);
|
||||
context.closeContextModal(id);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Flex
|
||||
gap={rem(10)}
|
||||
@@ -35,26 +35,27 @@ const ServicesKitSelectModal = ({
|
||||
placeholder={"Выберите набор услуг"}
|
||||
value={kit}
|
||||
onChange={setKit}
|
||||
filterBy={item => item.serviceType === innerProps.serviceType}
|
||||
filterBy={item =>
|
||||
item.serviceType === innerProps.serviceType
|
||||
}
|
||||
/>
|
||||
</Flex>
|
||||
<Flex justify={"flex-end"} gap={rem(10)}>
|
||||
<Flex
|
||||
justify={"flex-end"}
|
||||
gap={rem(10)}>
|
||||
<Button
|
||||
variant={"subtle"}
|
||||
onClick={() => context.closeContextModal(id)}
|
||||
>
|
||||
onClick={() => context.closeContextModal(id)}>
|
||||
Отменить
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onSelectClick}
|
||||
variant={"default"}
|
||||
>
|
||||
variant={"default"}>
|
||||
Добавить
|
||||
</Button>
|
||||
|
||||
</Flex>
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default ServicesKitSelectModal;
|
||||
export default ServicesKitSelectModal;
|
||||
|
||||
@@ -7,8 +7,7 @@ import AddDealServiceModal from "../pages/LeadsPage/modals/AddDealServiceModal.t
|
||||
import AddDealProductModal from "../pages/LeadsPage/modals/AddDealProductModal.tsx";
|
||||
import PrintBarcodeModal from "./PrintBarcodeModal/PrintBarcodeModal.tsx";
|
||||
import AddBarcodeModal from "./AddBarcodeModal/AddBarcodeModal.tsx";
|
||||
import BarcodeTemplateFormModal
|
||||
from "../pages/BarcodePage/modals/BarcodeTemplateFormModal/BarcodeTemplateFormModal.tsx";
|
||||
import BarcodeTemplateFormModal from "../pages/BarcodePage/modals/BarcodeTemplateFormModal/BarcodeTemplateFormModal.tsx";
|
||||
import ProductServiceFormModal from "../pages/LeadsPage/modals/ProductServiceFormModal.tsx";
|
||||
import UserFormModal from "../pages/AdminPage/modals/UserFormModal/UserFormModal.tsx";
|
||||
import EmployeeSelectModal from "./EmployeeSelectModal/EmployeeSelectModal.tsx";
|
||||
|
||||
Reference in New Issue
Block a user