feat(settings): restructure settings into payment, shipping, and rich page builder v2 with SEO and icons
Deploy Canina / deploy (push) Has been cancelled

This commit is contained in:
parsa aghaei committed 2026-08-18 20:08:07 +03:30
1 parent aa10ee735f
commit a291fa0c4a
22 files changed
+37783 -35567

No files matched your search

@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { DollarSign, Save, Plus, X } from 'lucide-react';
import { DollarSign, Save, Plus, X, Heart, Percent, Wallet } from 'lucide-react';
import { toast } from 'react-hot-toast';
import api from '../services/api';
import Spinner from '../components/ui/Spinner';
@@ -14,16 +14,20 @@ export default function FinancialSettingsPage() {
charityDonationOptions: [10000, 20000, 50000],
walletWithdrawalEnabled: false,
});
const [charityStep, setCharityStep] = useState('10000');
const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
const [donationInput, setDonationInput] = useState('');
useEffect(() => {
let isSubscribed = true;
api.get('/settings/financial')
.then(res => {
Promise.all([
api.get('/settings/financial'),
api.get('/admin/settings'),
])
.then(([resFin, resAdmin]) => {
if (!isSubscribed) return;
const data = res.data?.data || res.data;
const data = resFin.data?.data || resFin.data;
if (data) {
setFinancial({
taxPercentage: Number(data.taxPercentage ?? 10),
@@ -35,8 +39,11 @@ export default function FinancialSettingsPage() {
walletWithdrawalEnabled: Boolean(data.walletWithdrawalEnabled ?? false),
});
}
if (resAdmin.data?.success) {
setCharityStep(resAdmin.data.data.CHARITY_ROUND_STEP || '10000');
}
})
.catch(err => {
.catch((err) => {
console.warn('Failed to fetch Financial settings', err);
})
.finally(() => {
@@ -51,8 +58,14 @@ export default function FinancialSettingsPage() {
e.preventDefault();
try {
setIsSaving(true);
await api.patch('/settings/financial', financial);
toast.success('تنظیمات مالی و ارسال با موفقیت بروزرسانی شد');
await Promise.all([
api.patch('/settings/financial', financial),
api.put('/admin/settings', {
TAX_PERCENTAGE: String(financial.taxPercentage),
CHARITY_ROUND_STEP: charityStep,
}),
]);
toast.success('تنظیمات مالی با موفقیت بروزرسانی شد');
} catch (err) {
console.error('Failed to update financial settings:', err);
toast.error('خطا در بروزرسانی تنظیمات مالی');
@@ -75,29 +88,37 @@ export default function FinancialSettingsPage() {
const removeDonationOption = (amount: number) => {
setFinancial({
...financial,
charityDonationOptions: financial.charityDonationOptions.filter(a => a !== amount),
charityDonationOptions: financial.charityDonationOptions.filter((a) => a !== amount),
});
};
return (
<div className="space-y-6">
<div className="space-y-6 font-vazir" dir="rtl">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
<DollarSign className="w-6 h-6 text-purple-600" />
تنظیمات مالی و ارسال (Financial & Shipping Settings)
<DollarSign className="w-6 h-6 text-emerald-600" />
تنظیمات مالی، مالیات و خیریه (Financial Settings)
</h2>
<p className="text-gray-500 font-medium mt-1">تنظیم درصد مالیات، آستانه ارسال رایگان و گزینه‌های کمک به خیریه</p>
<p className="text-gray-500 font-medium mt-1">
تعیین درصد مالیات بر ارزش افزوده، کمک‌های خیریه ردپای مهربانی و تسویه‌حساب کیف پول
</p>
</div>
</div>
{isLoading ? (
<div className="flex justify-center p-12"><Spinner size="lg" className="text-purple-600" /></div>
<div className="flex justify-center p-12">
<Spinner size="lg" className="text-emerald-600" />
</div>
) : (
<form onSubmit={handleSave} className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-6">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
{/* Tax Percentage */}
<div>
<label className="block text-sm font-bold text-gray-700 mb-1">درصد مالیات ارزش افزوده (taxPercentage) *</label>
<label className="block text-sm font-bold text-gray-700 mb-1.5 flex items-center gap-1.5">
<Percent className="w-4 h-4 text-emerald-600" />
<span>درصد مالیات بر ارزش افزوده (VAT) *</span>
</label>
<div className="relative">
<input
required
@@ -106,36 +127,35 @@ export default function FinancialSettingsPage() {
max="100"
value={financial.taxPercentage}
onChange={(e) => setFinancial({ ...financial, taxPercentage: Number(e.target.value) })}
className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500 outline-none font-bold text-sm"
className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-emerald-500 outline-none font-bold text-sm"
dir="ltr"
/>
<span className="absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 font-bold">%</span>
</div>
<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">هزینه ارسال استاندارد (standardShippingFee) *</label>
<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
required
value={financial.standardShippingFee}
onChange={(val) => setFinancial({ ...financial, standardShippingFee: Number(val) })}
className="px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500 text-sm"
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>
</div>
<div className="md:col-span-2">
<label className="block text-sm font-bold text-gray-700 mb-1">آستانه ارسال رایگان (freeShippingThreshold) *</label>
<PriceInput
required
value={financial.freeShippingThreshold}
onChange={(val) => setFinancial({ ...financial, freeShippingThreshold: Number(val) })}
className="px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500 text-sm"
/>
<p className="text-xs text-gray-500 mt-1">سبدهای خرید با مبلغ بالاتر از این مقدار، ارسال رایگان خواهند داشت.</p>
</div>
<div className="md:col-span-2 space-y-2">
<label className="block text-sm font-bold text-gray-700 mb-1">گزینه‌های کمک به خیریه ردپای مهربانی (charityDonationOptions)</label>
{/* 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="مبلغ جدید (مثال: ۱۰۰,۰۰۰)"
@@ -146,17 +166,24 @@ export default function FinancialSettingsPage() {
<button
type="button"
onClick={addDonationOption}
className="px-4 py-2 bg-purple-600 hover:bg-purple-700 text-white rounded-xl text-xs font-bold flex items-center gap-1 shrink-0"
className="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white rounded-xl text-xs font-bold flex items-center gap-1 shrink-0 cursor-pointer"
>
<Plus className="w-4 h-4" /> افزودن
</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-purple-50 text-purple-700 text-xs font-bold rounded-xl border border-purple-200">
{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"
>
{amount.toLocaleString('fa-IR')} تومان
<button type="button" onClick={() => removeDonationOption(amount)} className="hover:text-red-500">
<button
type="button"
onClick={() => removeDonationOption(amount)}
className="hover:text-red-500 cursor-pointer"
>
<X className="w-3.5 h-3.5" />
</button>
</span>
@@ -166,16 +193,21 @@ export default function FinancialSettingsPage() {
{/* Wallet Withdrawal Feature Toggle */}
<div className="md:col-span-2 pt-4 border-t border-gray-100">
<label className="flex items-center gap-3 cursor-pointer p-4 bg-purple-50/50 hover:bg-purple-50 rounded-2xl border border-purple-100 transition-colors">
<label className="flex items-center gap-3 cursor-pointer p-4 bg-emerald-50/50 hover:bg-emerald-50 rounded-2xl border border-emerald-100 transition-colors">
<input
type="checkbox"
checked={Boolean(financial.walletWithdrawalEnabled)}
onChange={(e) => setFinancial({ ...financial, walletWithdrawalEnabled: e.target.checked })}
className="w-5 h-5 rounded-lg text-purple-600 focus:ring-purple-500 border-gray-300 cursor-pointer"
className="w-5 h-5 rounded-lg text-emerald-600 focus:ring-emerald-500 border-gray-300 cursor-pointer"
/>
<div>
<span className="text-sm font-black text-gray-900 block">فعال‌سازی امکان ثبت درخواست برداشت و تسویه‌حساب کیف پول (wallet_withdrawal_enabled)</span>
<span className="text-xs text-gray-500 font-medium block mt-0.5">در صورت فعال بودن، کاربران می‌توانند از طریق داشبورد خود درخواست تسویه و واریز وجه به شماره شبا ثبت کنند.</span>
<span className="text-sm font-black text-gray-900 block flex items-center gap-2">
<Wallet className="w-4 h-4 text-emerald-600" />
فعال‌سازی امکان ثبت درخواست برداشت و تسویه‌حساب کیف پول
</span>
<span className="text-xs text-gray-500 font-medium block mt-0.5">
در صورت فعال بودن، کاربران می‌توانند از طریق داشبورد خود درخواست تسویه و واریز وجه کیف پول به شماره شبا ثبت کنند.
</span>
</div>
</label>
</div>
@@ -185,7 +217,7 @@ export default function FinancialSettingsPage() {
<button
type="submit"
disabled={isSaving}
className="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-8 rounded-xl transition-colors flex items-center gap-2 shadow-md shadow-purple-200"
className="bg-emerald-600 hover:bg-emerald-700 text-white font-bold py-3 px-8 rounded-xl transition-colors flex items-center gap-2 shadow-md shadow-emerald-200 cursor-pointer"
>
{isSaving ? <Spinner size="sm" /> : <Save className="w-5 h-5" />}
ذخیره تنظیمات مالی
@@ -0,0 +1,270 @@
import { useState, useEffect } from 'react';
import { CreditCard, Save, ShieldCheck, Wallet, ArrowLeftRight, CheckCircle2 } from 'lucide-react';
import { toast } from 'react-hot-toast';
import api from '../services/api';
import Spinner from '../components/ui/Spinner';
export default function PaymentGatewaysPage() {
const [settings, setSettings] = useState({
PAY_GATEWAY_CARD_ENABLE: 'true',
PAY_GATEWAY_WALLET_ENABLE: 'true',
PAY_GATEWAY_ONLINE_ENABLE: 'true',
PAY_GATEWAY_COD_ENABLE: 'false',
ZIBAL_MERCHANT: 'zibal',
ZIBAL_SANDBOX: 'true',
FRONTEND_URL: 'https://canina.ir',
});
const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
useEffect(() => {
let isSubscribed = true;
api.get('/admin/settings')
.then((res) => {
if (!isSubscribed) return;
if (res.data?.success) {
const d = res.data.data;
setSettings({
PAY_GATEWAY_CARD_ENABLE: d.PAY_GATEWAY_CARD_ENABLE ?? 'true',
PAY_GATEWAY_WALLET_ENABLE: d.PAY_GATEWAY_WALLET_ENABLE ?? 'true',
PAY_GATEWAY_ONLINE_ENABLE: d.PAY_GATEWAY_ONLINE_ENABLE ?? 'true',
PAY_GATEWAY_COD_ENABLE: d.PAY_GATEWAY_COD_ENABLE ?? 'false',
ZIBAL_MERCHANT: d.ZIBAL_MERCHANT || 'zibal',
ZIBAL_SANDBOX: d.ZIBAL_SANDBOX ?? 'true',
FRONTEND_URL: d.FRONTEND_URL || 'https://canina.ir',
});
}
})
.catch((err) => {
console.error('Failed to fetch payment settings', err);
})
.finally(() => {
if (isSubscribed) setIsLoading(false);
});
return () => {
isSubscribed = false;
};
}, []);
const handleSave = async (e: React.FormEvent) => {
e.preventDefault();
try {
setIsSaving(true);
await api.put('/admin/settings', settings);
toast.success('تنظیمات روش‌های پرداخت با موفقیت بروزرسانی شد.');
} catch (err) {
console.error('Failed to update payment settings', err);
toast.error('خطا در ذخیره تنظیمات درگاه پرداخت');
} finally {
setIsSaving(false);
}
};
return (
<div className="space-y-6 font-vazir" dir="rtl">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
<CreditCard className="w-6 h-6 text-indigo-600" />
مدیریت روش‌های پرداخت و درگاه بانکی
</h2>
<p className="text-gray-500 font-medium mt-1">
پیکربندی پایانه‌های پرداخت اینترنتی زیبال، کیف پول داخلی، کارت به کارت و پرداخت در محل
</p>
</div>
</div>
{isLoading ? (
<div className="flex justify-center p-12">
<Spinner size="lg" className="text-indigo-600" />
</div>
) : (
<form onSubmit={handleSave} className="space-y-6">
{/* Methods Cards */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-6">
<h3 className="text-base font-black text-gray-900 border-b border-gray-100 pb-3 flex items-center gap-2">
<ShieldCheck className="w-5 h-5 text-indigo-600" />
وضعیت فعال بودن روش‌های پرداخت در تسویه‌حساب
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Zibal IPG */}
<div className="flex items-center justify-between p-4 bg-indigo-50/50 rounded-2xl border border-indigo-100">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-indigo-600 text-white flex items-center justify-center font-black">
Z
</div>
<div>
<h4 className="font-bold text-gray-900 text-sm">درگاه آنلاین شتاب (زیبال)</h4>
<p className="text-xs text-gray-500 mt-0.5">پرداخت اینترنتی کلیه کارت‌های عضو شتاب</p>
</div>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={settings.PAY_GATEWAY_ONLINE_ENABLE === 'true'}
onChange={(e) =>
setSettings({
...settings,
PAY_GATEWAY_ONLINE_ENABLE: e.target.checked ? 'true' : 'false',
})
}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
{/* Wallet Internal */}
<div className="flex items-center justify-between p-4 bg-blue-50/50 rounded-2xl border border-blue-100">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-blue-600 text-white flex items-center justify-center font-black">
<Wallet className="w-5 h-5" />
</div>
<div>
<h4 className="font-bold text-gray-900 text-sm">اعتبار کیف پول کنینا</h4>
<p className="text-xs text-gray-500 mt-0.5">پرداخت لحظه‌ای از موجودی شارژشده کاربر</p>
</div>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={settings.PAY_GATEWAY_WALLET_ENABLE === 'true'}
onChange={(e) =>
setSettings({
...settings,
PAY_GATEWAY_WALLET_ENABLE: e.target.checked ? 'true' : 'false',
})
}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-600"></div>
</label>
</div>
{/* Card to Card */}
<div className="flex items-center justify-between p-4 bg-slate-50 rounded-2xl border border-gray-200">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-slate-700 text-white flex items-center justify-center font-black">
<ArrowLeftRight className="w-5 h-5" />
</div>
<div>
<h4 className="font-bold text-gray-900 text-sm">کارت به کارت (واریز مستقیم)</h4>
<p className="text-xs text-gray-500 mt-0.5">واریز به شماره شبا / کارت رسمی و ثبت فیش</p>
</div>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={settings.PAY_GATEWAY_CARD_ENABLE === 'true'}
onChange={(e) =>
setSettings({
...settings,
PAY_GATEWAY_CARD_ENABLE: e.target.checked ? 'true' : 'false',
})
}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-slate-700"></div>
</label>
</div>
{/* Cash On Delivery */}
<div className="flex items-center justify-between p-4 bg-amber-50/50 rounded-2xl border border-amber-100">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-amber-600 text-white flex items-center justify-center font-black">
<CreditCard className="w-5 h-5" />
</div>
<div>
<h4 className="font-bold text-gray-900 text-sm">پرداخت در محل (COD)</h4>
<p className="text-xs text-gray-500 mt-0.5">پرداخت با پوز هنگام دریافت سفارش</p>
</div>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={settings.PAY_GATEWAY_COD_ENABLE === 'true'}
onChange={(e) =>
setSettings({
...settings,
PAY_GATEWAY_COD_ENABLE: e.target.checked ? 'true' : 'false',
})
}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-600"></div>
</label>
</div>
</div>
</div>
{/* Zibal Configuration Card */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-5">
<div className="flex items-center justify-between border-b border-gray-100 pb-3">
<h3 className="text-base font-black text-gray-900 flex items-center gap-2">
<ShieldCheck className="w-5 h-5 text-indigo-600" />
پیکربندی پایانه پرداخت زیبال (Zibal IPG Config)
</h3>
{settings.ZIBAL_MERCHANT === 'zibal' && (
<span className="bg-amber-100 text-amber-800 text-xs px-3 py-1 rounded-xl font-bold flex items-center gap-1">
<CheckCircle2 className="w-3.5 h-3.5" />
حالت آزمایشی (Sandbox)
</span>
)}
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-5">
<div>
<label className="block text-xs font-bold text-gray-700 mb-1.5">
کد مرچنت زیبال (Merchant ID) *
</label>
<input
type="text"
required
value={settings.ZIBAL_MERCHANT}
onChange={(e) => setSettings({ ...settings, ZIBAL_MERCHANT: e.target.value })}
placeholder="zibal یا کد مرچنت دریافتی"
className="w-full border border-gray-200 rounded-xl p-3 outline-none focus:ring-2 focus:ring-indigo-500 text-xs font-mono font-bold"
dir="ltr"
/>
<p className="text-[11px] text-gray-400 mt-1">
جهت فعال‌سازی درگاه زنده، مرچنت آی‌دی رسمی زیبال را در این کادر قرار دهید.
</p>
</div>
<div>
<label className="block text-xs font-bold text-gray-700 mb-1.5">
دامنه بازگشت پس از پرداخت (Frontend Return Domain) *
</label>
<input
type="text"
required
value={settings.FRONTEND_URL}
onChange={(e) => setSettings({ ...settings, FRONTEND_URL: e.target.value })}
placeholder="https://canina.ir"
className="w-full border border-gray-200 rounded-xl p-3 outline-none focus:ring-2 focus:ring-indigo-500 text-xs font-mono font-bold"
dir="ltr"
/>
<p className="text-[11px] text-gray-400 mt-1">
آدرس صفحه‌ای که نتیجه تراکنش به آن ارجاع داده می‌شود.
</p>
</div>
</div>
</div>
<div className="flex justify-end">
<button
type="submit"
disabled={isSaving}
className="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-8 rounded-xl transition-colors flex items-center gap-2 shadow-md shadow-indigo-200 cursor-pointer"
>
{isSaving ? <Spinner size="sm" /> : <Save className="w-5 h-5" />}
<span>ذخیره تغییرات روش‌های پرداخت</span>
</button>
</div>
</form>
)}
</div>
);
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,164 @@
import { useState, useEffect } from 'react';
import { Truck, Save, Gift, ShieldAlert } from 'lucide-react';
import { toast } from 'react-hot-toast';
import api from '../services/api';
import Spinner from '../components/ui/Spinner';
import PriceInput from '../components/ui/PriceInput';
export default function ShippingSettingsPage() {
const [shipping, setShipping] = useState({
SHIPPING_FEE: '85000',
FREE_SHIPPING_THRESHOLD: '2000000',
MIN_ORDER_AMOUNT: '0',
shipping_notice:
'ارسال رایگان برای سفارش‌های بالای ۱۵۰ هزار تومان — گارانتی اصالت کنینا آلمان — مشاوره تخصصی مکمل‌های دارویی سگ و گربه با کادر دامپزشکان مجرب',
});
const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
useEffect(() => {
let isSubscribed = true;
api.get('/admin/settings')
.then((res) => {
if (!isSubscribed) return;
if (res.data?.success) {
const d = res.data.data;
setShipping({
SHIPPING_FEE: String(d.SHIPPING_FEE || d.shipping_fee || d.standardShippingFee || '85000'),
FREE_SHIPPING_THRESHOLD: String(d.FREE_SHIPPING_THRESHOLD || d.free_shipping_threshold || d.freeShippingThreshold || '2000000'),
MIN_ORDER_AMOUNT: String(d.MIN_ORDER_AMOUNT || d.min_order_amount || d.minOrderAmount || '0'),
shipping_notice: d.shipping_notice || d.SHIPPING_NOTICE || 'ارسال رایگان برای سفارش‌های بالای ۱۵۰ هزار تومان — گارانتی اصالت کنینا آلمان',
});
}
})
.catch((err) => {
console.error('Failed to fetch shipping settings', err);
})
.finally(() => {
if (isSubscribed) setIsLoading(false);
});
return () => {
isSubscribed = false;
};
}, []);
const handleSave = async (e: React.FormEvent) => {
e.preventDefault();
try {
setIsSaving(true);
await api.put('/admin/settings', shipping);
toast.success('تنظیمات ارسال و کرایه حمل با موفقیت بروزرسانی شد.');
} catch (err) {
console.error('Failed to update shipping settings:', err);
toast.error('خطا در ذخیره تنظیمات ارسال');
} finally {
setIsSaving(false);
}
};
return (
<div className="space-y-6 font-vazir" dir="rtl">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
<Truck className="w-6 h-6 text-blue-600" />
تنظیمات ارسال و کرایه حمل (Shipping & Delivery)
</h2>
<p className="text-gray-500 font-medium mt-1">
تعیین هزینه پایه پست، آستانه ارسال رایگان، حداقل مجاز مبلغ سفارش و نوار اعلان تحویل
</p>
</div>
</div>
{isLoading ? (
<div className="flex justify-center p-12">
<Spinner size="lg" className="text-blue-600" />
</div>
) : (
<form onSubmit={handleSave} className="space-y-6">
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-6">
<h3 className="text-base font-black text-gray-900 border-b border-gray-100 pb-3 flex items-center gap-2">
<Truck className="w-5 h-5 text-blue-600" />
قوانین هزینه و کرایه ارسال
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">
هزینه ثابت ارسال (تومان) *
</label>
<PriceInput
value={shipping.SHIPPING_FEE}
onChange={(val) => setShipping({ ...shipping, SHIPPING_FEE: val })}
placeholder="مثال: ۸۵,۰۰۰"
className="border border-gray-200 rounded-xl p-3 focus:ring-2 focus:ring-blue-500"
/>
<p className="text-xs text-gray-500 mt-1.5 font-medium">
هزینه استاندارد پستی که برای سفارش‌های عادی منظور می‌شود.
</p>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">
آستانه ارسال رایگان (تومان) *
</label>
<PriceInput
value={shipping.FREE_SHIPPING_THRESHOLD}
onChange={(val) => setShipping({ ...shipping, FREE_SHIPPING_THRESHOLD: val })}
placeholder="مثال: ۲,۰۰۰,۰۰۰"
className="border border-gray-200 rounded-xl p-3 focus:ring-2 focus:ring-blue-500"
/>
<p className="text-xs text-gray-500 mt-1.5 font-medium">
سفارش‌های با جمع مبلغ بالاتر از این عدد، به طور خودکار رایگان ارسال می‌شوند.
</p>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">
حداقل مبلغ سفارش مجاز (تومان)
</label>
<PriceInput
value={shipping.MIN_ORDER_AMOUNT}
onChange={(val) => setShipping({ ...shipping, MIN_ORDER_AMOUNT: val })}
placeholder="۰ = بدون محدودیت"
className="border border-gray-200 rounded-xl p-3 focus:ring-2 focus:ring-blue-500"
/>
<p className="text-xs text-gray-500 mt-1.5 font-medium">
سفارشات کمتر از این عدد اجازه ورود به درگاه را نخواهند داشت (۰ برای لغو شرط).
</p>
</div>
<div className="md:col-span-2">
<label className="block text-sm font-bold text-gray-700 mb-2">
متن نوار متحرک اعلان بالای سایت (Ticker Announcement)
</label>
<textarea
rows={2}
value={shipping.shipping_notice}
onChange={(e) => setShipping({ ...shipping, shipping_notice: e.target.value })}
placeholder="ارسال رایگان برای سفارش‌های بالای ۱۵۰ هزار تومان — ..."
className="w-full border border-gray-200 rounded-xl p-3 outline-none focus:ring-2 focus:ring-blue-500 text-xs font-bold bg-amber-50/40"
/>
<p className="text-xs text-gray-500 mt-1 font-medium">
این متن در نوار زرد متحرک بالای تمام صفحات سایت نمایش داده می‌شود.
</p>
</div>
</div>
</div>
<div className="flex justify-end">
<button
type="submit"
disabled={isSaving}
className="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-8 rounded-xl transition-colors flex items-center gap-2 shadow-md shadow-blue-200 cursor-pointer"
>
{isSaving ? <Spinner size="sm" /> : <Save className="w-5 h-5" />}
<span>ذخیره تغییرات ارسال</span>
</button>
</div>
</form>
)}
</div>
);
}
@@ -1,5 +1,16 @@
import { useState, useEffect } from 'react';
import { Sliders, Save, AlertTriangle } from 'lucide-react';
import { Link } from 'react-router-dom';
import {
Sliders,
Save,
AlertTriangle,
ShieldAlert,
MessageSquare,
BookOpen,
ShoppingBag,
Info,
CheckCircle2,
} from 'lucide-react';
import { toast } from 'react-hot-toast';
import api from '../services/api';
import Spinner from '../components/ui/Spinner';
@@ -12,26 +23,49 @@ export default function SystemSettingsPage() {
b2bRegistrationOpen: true,
supportPhone: '021-12345678',
});
const [catalogSettings, setCatalogSettings] = useState({
CATALOG_ONLY_MODE: 'false',
CATALOG_SHOW_PRICES: 'true',
CATALOG_ALLOW_CART: 'false',
CATALOG_ALLOW_CHECKOUT: 'false',
CATALOG_PREORDER_BTN: 'false',
});
const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
useEffect(() => {
let isSubscribed = true;
api.get('/settings/system')
.then(res => {
Promise.all([
api.get('/settings/system'),
api.get('/admin/settings'),
])
.then(([resSys, resAdmin]) => {
if (!isSubscribed) return;
const data = res.data?.data || res.data;
const data = resSys.data?.data || resSys.data;
if (data) {
setSystem(prev => ({
setSystem((prev) => ({
maintenanceMode: Boolean(data.maintenanceMode),
allowGuestCheckout: Boolean(data.allowGuestCheckout ?? true),
b2bRegistrationOpen: Boolean(data.b2bRegistrationOpen ?? true),
supportPhone: data.supportPhone || prev.supportPhone,
}));
}
if (resAdmin.data?.success) {
const d = resAdmin.data.data;
setCatalogSettings({
CATALOG_ONLY_MODE: d.CATALOG_ONLY_MODE || 'false',
CATALOG_SHOW_PRICES: d.CATALOG_SHOW_PRICES || 'true',
CATALOG_ALLOW_CART: d.CATALOG_ALLOW_CART || 'false',
CATALOG_ALLOW_CHECKOUT: d.CATALOG_ALLOW_CHECKOUT || 'false',
CATALOG_PREORDER_BTN: d.CATALOG_PREORDER_BTN || 'false',
});
}
})
.catch(err => {
console.warn('Failed to fetch System settings, using default state', err);
.catch((err) => {
console.warn('Failed to fetch system/catalog settings', err);
})
.finally(() => {
if (isSubscribed) setIsLoading(false);
@@ -45,8 +79,14 @@ export default function SystemSettingsPage() {
e.preventDefault();
try {
setIsSaving(true);
await api.patch('/settings/system', system);
toast.success('تنظیمات سیستمی با موفقیت بروزرسانی شد');
await Promise.all([
api.patch('/settings/system', system),
api.put('/admin/settings', {
MAINTENANCE_MODE: system.maintenanceMode ? 'true' : 'false',
...catalogSettings,
}),
]);
toast.success('تنظیمات سیستمی و حالت‌های فروشگاه با موفقیت ذخیره شد.');
} catch (err) {
console.error('Failed to update system settings:', err);
toast.error('خطا در بروزرسانی تنظیمات سیستمی');
@@ -56,29 +96,61 @@ export default function SystemSettingsPage() {
};
return (
<div className="space-y-6">
<div className="space-y-6 font-vazir" dir="rtl">
{/* Top Header with Quick Security and SMS links */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
<Sliders className="w-6 h-6 text-purple-600" />
تنظیمات سیستمی و کنترل حالت‌ها (System Settings)
تنظیمات سیستمی پیشرفته و کنترل دسترسی
</h2>
<p className="text-gray-500 font-medium mt-1">مدیریت حالت تعمیرات، خرید مهمان و ثبت‌نام همکاران B2B</p>
<p className="text-gray-500 font-medium mt-1">
مدیریت وضعیت صیانت و تعمیرات، کنترل کاتالوگ‌مود، خرید مهمان و ابزارهای امنیتی
</p>
</div>
{/* Action buttons for SSL and SMS as requested */}
<div className="flex items-center gap-2.5 flex-wrap">
<Link
to="/settings/ssl"
className="bg-emerald-50 text-emerald-700 hover:bg-emerald-100 border border-emerald-200 text-xs font-black px-4 py-2.5 rounded-xl transition-all flex items-center gap-2 shadow-xs"
>
<ShieldAlert className="w-4 h-4 text-emerald-600" />
<span>مدیریت گواهی SSL و امنیت</span>
</Link>
<Link
to="/settings/sms"
className="bg-purple-50 text-purple-700 hover:bg-purple-100 border border-purple-200 text-xs font-black px-4 py-2.5 rounded-xl transition-all flex items-center gap-2 shadow-xs"
>
<MessageSquare className="w-4 h-4 text-purple-600" />
<span>تنظیمات درگاه پیامک (MeliPayamak)</span>
</Link>
</div>
</div>
{isLoading ? (
<div className="flex justify-center p-12"><Spinner size="lg" className="text-purple-600" /></div>
<div className="flex justify-center p-12">
<Spinner size="lg" className="text-purple-600" />
</div>
) : (
<form onSubmit={handleSave} className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-6">
<div className="space-y-4">
{/* Maintenance Mode */}
<div className="flex items-center justify-between p-4 bg-amber-50/60 rounded-xl border border-amber-200">
<form onSubmit={handleSave} className="space-y-6">
{/* Maintenance Mode Card */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-4">
<h3 className="text-base font-black text-gray-900 border-b border-gray-100 pb-3 flex items-center gap-2">
<AlertTriangle className="w-5 h-5 text-amber-500" />
حالت تعمیرات و صیانت موقت سایت (Maintenance Mode)
</h3>
<div className="flex items-center justify-between p-4 bg-amber-50/70 rounded-2xl border border-amber-200">
<div className="flex items-center gap-3">
<AlertTriangle className="w-6 h-6 text-amber-600" />
<div className="w-10 h-10 rounded-xl bg-amber-500 text-white flex items-center justify-center font-black">
<AlertTriangle className="w-5 h-5" />
</div>
<div>
<h4 className="font-bold text-gray-900 text-sm">حالت تعمیرات (maintenanceMode)</h4>
<p className="text-xs text-gray-600 mt-0.5">غیرفعال‌سازی موقت فرانت‌اند جهت بروزرسانی دیتابیس یا سرور</p>
<h4 className="font-bold text-gray-900 text-sm">فعال‌سازی حالت تعمیرات</h4>
<p className="text-xs text-gray-600 mt-0.5">
با فعال کردن این گزینه، فرانت‌اند سایت برای کاربران قفل شده و صفحه «در حال بروزرسانی» نمایش داده می‌شود.
</p>
</div>
</div>
<label className="relative inline-flex items-center cursor-pointer">
@@ -88,66 +160,177 @@ export default function SystemSettingsPage() {
checked={system.maintenanceMode}
onChange={(e) => setSystem({ ...system, maintenanceMode: e.target.checked })}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-600"></div>
<div className="w-12 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500"></div>
</label>
</div>
{/* Guest Checkout */}
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-xl border border-gray-200">
<div>
<h4 className="font-bold text-gray-900 text-sm">اجازه خرید کاربر مهمان (allowGuestCheckout)</h4>
<p className="text-xs text-gray-500 mt-0.5">امکان تسویه‌حساب سریع بدون نیاز به ایجاد حساب کاربری قبل از ثبت سفارش</p>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={system.allowGuestCheckout}
onChange={(e) => setSystem({ ...system, allowGuestCheckout: e.target.checked })}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-purple-600"></div>
</label>
</div>
{/* B2B Registration Open */}
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-xl border border-gray-200">
<div>
<h4 className="font-bold text-gray-900 text-sm">ثبت‌نام متقاضیان همکار باز است (b2bRegistrationOpen)</h4>
<p className="text-xs text-gray-500 mt-0.5">فعال بودن فرم پذیرش درخواست‌های جدید عمده‌فروشی در سایت</p>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={system.b2bRegistrationOpen}
onChange={(e) => setSystem({ ...system, b2bRegistrationOpen: e.target.checked })}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-purple-600"></div>
</label>
</div>
{/* Support Phone */}
<div>
<label className="block text-sm font-bold text-gray-700 mb-1">شماره تلفن پشتیبانی اصلی (supportPhone) *</label>
<input
required
type="text"
value={system.supportPhone}
onChange={(e) => setSystem({ ...system, supportPhone: e.target.value })}
className="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-sm font-bold"
dir="ltr"
/>
</div>
</div>
<div className="flex justify-end pt-4 border-t border-gray-100">
{/* Catalog Only Mode Card */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-4">
<h3 className="text-base font-black text-gray-900 border-b border-gray-100 pb-3 flex items-center gap-2">
<BookOpen className="w-5 h-5 text-purple-600" />
حالت کاتالوگ آنلاین بدون فروش مستقیم (Catalog Only Mode)
</h3>
<div className="p-4 bg-purple-50/60 rounded-2xl border border-purple-100 space-y-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-purple-600 text-white flex items-center justify-center font-black">
<BookOpen className="w-5 h-5" />
</div>
<div>
<h4 className="font-bold text-gray-900 text-sm">فعال‌سازی حالت کاتالوگ</h4>
<p className="text-xs text-gray-600 mt-0.5">
مناسب برای زمانی که قصد دارید محصولات را صرفاً به عنوان دایرکتوری و مشخصات فنی معرفی کنید.
</p>
</div>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={catalogSettings.CATALOG_ONLY_MODE === 'true'}
onChange={(e) =>
setCatalogSettings({
...catalogSettings,
CATALOG_ONLY_MODE: e.target.checked ? 'true' : 'false',
})
}
/>
<div className="w-12 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-purple-600"></div>
</label>
</div>
{catalogSettings.CATALOG_ONLY_MODE === 'true' && (
<div className="pt-4 border-t border-purple-200/60 grid grid-cols-1 md:grid-cols-2 gap-3 text-xs">
<label className="flex items-center gap-2.5 font-bold text-gray-800 p-2.5 bg-white rounded-xl border border-purple-100 cursor-pointer">
<input
type="checkbox"
checked={catalogSettings.CATALOG_SHOW_PRICES === 'true'}
onChange={(e) =>
setCatalogSettings({
...catalogSettings,
CATALOG_SHOW_PRICES: e.target.checked ? 'true' : 'false',
})
}
className="w-4 h-4 rounded text-purple-600 focus:ring-purple-500"
/>
<span>نمایش قیمت محصولات در حالت کاتالوگ</span>
</label>
<label className="flex items-center gap-2.5 font-bold text-gray-800 p-2.5 bg-white rounded-xl border border-purple-100 cursor-pointer">
<input
type="checkbox"
checked={catalogSettings.CATALOG_ALLOW_CART === 'true'}
onChange={(e) =>
setCatalogSettings({
...catalogSettings,
CATALOG_ALLOW_CART: e.target.checked ? 'true' : 'false',
})
}
className="w-4 h-4 rounded text-purple-600 focus:ring-purple-500"
/>
<span>امکان افزودن به سبد خرید</span>
</label>
<label className="flex items-center gap-2.5 font-bold text-gray-800 p-2.5 bg-white rounded-xl border border-purple-100 cursor-pointer">
<input
type="checkbox"
checked={catalogSettings.CATALOG_ALLOW_CHECKOUT === 'true'}
onChange={(e) =>
setCatalogSettings({
...catalogSettings,
CATALOG_ALLOW_CHECKOUT: e.target.checked ? 'true' : 'false',
})
}
className="w-4 h-4 rounded text-purple-600 focus:ring-purple-500"
/>
<span>امکان ورود به صفحه تسویه‌حساب (ثبت فاکتور)</span>
</label>
<label className="flex items-center gap-2.5 font-bold text-gray-800 p-2.5 bg-white rounded-xl border border-purple-100 cursor-pointer">
<input
type="checkbox"
checked={catalogSettings.CATALOG_PREORDER_BTN === 'true'}
onChange={(e) =>
setCatalogSettings({
...catalogSettings,
CATALOG_PREORDER_BTN: e.target.checked ? 'true' : 'false',
})
}
className="w-4 h-4 rounded text-purple-600 focus:ring-purple-500"
/>
<span>نمایش دکمه «ثبت پیش‌خرید» به جای خرید مستقیم</span>
</label>
</div>
)}
</div>
</div>
{/* User & B2B System Rules */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-200 space-y-4">
<h3 className="text-base font-black text-gray-900 border-b border-gray-100 pb-3 flex items-center gap-2">
<ShoppingBag className="w-5 h-5 text-slate-700" />
قوانین خرید مهمان و ثبت‌نام متقاضیان همکار
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-2xl border border-gray-200">
<div>
<h4 className="font-bold text-gray-900 text-sm">اجازه خرید کاربر مهمان</h4>
<p className="text-xs text-gray-500 mt-0.5">تسویه‌حساب بدون نیاز به ساخت حساب کاربری قبلی</p>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={system.allowGuestCheckout}
onChange={(e) => setSystem({ ...system, allowGuestCheckout: e.target.checked })}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-purple-600"></div>
</label>
</div>
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-2xl border border-gray-200">
<div>
<h4 className="font-bold text-gray-900 text-sm">فرم ثبت‌نام همکاران B2B باز است</h4>
<p className="text-xs text-gray-500 mt-0.5">امکان ارسال درخواست نمایندگی جدید در سایت</p>
</div>
<label className="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
className="sr-only peer"
checked={system.b2bRegistrationOpen}
onChange={(e) => setSystem({ ...system, b2bRegistrationOpen: e.target.checked })}
/>
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-purple-600"></div>
</label>
</div>
<div className="md:col-span-2">
<label className="block text-sm font-bold text-gray-700 mb-1">
شماره تماس پشتیبانی اضطراری (در زمان تعمیرات)
</label>
<input
required
type="text"
value={system.supportPhone}
onChange={(e) => setSystem({ ...system, supportPhone: e.target.value })}
className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:border-purple-500 outline-none text-xs font-bold"
dir="ltr"
/>
</div>
</div>
</div>
<div className="flex justify-end">
<button
type="submit"
disabled={isSaving}
className="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-8 rounded-xl transition-colors flex items-center gap-2 shadow-md shadow-purple-200"
className="bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-8 rounded-xl transition-colors flex items-center gap-2 shadow-md shadow-purple-200 cursor-pointer"
>
{isSaving ? <Spinner size="sm" /> : <Save className="w-5 h-5" />}
ذخیره تنظیمات سیستمی
<span>ذخیره تنظیمات سیستمی</span>
</button>
</div>
</form>
File diff suppressed because it is too large. Load diff