feat(financial): add enable/disable toggle for shelter animal charity and round-up donation
This commit is contained in:
1 parent
e7ded849f6
commit
204350eff8
18 files changed
+11235
-11034
No files matched your search
@@ -18,6 +18,7 @@ export default function FinancialSettingsPage() {
|
||||
walletWithdrawalEnabled: false,
|
||||
});
|
||||
const [charityStep, setCharityStep] = useState('10000');
|
||||
const [charityEnabled, setCharityEnabled] = useState(true);
|
||||
const [refillEnabled, setRefillEnabled] = useState(false);
|
||||
const [refillPercent, setRefillPercent] = useState('5');
|
||||
|
||||
@@ -53,11 +54,18 @@ export default function FinancialSettingsPage() {
|
||||
charityDonationOptions: Array.isArray(data.charityDonationOptions)
|
||||
? data.charityDonationOptions.map(Number)
|
||||
: [10000, 20000, 50000],
|
||||
charityDonationEnabled: Boolean(data.charityDonationEnabled ?? true),
|
||||
walletWithdrawalEnabled: Boolean(data.walletWithdrawalEnabled ?? false),
|
||||
});
|
||||
if (data.charityDonationEnabled !== undefined) {
|
||||
setCharityEnabled(Boolean(data.charityDonationEnabled));
|
||||
}
|
||||
}
|
||||
if (resAdmin.data?.success) {
|
||||
setCharityStep(resAdmin.data.data.CHARITY_ROUND_STEP || '10000');
|
||||
if (resAdmin.data.data.CHARITY_DONATION_ENABLED !== undefined) {
|
||||
setCharityEnabled(resAdmin.data.data.CHARITY_DONATION_ENABLED !== 'false');
|
||||
}
|
||||
setRefillEnabled(resAdmin.data.data.REFILL_SUBSCRIPTION_ENABLED === 'true');
|
||||
setRefillPercent(resAdmin.data.data.REFILL_REWARD_PERCENT || '5');
|
||||
}
|
||||
@@ -87,10 +95,14 @@ export default function FinancialSettingsPage() {
|
||||
try {
|
||||
setIsSaving(true);
|
||||
const [, , resPricing] = await Promise.all([
|
||||
api.patch('/settings/financial', financial),
|
||||
api.patch('/settings/financial', {
|
||||
...financial,
|
||||
charityDonationEnabled: charityEnabled,
|
||||
}),
|
||||
api.put('/admin/settings', {
|
||||
TAX_PERCENTAGE: String(financial.taxPercentage),
|
||||
CHARITY_ROUND_STEP: charityStep,
|
||||
CHARITY_DONATION_ENABLED: charityEnabled ? 'true' : 'false',
|
||||
REFILL_SUBSCRIPTION_ENABLED: refillEnabled ? 'true' : 'false',
|
||||
REFILL_REWARD_PERCENT: refillPercent,
|
||||
}),
|
||||
@@ -168,63 +180,91 @@ export default function FinancialSettingsPage() {
|
||||
<p className="text-xs text-gray-500 mt-1">درصد قانونی محاسبه مالیات بر ارزش افزوده در فاکتور نهایی سفارشات.</p>
|
||||
</div>
|
||||
|
||||
{/* Charity Round Step */}
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1.5 flex items-center gap-1.5">
|
||||
<Heart className="w-4 h-4 text-rose-500" />
|
||||
<span>پله رند کردن کمک به خیریه ردپای مهربانی (تومان)</span>
|
||||
{/* Charity Donation Toggle & Step */}
|
||||
<div className="md:col-span-2 p-5 bg-rose-50/50 rounded-2xl border border-rose-100 space-y-4">
|
||||
<label className="flex items-center justify-between cursor-pointer">
|
||||
<div className="flex items-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={charityEnabled}
|
||||
onChange={(e) => setCharityEnabled(e.target.checked)}
|
||||
className="w-5 h-5 mt-0.5 rounded-lg text-rose-600 focus:ring-rose-500 border-gray-300 cursor-pointer"
|
||||
/>
|
||||
<div>
|
||||
<span className="text-sm font-black text-gray-900 block flex items-center gap-2">
|
||||
<Heart className="w-4 h-4 text-rose-500 fill-rose-500" />
|
||||
فعالسازی طرح ردپای مهربانی (کمک داوطلبانه به پناهگاه حیوانات)
|
||||
</span>
|
||||
<span className="text-xs text-gray-500 font-medium block mt-1">
|
||||
در صورت غیرفعال بودن، بخش رند کردن فاکتور، مشارکت در خیریه و ردپای مهربانی به طور کامل از تسویهحساب و بخشهای مختلف سایت مخفی میشود.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
<PriceInput
|
||||
value={charityStep}
|
||||
onChange={(val) => setCharityStep(val)}
|
||||
placeholder="10000"
|
||||
className="px-4 py-3 rounded-xl border border-gray-200 focus:border-emerald-500 text-sm"
|
||||
/>
|
||||
<p className="text-xs text-gray-500 mt-1">مبلغ فاکتور به نزدیکترین ضریب این عدد (مثلاً ۱۰,۰۰۰ یا ۵۰,۰۰۰ تومان) رند میگردد.</p>
|
||||
|
||||
{charityEnabled && (
|
||||
<div className="pt-4 border-t border-rose-100/80 grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1.5 flex items-center gap-1.5">
|
||||
<Heart className="w-4 h-4 text-rose-500" />
|
||||
<span>پله رند کردن کمک به خیریه ردپای مهربانی (تومان)</span>
|
||||
</label>
|
||||
<PriceInput
|
||||
value={charityStep}
|
||||
onChange={(val) => setCharityStep(val)}
|
||||
placeholder="10000"
|
||||
className="px-4 py-3 rounded-xl border border-gray-200 focus:border-rose-500 text-sm bg-white"
|
||||
/>
|
||||
<p className="text-xs text-gray-500 mt-1">مبلغ فاکتور به نزدیکترین ضریب این عدد (مثلاً ۱۰,۰۰۰ یا ۵۰,۰۰۰ تومان) رند میگردد.</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Charity Donation Options */}
|
||||
<div className="md:col-span-2 space-y-2 pt-3 border-t border-gray-100">
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1 flex items-center gap-1.5">
|
||||
<Heart className="w-4 h-4 text-rose-500" />
|
||||
<span>گزینههای دلخواه کمک مستقیم به خیریه (charityDonationOptions)</span>
|
||||
</label>
|
||||
<div className="flex gap-2 max-w-md">
|
||||
<PriceInput
|
||||
placeholder="مبلغ جدید (مثال: ۱۰۰,۰۰۰)"
|
||||
value={donationInput}
|
||||
onChange={(val) => setDonationInput(val)}
|
||||
className="px-4 py-2 rounded-xl border border-gray-200 text-xs"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
size="xs"
|
||||
startIcon={Plus}
|
||||
onClick={addDonationOption}
|
||||
>
|
||||
افزودن
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2 pt-2">
|
||||
{financial.charityDonationOptions.map((amount) => (
|
||||
<span
|
||||
key={amount}
|
||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-rose-50 text-rose-700 text-xs font-bold rounded-xl border border-rose-200"
|
||||
{charityEnabled && (
|
||||
<div className="md:col-span-2 space-y-2 pt-3 border-t border-gray-100">
|
||||
<label className="block text-sm font-bold text-gray-700 mb-1 flex items-center gap-1.5">
|
||||
<Heart className="w-4 h-4 text-rose-500" />
|
||||
<span>گزینههای دلخواه کمک مستقیم به خیریه (charityDonationOptions)</span>
|
||||
</label>
|
||||
<div className="flex gap-2 max-w-md">
|
||||
<PriceInput
|
||||
placeholder="مبلغ جدید (مثال: ۱۰۰,۰۰۰)"
|
||||
value={donationInput}
|
||||
onChange={(val) => setDonationInput(val)}
|
||||
className="px-4 py-2 rounded-xl border border-gray-200 text-xs"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
size="xs"
|
||||
startIcon={Plus}
|
||||
onClick={addDonationOption}
|
||||
>
|
||||
{amount.toLocaleString('fa-IR')} تومان
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeDonationOption(amount)}
|
||||
className="hover:text-red-500 cursor-pointer"
|
||||
افزودن
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2 pt-2">
|
||||
{financial.charityDonationOptions.map((amount) => (
|
||||
<span
|
||||
key={amount}
|
||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-rose-50 text-rose-700 text-xs font-bold rounded-xl border border-rose-200"
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
{amount.toLocaleString('fa-IR')} تومان
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeDonationOption(amount)}
|
||||
className="hover:text-red-500 cursor-pointer"
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Refill Subscription and Reward Cashback */}
|
||||
<div className="md:col-span-2 pt-4 border-t border-gray-100 space-y-4">
|
||||
|
||||
@@ -198,6 +198,7 @@ export interface FinancialSettings {
|
||||
freeShippingThreshold: number;
|
||||
standardShippingFee: number;
|
||||
charityDonationOptions: number[];
|
||||
charityDonationEnabled?: boolean;
|
||||
walletWithdrawalEnabled?: boolean;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user