feat(support-chat): add admin smart chat settings
This commit is contained in:
1 parent
fa4f1124e6
commit
b6735b5a9c
14 files changed
+285
-25
No files matched your search
@@ -114,6 +114,7 @@ export default function Settings() {
|
||||
};
|
||||
|
||||
const SETTING_MODULES = [
|
||||
{ title: 'پشتیبان هوشمند سایت', desc: 'فعالسازی، ارائهدهنده و مدل، نام دکمه و آیکون دستیار', path: '/settings/smart-chat', icon: MessageSquare, color: 'from-purple-600 to-purple-800', badge: 'هوشمند' },
|
||||
{
|
||||
title: 'روشهای پرداخت و زیبال',
|
||||
desc: 'درگاه آنلاین شتاب، کیف پول کنینا، کارت به کارت و پرداخت در محل',
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api from '../services/api';
|
||||
import Button from '../components/ui/Button';
|
||||
|
||||
type Settings = { enabled: boolean; provider: string; model: string; label: string; icon: string };
|
||||
type Provider = { id: string; label: string; models: string[] };
|
||||
const unwrap = (r: any) => r.data?.data ?? r.data;
|
||||
export default function SmartChatSettingsPage() {
|
||||
const [settings, setSettings] = useState<Settings | null>(null);
|
||||
const [providers, setProviders] = useState<Provider[]>([]);
|
||||
const [error, setError] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
const load = async () => {
|
||||
setError('');
|
||||
const [s, c] = await Promise.allSettled([api.get('/support-chat/settings'), api.get('/support-chat/catalog')]);
|
||||
if (s.status === 'fulfilled') setSettings(unwrap(s.value));
|
||||
else setError('تنظیمات ذخیرهشده دریافت نشد. پشتیبان تا ثبت تنظیمات معتبر نمایش داده نمیشود.');
|
||||
if (c.status === 'fulfilled') setProviders(unwrap(c.value).providers);
|
||||
else { setProviders([]); setError('فهرست واقعی ارائهدهندگان در دسترس نیست. لطفاً دوباره تلاش کنید.'); }
|
||||
};
|
||||
useEffect(() => { void load(); }, []);
|
||||
const save = async (event: React.FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (!settings) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
await api.put('/support-chat/settings', settings);
|
||||
const saved = unwrap(await api.get('/support-chat/settings'));
|
||||
setSettings(saved);
|
||||
setError('');
|
||||
toast.success('تنظیمات پشتیبان هوشمند ذخیره شد.');
|
||||
} catch { toast.error('ذخیره تنظیمات انجام نشد؛ ارائهدهنده و مدل را بررسی کنید.'); }
|
||||
finally { setSaving(false); }
|
||||
};
|
||||
const icons: Record<string, string> = { chat: '💬', paw: '🐾', bot: '🤖' };
|
||||
return <div dir="rtl" className="space-y-6 font-vazir">
|
||||
<Link to="/settings">← تنظیمات فروشگاه</Link>
|
||||
<h2 className="text-2xl font-black">پشتیبان هوشمند سایت</h2>
|
||||
<p>انتخاب مدل برای تشخیص درخواست و پاسخگویی یکسان است. اطلاعات حساب مشتری به مدل ارسال نمیشود.</p>
|
||||
{error && <div role="alert" className="rounded-xl bg-amber-50 p-4">{error} <button type="button" onClick={load}>تلاش دوباره</button></div>}
|
||||
{!settings ? <Button onClick={() => setSettings({ enabled: false, provider: '', model: '', label: '', icon: 'chat' })}>ایجاد تنظیمات جدید</Button> :
|
||||
<form onSubmit={save} className="space-y-5 rounded-2xl bg-white p-6 border border-gray-200">
|
||||
<label className="flex gap-2"><input type="checkbox" checked={settings.enabled} onChange={e => setSettings({ ...settings, enabled: e.target.checked })} />فعالسازی پشتیبان هوشمند</label>
|
||||
<label className="block">ارائهدهنده<select aria-label="ارائهدهنده" className="block border rounded-xl p-3 w-full" value={settings.provider} onChange={e => setSettings({ ...settings, provider: e.target.value, model: '' })}>
|
||||
<option value="">انتخاب ارائهدهنده</option>{providers.map(p => <option key={p.id} value={p.id}>{p.label}</option>)}
|
||||
</select></label>
|
||||
<label className="block">مدل<select aria-label="مدل" disabled={!settings.provider} className="block border rounded-xl p-3 w-full" value={settings.model} onChange={e => setSettings({ ...settings, model: e.target.value })}>
|
||||
<option value="">انتخاب مدل</option>{providers.find(p => p.id === settings.provider)?.models.map(m => <option key={m} value={m}>{m}</option>)}
|
||||
</select></label>
|
||||
<label className="block">نام دکمه و دستیار<input aria-label="نام دکمه و دستیار" required maxLength={60} className="block border rounded-xl p-3 w-full" value={settings.label} onChange={e => setSettings({ ...settings, label: e.target.value })} /></label>
|
||||
<label className="block">آیکون دستیار<select aria-label="آیکون دستیار" className="block border rounded-xl p-3 w-full" value={settings.icon} onChange={e => setSettings({ ...settings, icon: e.target.value })}><option value="chat">💬 گفتگو</option><option value="paw">🐾 پنجه</option><option value="bot">🤖 ربات</option></select></label>
|
||||
<p className="text-sm text-gray-500">برای امنیت سایت فقط آیکونهای داخلی قابل انتخاب هستند؛ نشانی یا SVG دلخواه پذیرفته نمیشود.</p>
|
||||
<div aria-label="پیشنمایش دکمه" className="inline-flex gap-2 rounded-full bg-[#1E4053] text-white px-4 py-3"><span>{icons[settings.icon]}</span><span>{settings.label}</span></div>
|
||||
<div><Button type="submit" disabled={saving || (settings.enabled && (!settings.provider || !settings.model))}>{saving ? 'در حال ذخیره…' : 'ذخیره تنظیمات'}</Button></div>
|
||||
</form>}
|
||||
</div>;
|
||||
}
|
||||
@@ -12,6 +12,7 @@ const Users = lazyWithRetry(() => import('../pages/Users'));
|
||||
const Products = lazyWithRetry(() => import('../pages/Products'));
|
||||
const Orders = lazyWithRetry(() => import('../pages/Orders'));
|
||||
const Coupons = lazyWithRetry(() => import('../pages/Coupons'));
|
||||
const SmartChatSettingsPage = lazyWithRetry(() => import('../pages/SmartChatSettingsPage'));
|
||||
const Settings = lazyWithRetry(() => import('../pages/Settings'));
|
||||
const Reports = lazyWithRetry(() => import('../pages/Reports'));
|
||||
const Categories = lazyWithRetry(() => import('../pages/Categories'));
|
||||
@@ -79,6 +80,7 @@ export const router = createBrowserRouter([
|
||||
{ path: 'zibal-portal/*', element: <ZibalPortalPage /> },
|
||||
{ path: 'coupons/*', element: <Coupons /> },
|
||||
{ path: 'settings', element: <Settings /> },
|
||||
{ path: 'settings/smart-chat', element: <SmartChatSettingsPage /> },
|
||||
{ path: 'settings/payment-methods', element: <PaymentGatewaysPage /> },
|
||||
{ path: 'settings/shipping', element: <ShippingSettingsPage /> },
|
||||
{ path: 'settings/ssl', element: <SslSettingsPage /> },
|
||||
|
||||
Reference in new issue
Block a user