add max payment method for cheque
All checks were successful
Deploy Amap / deploy (push) Successful in 34s
All checks were successful
Deploy Amap / deploy (push) Successful in 34s
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { t } from "@/config/i18n";
|
||||
import type { ContractInputs } from "@/services/resources/contracts";
|
||||
import { Group, NumberInput, Stack, Text, TextInput, Title } from "@mantine/core";
|
||||
import type { Productor } from "@/services/resources/productors";
|
||||
import { Group, NumberInput, Stack, TextInput, Title } from "@mantine/core";
|
||||
import type { UseFormReturnType } from "@mantine/form";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useMemo } from "react";
|
||||
|
||||
export type ContractChequeProps = {
|
||||
inputForm: UseFormReturnType<ContractInputs>;
|
||||
price: number;
|
||||
chequeOrder: string;
|
||||
productor: Productor;
|
||||
};
|
||||
|
||||
export type Cheque = {
|
||||
@@ -15,7 +16,7 @@ export type Cheque = {
|
||||
value: string;
|
||||
};
|
||||
|
||||
export function ContractCheque({ inputForm, price, chequeOrder }: ContractChequeProps) {
|
||||
export function ContractCheque({ inputForm, price, productor }: ContractChequeProps) {
|
||||
useEffect(() => {
|
||||
if (!inputForm.values.payment_method.includes("cheque")) {
|
||||
return;
|
||||
@@ -41,9 +42,13 @@ export function ContractCheque({ inputForm, price, chequeOrder }: ContractCheque
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [inputForm.values.cheque_quantity, price, inputForm.values.cheques]);
|
||||
|
||||
const paymentMethod = useMemo(() => {
|
||||
return productor?.payment_methods.find((el) => el.name === "cheque")
|
||||
}, [productor]);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Title order={4}>{`${t("order name")} : ${chequeOrder}`}</Title>
|
||||
<Title order={4}>{`${t("order name")} : ${paymentMethod?.details}`}</Title>
|
||||
<NumberInput
|
||||
label={t("cheque quantity", { capfirst: true })}
|
||||
placeholder={t("enter cheque quantity", { capfirst: true })}
|
||||
@@ -52,7 +57,7 @@ export function ContractCheque({ inputForm, price, chequeOrder }: ContractCheque
|
||||
{ capfirst: true },
|
||||
)}
|
||||
min={1}
|
||||
max={3}
|
||||
max={paymentMethod?.max || 3}
|
||||
{...inputForm.getInputProps(`cheque_quantity`)}
|
||||
/>
|
||||
<Group grow>
|
||||
@@ -64,7 +69,7 @@ export function ContractCheque({ inputForm, price, chequeOrder }: ContractCheque
|
||||
{...inputForm.getInputProps(`cheques.${index}.name`)}
|
||||
error={
|
||||
cheque.name == "" ?
|
||||
<Text size="sm" c="red">{inputForm?.errors.cheques}</Text> :
|
||||
inputForm?.errors.cheques :
|
||||
null
|
||||
}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user