feat: inn verification
This commit is contained in:
@@ -9,6 +9,7 @@ import InlineButton from "../../../../components/InlineButton/InlineButton.tsx";
|
||||
import { isEqual } from "lodash";
|
||||
import { IMaskInput } from "react-imask";
|
||||
import phone from "phone";
|
||||
import isValidInn from "../../../../pages/ClientsPage/utils/isValidInn.ts";
|
||||
|
||||
const ClientTab = () => {
|
||||
const { selectedCard: card, refetchCard } = useCardPageContext();
|
||||
@@ -27,6 +28,7 @@ const ClientTab = () => {
|
||||
strictDetection: false,
|
||||
validateMobilePrefix: false,
|
||||
}).isValid && "Неверно указан номер телефона",
|
||||
inn: (inn: string | undefined | null) => inn && !isValidInn(inn) ? "Некорректный ИНН" : null,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -19,6 +19,7 @@ import classNames from "classnames";
|
||||
import GeneralDataForm from "./components/GeneralDataForm/GeneralDataForm.tsx";
|
||||
import PrintDealBarcodesButton from "./components/PrintDealBarcodesButton/PrintDealBarcodesButton.tsx";
|
||||
import PaymentLinkButton from "./components/PaymentLinkButton/PaymentLinkButton.tsx";
|
||||
import isValidInn from "../../../../pages/ClientsPage/utils/isValidInn.ts";
|
||||
|
||||
const ProductAndServiceTab: FC = () => {
|
||||
const { cardState, cardServicesState, cardProductsState } = useCardProductAndServiceTabState();
|
||||
@@ -147,6 +148,11 @@ const ProductAndServiceTab: FC = () => {
|
||||
|
||||
const onCreateBillClick = () => {
|
||||
if (!cardState.card) return;
|
||||
if (!isValidInn(cardState.card.client?.details?.inn)) {
|
||||
notifications.error({ message: "Некорректный ИНН" });
|
||||
return;
|
||||
}
|
||||
|
||||
const cardId = cardState.card.id;
|
||||
modals.openConfirmModal({
|
||||
withCloseButton: false,
|
||||
@@ -182,6 +188,11 @@ const ProductAndServiceTab: FC = () => {
|
||||
};
|
||||
const onCancelBillClick = () => {
|
||||
if (!cardState.card) return;
|
||||
if (!isValidInn(cardState.card.client?.details?.inn)) {
|
||||
notifications.error({ message: "Некорректный ИНН" });
|
||||
return;
|
||||
}
|
||||
|
||||
const cardId = cardState.card.id;
|
||||
modals.openConfirmModal({
|
||||
withCloseButton: false,
|
||||
|
||||
@@ -2,10 +2,9 @@ import { ContextModalProps } from "@mantine/modals";
|
||||
import { Fieldset, Textarea, TextInput } from "@mantine/core";
|
||||
import { useForm } from "@mantine/form";
|
||||
import { ClientSchema } from "../../../../client";
|
||||
import BaseFormModal, {
|
||||
CreateEditFormProps,
|
||||
} from "../BaseFormModal/BaseFormModal.tsx";
|
||||
import BaseFormModal, { CreateEditFormProps } from "../BaseFormModal/BaseFormModal.tsx";
|
||||
import BarcodeTemplateSelect from "../../../../components/Selects/BarcodeTemplateSelect/BarcodeTemplateSelect.tsx";
|
||||
import isValidInn from "../../utils/isValidInn.ts";
|
||||
|
||||
type Props = CreateEditFormProps<ClientSchema>;
|
||||
|
||||
@@ -37,12 +36,12 @@ const ClientFormModal = ({
|
||||
name.trim() !== ""
|
||||
? null
|
||||
: "Необходимо ввести название клиента",
|
||||
// details: {
|
||||
// telegram: (address: string | undefined | null) => (address && address.trim() !== '') ? null : "Необходимо ввести телеграм",
|
||||
// phoneNumber: (phoneNumber: string | undefined | null) => (phoneNumber && phoneNumber.trim() !== '') ? null : "Необходимо ввести номер телефона",
|
||||
// email: (email: string | undefined | null) => (email && email.trim() !== '') ? null : "Необходимо ввести почту",
|
||||
// inn: (inn: string | undefined | null) => (inn && getDigitsCount(parseInt(inn)) >= 10) ? null : "ИНН должен содержать не менее 10 цифр",
|
||||
// }
|
||||
details: {
|
||||
// telegram: (address: string | undefined | null) => (address && address.trim() !== '') ? null : "Необходимо ввести телеграм",
|
||||
// phoneNumber: (phoneNumber: string | undefined | null) => (phoneNumber && phoneNumber.trim() !== '') ? null : "Необходимо ввести номер телефона",
|
||||
// email: (email: string | undefined | null) => (email && email.trim() !== '') ? null : "Необходимо ввести почту",
|
||||
inn: (inn: string | undefined | null) => inn && !isValidInn(inn) ? "Некорректный ИНН" : null,
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
5
src/pages/ClientsPage/utils/isValidInn.ts
Normal file
5
src/pages/ClientsPage/utils/isValidInn.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
const isValidInn = (inn: string | null | undefined) => {
|
||||
return inn && inn.match(/^(\d{12}|\d{10})$/);
|
||||
};
|
||||
|
||||
export default isValidInn;
|
||||
Reference in New Issue
Block a user