feat: inn verification

This commit is contained in:
2025-04-03 00:04:06 +04:00
parent ad09103e14
commit a7ed490ec3
4 changed files with 26 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ import InlineButton from "../../../../components/InlineButton/InlineButton.tsx";
import { isEqual } from "lodash"; import { isEqual } from "lodash";
import { IMaskInput } from "react-imask"; import { IMaskInput } from "react-imask";
import phone from "phone"; import phone from "phone";
import isValidInn from "../../../../pages/ClientsPage/utils/isValidInn.ts";
const ClientTab = () => { const ClientTab = () => {
const { selectedCard: card, refetchCard } = useCardPageContext(); const { selectedCard: card, refetchCard } = useCardPageContext();
@@ -27,6 +28,7 @@ const ClientTab = () => {
strictDetection: false, strictDetection: false,
validateMobilePrefix: false, validateMobilePrefix: false,
}).isValid && "Неверно указан номер телефона", }).isValid && "Неверно указан номер телефона",
inn: (inn: string | undefined | null) => inn && !isValidInn(inn) ? "Некорректный ИНН" : null,
}, },
}, },
}, },

View File

@@ -19,6 +19,7 @@ import classNames from "classnames";
import GeneralDataForm from "./components/GeneralDataForm/GeneralDataForm.tsx"; import GeneralDataForm from "./components/GeneralDataForm/GeneralDataForm.tsx";
import PrintDealBarcodesButton from "./components/PrintDealBarcodesButton/PrintDealBarcodesButton.tsx"; import PrintDealBarcodesButton from "./components/PrintDealBarcodesButton/PrintDealBarcodesButton.tsx";
import PaymentLinkButton from "./components/PaymentLinkButton/PaymentLinkButton.tsx"; import PaymentLinkButton from "./components/PaymentLinkButton/PaymentLinkButton.tsx";
import isValidInn from "../../../../pages/ClientsPage/utils/isValidInn.ts";
const ProductAndServiceTab: FC = () => { const ProductAndServiceTab: FC = () => {
const { cardState, cardServicesState, cardProductsState } = useCardProductAndServiceTabState(); const { cardState, cardServicesState, cardProductsState } = useCardProductAndServiceTabState();
@@ -147,6 +148,11 @@ const ProductAndServiceTab: FC = () => {
const onCreateBillClick = () => { const onCreateBillClick = () => {
if (!cardState.card) return; if (!cardState.card) return;
if (!isValidInn(cardState.card.client?.details?.inn)) {
notifications.error({ message: "Некорректный ИНН" });
return;
}
const cardId = cardState.card.id; const cardId = cardState.card.id;
modals.openConfirmModal({ modals.openConfirmModal({
withCloseButton: false, withCloseButton: false,
@@ -182,6 +188,11 @@ const ProductAndServiceTab: FC = () => {
}; };
const onCancelBillClick = () => { const onCancelBillClick = () => {
if (!cardState.card) return; if (!cardState.card) return;
if (!isValidInn(cardState.card.client?.details?.inn)) {
notifications.error({ message: "Некорректный ИНН" });
return;
}
const cardId = cardState.card.id; const cardId = cardState.card.id;
modals.openConfirmModal({ modals.openConfirmModal({
withCloseButton: false, withCloseButton: false,

View File

@@ -2,10 +2,9 @@ import { ContextModalProps } from "@mantine/modals";
import { Fieldset, Textarea, TextInput } from "@mantine/core"; import { Fieldset, Textarea, TextInput } from "@mantine/core";
import { useForm } from "@mantine/form"; import { useForm } from "@mantine/form";
import { ClientSchema } from "../../../../client"; import { ClientSchema } from "../../../../client";
import BaseFormModal, { import BaseFormModal, { CreateEditFormProps } from "../BaseFormModal/BaseFormModal.tsx";
CreateEditFormProps,
} from "../BaseFormModal/BaseFormModal.tsx";
import BarcodeTemplateSelect from "../../../../components/Selects/BarcodeTemplateSelect/BarcodeTemplateSelect.tsx"; import BarcodeTemplateSelect from "../../../../components/Selects/BarcodeTemplateSelect/BarcodeTemplateSelect.tsx";
import isValidInn from "../../utils/isValidInn.ts";
type Props = CreateEditFormProps<ClientSchema>; type Props = CreateEditFormProps<ClientSchema>;
@@ -37,12 +36,12 @@ const ClientFormModal = ({
name.trim() !== "" name.trim() !== ""
? null ? null
: "Необходимо ввести название клиента", : "Необходимо ввести название клиента",
// details: { details: {
// telegram: (address: string | undefined | null) => (address && address.trim() !== '') ? null : "Необходимо ввести телеграм", // telegram: (address: string | undefined | null) => (address && address.trim() !== '') ? null : "Необходимо ввести телеграм",
// phoneNumber: (phoneNumber: string | undefined | null) => (phoneNumber && phoneNumber.trim() !== '') ? null : "Необходимо ввести номер телефона", // phoneNumber: (phoneNumber: string | undefined | null) => (phoneNumber && phoneNumber.trim() !== '') ? null : "Необходимо ввести номер телефона",
// email: (email: string | undefined | null) => (email && email.trim() !== '') ? null : "Необходимо ввести почту", // email: (email: string | undefined | null) => (email && email.trim() !== '') ? null : "Необходимо ввести почту",
// inn: (inn: string | undefined | null) => (inn && getDigitsCount(parseInt(inn)) >= 10) ? null : "ИНН должен содержать не менее 10 цифр", inn: (inn: string | undefined | null) => inn && !isValidInn(inn) ? "Некорректный ИНН" : null,
// } }
}, },
}); });

View File

@@ -0,0 +1,5 @@
const isValidInn = (inn: string | null | undefined) => {
return inn && inn.match(/^(\d{12}|\d{10})$/);
};
export default isValidInn;