From abe53b885a933d05a848c202e83c4a555fbc23bf Mon Sep 17 00:00:00 2001 From: wixarm Date: Sun, 15 Feb 2026 10:17:42 +0330 Subject: [PATCH] add: one time purchase limit --- src/partials/quota/AddQuota.tsx | 7 ++--- src/partials/quota/QuotaLevel3.tsx | 23 +++++++++++++--- src/partials/quota/QuotaView.tsx | 43 +++++++++++++++++------------- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/partials/quota/AddQuota.tsx b/src/partials/quota/AddQuota.tsx index ee56fd8..74c1425 100644 --- a/src/partials/quota/AddQuota.tsx +++ b/src/partials/quota/AddQuota.tsx @@ -70,7 +70,7 @@ export const AddQuota = ({ item, getData }: Props) => { const handleSubmitForm = async () => { if (item && item?.quota_distributed > 0) { const confirmed = await showConfirmToast( - "اطلاعات ویرایش شده بر روی تمام توزیع های زیر مجموعه اعمال میشود!" + "اطلاعات ویرایش شده بر روی تمام توزیع های زیر مجموعه اعمال میشود!", ); if (!confirmed) { return; @@ -96,15 +96,16 @@ export const AddQuota = ({ item, getData }: Props) => { broker_data: formData?.broker_data, pos_sale_type: formData?.pos_sale_type, livestock_allocation_data: formData?.livestockTypes?.filter( - (opt: { quantity_kg: number }) => opt?.quantity_kg > 0 + (opt: { quantity_kg: number }) => opt?.quantity_kg > 0, ), livestock_age_limitations: formData?.livestock_age_limitations, pre_sale: formData?.pre_sale, free_sale: formData?.free_sale, + one_time_purchase_limit: formData?.one_time_purchase_limit, }; let filterEmptyKeys = Object.fromEntries( - Object.entries(submitData).filter(([, v]) => v != null) + Object.entries(submitData).filter(([, v]) => v != null), ); try { diff --git a/src/partials/quota/QuotaLevel3.tsx b/src/partials/quota/QuotaLevel3.tsx index 1a8b254..baca797 100644 --- a/src/partials/quota/QuotaLevel3.tsx +++ b/src/partials/quota/QuotaLevel3.tsx @@ -24,13 +24,17 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => { const internalRef = useRef(null); const [limitByHerdSize, setLimitByHerdSize] = useState( - item?.limit_by_herd_size || false + item?.limit_by_herd_size || false, ); const [preSale, setPreSale] = useState(item?.pre_sale || false); const [freeSale, setFreeSale] = useState(item?.free_sale || false); + const [oneTimePurchase, setOneTimePurchase] = useState( + item?.one_time_purchase_limit || false, + ); + useEffect(() => { if (visible) { setFormRef(internalRef.current); @@ -66,7 +70,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => { (option: any) => option?.livestock_type?.weight_type === allocate?.weight_type && option?.livestock_type?.id === allocate?.id && - option?.livestock_type?.name === allocate?.name + option?.livestock_type?.name === allocate?.name, ); if (result) { return result.age_month; @@ -105,6 +109,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => { }), pre_sale: preSale, free_sale: freeSale, + one_time_purchase_limit: oneTimePurchase, }; if ( @@ -234,7 +239,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => { const originalIndex = livestockTypes.findIndex( (type) => type.livestock_type === item.livestock_type && - type.weight_type === item.weight_type + type.weight_type === item.weight_type, ); if (originalIndex !== -1) { handleLivestockTypeChange(originalIndex, value); @@ -268,7 +273,7 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => { const originalIndex = livestockTypes.findIndex( (type) => type.livestock_type === item.livestock_type && - type.weight_type === item.weight_type + type.weight_type === item.weight_type, ); if (originalIndex !== -1) { handleLivestockTypeChange(originalIndex, value); @@ -301,6 +306,16 @@ export const QuotaLevel3 = ({ item, onSubmit, setFormRef, visible }: Props) => { }} /> + + + { + setOneTimePurchase(!oneTimePurchase); + }} + /> + diff --git a/src/partials/quota/QuotaView.tsx b/src/partials/quota/QuotaView.tsx index c1bb86e..813337d 100644 --- a/src/partials/quota/QuotaView.tsx +++ b/src/partials/quota/QuotaView.tsx @@ -129,8 +129,8 @@ export const QuotaView: React.FC = ({ item }) => { group === "rural" ? "روستایی" : group === "industrial" - ? "صنعتی" - : "عشایری" + ? "صنعتی" + : "عشایری", ) .join(", ") || "-" } @@ -145,10 +145,10 @@ export const QuotaView: React.FC = ({ item }) => { item?.pos_sale_type === "all" ? "بر اساس تعداد راس دام و وزن" : item?.pos_sale_type === "weight" - ? "بر اساس وزن" - : item?.pos_sale_type === "count" - ? "بر اساس تعداد راس دام" - : "-" + ? "بر اساس وزن" + : item?.pos_sale_type === "count" + ? "بر اساس تعداد راس دام" + : "-" } /> @@ -202,8 +202,8 @@ export const QuotaView: React.FC = ({ item }) => { acc[group].push(allocation); return acc; }, - {} as Record - ) + {} as Record, + ), ) as [string, any[]][] ).map(([group, allocations]) => (
@@ -215,8 +215,8 @@ export const QuotaView: React.FC = ({ item }) => { {group === "rural" ? "روستایی" : group === "industrial" - ? "صنعتی" - : "سایر"} + ? "صنعتی" + : "سایر"}
@@ -296,6 +296,13 @@ export const QuotaView: React.FC = ({ item }) => { +
+ + محدودیت یکبار خرید از سهیمه:{" "} + {item?.one_time_purchase_limit ? "دارد" : "ندارد"} + +
+
= ({ item }) => { opt?.name + (opt: { name: string }) => opt?.name, )} /> ) : ( @@ -341,7 +348,7 @@ export const QuotaView: React.FC = ({ item }) => { opt?.livestock_type?.weight_type === "L" ? "سبک" : "سنگین" - }) با سن ${opt?.age_month}` + }) با سن ${opt?.age_month}`, )} /> ) : ( @@ -423,7 +430,7 @@ export const QuotaView: React.FC = ({ item }) => {
- ) + ), )} )} @@ -453,7 +460,7 @@ export const QuotaView: React.FC = ({ item }) => { pricing_type_name: string; name: string; value: number; - } + }, ) => { const key = itm.pricing_type_name; if (acc[key]) { @@ -463,8 +470,8 @@ export const QuotaView: React.FC = ({ item }) => { } return acc; }, - {} as Record - ) + {} as Record, + ), ).map((priceItem: any, priceIndex: number) => (
= ({ item }) => { acc[key].push(itm); return acc; }, - {} as Record - ) + {} as Record, + ), ) as [string, any[]][] ).map(([pricingTypeName, items]) => (