feat(admin): add confirmation modal before applying bulk price adjustments and margins
This commit is contained in:
1 parent
ceaab10fdd
commit
3344fe7f8d
12 files changed
+3203
-3106
No files matched your search
@@ -326,6 +326,21 @@ export default function Products() {
|
||||
wholesaleMarginPercent: 15,
|
||||
});
|
||||
|
||||
// Confirm Modal state for Bulk Price actions
|
||||
const [confirmBulkModal, setConfirmBulkModal] = useState<{
|
||||
isOpen: boolean;
|
||||
type: 'adjust' | 'margin';
|
||||
title: string;
|
||||
message: string;
|
||||
confirmText: string;
|
||||
}>({
|
||||
isOpen: false,
|
||||
type: 'adjust',
|
||||
title: '',
|
||||
message: '',
|
||||
confirmText: 'تایید و اعمال',
|
||||
});
|
||||
|
||||
const [draggedMediaIdx, setDraggedMediaIdx] = useState<number | null>(null);
|
||||
const [dragOverMediaIdx, setDragOverMediaIdx] = useState<number | null>(null);
|
||||
const [customMediaUrl, setCustomMediaUrl] = useState('');
|
||||
@@ -725,6 +740,74 @@ export default function Products() {
|
||||
}
|
||||
};
|
||||
|
||||
// Open Confirmation Modal before applying bulk actions
|
||||
const handleInitiateBulkAction = () => {
|
||||
if (bulkPriceTab === 'adjust') {
|
||||
if (!bulkAdjustForm.value || Number(bulkAdjustForm.value) <= 0) {
|
||||
toast.error('لطفاً مقدار معتبر برای تغییر قیمت وارد نمایید');
|
||||
return;
|
||||
}
|
||||
|
||||
const scopeText = bulkAdjustForm.scope === 'ALL'
|
||||
? 'تمامی محصولات کاتالوگ'
|
||||
: `${bulkAdjustForm.categoryIds.length} دستهبندی انتخابشده`;
|
||||
|
||||
const dirText = bulkAdjustForm.adjustmentDirection === 'INCREASE' ? 'افزایش' : 'کاهش';
|
||||
const valText = bulkAdjustForm.adjustmentType === 'PERCENT'
|
||||
? `${bulkAdjustForm.value} درصد`
|
||||
: `${Number(bulkAdjustForm.value).toLocaleString('fa-IR')} تومان`;
|
||||
|
||||
const fieldText =
|
||||
bulkAdjustForm.targetField === 'RETAIL' ? 'قیمت مصرفکننده (فروش)' :
|
||||
bulkAdjustForm.targetField === 'WHOLESALE' ? 'قیمت همکار (عمده)' :
|
||||
bulkAdjustForm.targetField === 'BUY' ? 'قیمت خرید' :
|
||||
bulkAdjustForm.targetField === 'BOTH_SELLING' ? 'هر دو قیمت فروش (مصرفکننده و همکار)' :
|
||||
'تمامی قیمتها (خرید، فروش و همکار)';
|
||||
|
||||
const message = `آیا از اعمال ${dirText} ${valText} بر روی ${fieldText} برای ${scopeText} مطمئن هستید؟ این عملیات بلافاصله قیمتهای پایگاه داده را بهروزرسانی خواهد کرد.`;
|
||||
|
||||
setConfirmBulkModal({
|
||||
isOpen: true,
|
||||
type: 'adjust',
|
||||
title: 'تأیید اعمال گروهی تغییرات قیمت',
|
||||
message,
|
||||
confirmText: 'تایید و تغییر قیمتها',
|
||||
});
|
||||
} else {
|
||||
if (globalMarginForm.retailMarginPercent === undefined || Number(globalMarginForm.retailMarginPercent) < 0) {
|
||||
toast.error('لطفاً درصد سود مصرفکننده معتبر وارد نمایید');
|
||||
return;
|
||||
}
|
||||
if (globalMarginForm.wholesaleMarginPercent === undefined || Number(globalMarginForm.wholesaleMarginPercent) < 0) {
|
||||
toast.error('لطفاً درصد سود همکار معتبر وارد نمایید');
|
||||
return;
|
||||
}
|
||||
|
||||
const scopeText = globalMarginForm.scope === 'ALL'
|
||||
? 'تمامی محصولات کاتالوگ'
|
||||
: `${globalMarginForm.categoryIds.length} دستهبندی انتخابشده`;
|
||||
|
||||
const message = `آیا از محاسبه مجدد و اعمال سراسری سود (${globalMarginForm.retailMarginPercent}٪ مصرفکننده و ${globalMarginForm.wholesaleMarginPercent}٪ همکار) بر روی ${scopeText} مطمئن هستید؟ قیمتهای فروش بر اساس قیمت خرید و درصدهای سود جدید بازنویسی و رند خواهند شد.`;
|
||||
|
||||
setConfirmBulkModal({
|
||||
isOpen: true,
|
||||
type: 'margin',
|
||||
title: 'تأیید محاسبه و اعمال سراسری درصد سود',
|
||||
message,
|
||||
confirmText: 'تایید و محاسبه سود',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleConfirmBulkAction = async () => {
|
||||
if (confirmBulkModal.type === 'adjust') {
|
||||
await handleBulkPriceAdjustment();
|
||||
} else {
|
||||
await handleApplyGlobalMargins();
|
||||
}
|
||||
setConfirmBulkModal(prev => ({ ...prev, isOpen: false }));
|
||||
};
|
||||
|
||||
|
||||
|
||||
const handleSave = async (e: React.FormEvent) => {
|
||||
@@ -3929,7 +4012,7 @@ export default function Products() {
|
||||
size="sm"
|
||||
startIcon={isBulkApplying ? Spinner : CheckCircle2}
|
||||
isLoading={isBulkApplying}
|
||||
onClick={bulkPriceTab === 'adjust' ? handleBulkPriceAdjustment : handleApplyGlobalMargins}
|
||||
onClick={handleInitiateBulkAction}
|
||||
>
|
||||
{bulkPriceTab === 'adjust' ? 'اعمال تغییرات قیمت بر روی کالاها' : 'محاسبه و اعمال سراسری سود'}
|
||||
</Button>
|
||||
@@ -3963,6 +4046,7 @@ export default function Products() {
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Delete Product Confirmation Modal */}
|
||||
<ConfirmModal
|
||||
isOpen={!!deleteTargetId}
|
||||
title="حذف محصول"
|
||||
@@ -3971,6 +4055,19 @@ export default function Products() {
|
||||
onCancel={() => setDeleteTargetId(null)}
|
||||
/>
|
||||
|
||||
{/* Bulk Price Operations Confirmation Modal */}
|
||||
<ConfirmModal
|
||||
isOpen={confirmBulkModal.isOpen}
|
||||
title={confirmBulkModal.title}
|
||||
message={confirmBulkModal.message}
|
||||
confirmText={confirmBulkModal.confirmText}
|
||||
cancelText="انصراف و بازگشت"
|
||||
isDestructive={true}
|
||||
isLoading={isBulkApplying}
|
||||
onConfirm={handleConfirmBulkAction}
|
||||
onCancel={() => setConfirmBulkModal(prev => ({ ...prev, isOpen: false }))}
|
||||
/>
|
||||
|
||||
{/* Product Image Lightbox Modal */}
|
||||
{previewImage && (
|
||||
<div
|
||||
|
||||
Reference in new issue
Block a user