From ead4606bb59e59c50445c7b7198abf42c54e1326 Mon Sep 17 00:00:00 2001 From: c0mrade Date: Mon, 2 Feb 2026 08:47:35 +0300 Subject: [PATCH] feat: move ticket settings to dedicated page --- src/App.tsx | 11 ++ src/locales/en.json | 2 + src/locales/fa.json | 2 + src/locales/ru.json | 2 + src/locales/zh.json | 2 + src/pages/AdminTicketSettings.tsx | 297 ++++++++++++++++++++++++++++++ src/pages/AdminTickets.tsx | 274 +-------------------------- 7 files changed, 320 insertions(+), 270 deletions(-) create mode 100644 src/pages/AdminTicketSettings.tsx diff --git a/src/App.tsx b/src/App.tsx index d86bd06..9fa8309 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -30,6 +30,7 @@ const Wheel = lazy(() => import('./pages/Wheel')); // Admin pages - lazy load (only for admins) const AdminPanel = lazy(() => import('./pages/AdminPanel')); const AdminTickets = lazy(() => import('./pages/AdminTickets')); +const AdminTicketSettings = lazy(() => import('./pages/AdminTicketSettings')); const AdminSettings = lazy(() => import('./pages/AdminSettings')); const AdminApps = lazy(() => import('./pages/AdminApps')); const AdminWheel = lazy(() => import('./pages/AdminWheel')); @@ -257,6 +258,16 @@ function App() { } /> + + + + + + } + /> ( + + + + +); + +export default function AdminTicketSettings() { + const { t } = useTranslation(); + const navigate = useNavigate(); + const queryClient = useQueryClient(); + + const { + data: settings, + isLoading, + error, + } = useQuery({ + queryKey: ['ticket-settings'], + queryFn: adminApi.getTicketSettings, + }); + + const [formData, setFormData] = useState({ + sla_enabled: true, + sla_minutes: 5, + sla_check_interval_seconds: 60, + sla_reminder_cooldown_minutes: 15, + support_system_mode: 'both', + cabinet_user_notifications_enabled: true, + cabinet_admin_notifications_enabled: true, + }); + + useEffect(() => { + if (settings) { + setFormData({ + sla_enabled: settings.sla_enabled, + sla_minutes: settings.sla_minutes, + sla_check_interval_seconds: settings.sla_check_interval_seconds, + sla_reminder_cooldown_minutes: settings.sla_reminder_cooldown_minutes, + support_system_mode: settings.support_system_mode, + cabinet_user_notifications_enabled: settings.cabinet_user_notifications_enabled ?? true, + cabinet_admin_notifications_enabled: settings.cabinet_admin_notifications_enabled ?? true, + }); + } + }, [settings]); + + const updateMutation = useMutation({ + mutationFn: adminApi.updateTicketSettings, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ['ticket-settings'] }); + navigate('/admin/tickets'); + }, + }); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + updateMutation.mutate(formData); + }; + + if (isLoading) { + return ( +
+
+
+ ); + } + + if (error) { + return ( +
+
+ +

{t('admin.tickets.settings')}

+
+
+

{t('admin.tickets.settingsLoadError')}

+ +
+
+ ); + } + + return ( +
+ {/* Header */} +
+ +
+ +
+
+

{t('admin.tickets.settings')}

+

{t('admin.tickets.settingsSubtitle')}

+
+
+ +
+ {/* Support System Mode */} +
+

+ {t('admin.tickets.supportMode')} +

+ +

{t('admin.tickets.supportModeDesc')}

+
+ + {/* Cabinet Notifications */} +
+

+ {t('admin.tickets.cabinetNotifications')} +

+ + {/* User Notifications */} +
+ +
+ + {/* Admin Notifications */} +
+ +
+
+ + {/* SLA Settings */} +
+

+ {t('admin.tickets.slaSettings')} +

+ + {/* SLA Enabled */} +
+ +
+ + {/* SLA Minutes */} +
+ + setFormData({ ...formData, sla_minutes: parseInt(e.target.value) })} + className="input" + disabled={!formData.sla_enabled} + /> +

{t('admin.tickets.slaMinutesDesc')}

+
+ + {/* Check Interval */} +
+ + + setFormData({ ...formData, sla_check_interval_seconds: parseInt(e.target.value) }) + } + className="input" + disabled={!formData.sla_enabled} + /> +

{t('admin.tickets.checkIntervalDesc')}

+
+ + {/* Reminder Cooldown */} +
+ + + setFormData({ + ...formData, + sla_reminder_cooldown_minutes: parseInt(e.target.value), + }) + } + className="input" + disabled={!formData.sla_enabled} + /> +

{t('admin.tickets.reminderCooldownDesc')}

+
+
+ + {/* Buttons */} +
+ + +
+ + {updateMutation.isError && ( +
+ {t('admin.tickets.settingsUpdateError')} +
+ )} +
+
+ ); +} diff --git a/src/pages/AdminTickets.tsx b/src/pages/AdminTickets.tsx index 3898cc1..6a8dce6 100644 --- a/src/pages/AdminTickets.tsx +++ b/src/pages/AdminTickets.tsx @@ -1,4 +1,5 @@ -import { useState, useEffect } from 'react'; +import { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { adminApi, AdminTicket, AdminTicketDetail, AdminTicketMessage } from '../api/admin'; @@ -104,12 +105,12 @@ function AdminMessageMedia({ export default function AdminTickets() { const { t } = useTranslation(); + const navigate = useNavigate(); const queryClient = useQueryClient(); const [selectedTicketId, setSelectedTicketId] = useState(null); const [statusFilter, setStatusFilter] = useState(''); const [replyText, setReplyText] = useState(''); const [page, setPage] = useState(1); - const [showSettings, setShowSettings] = useState(false); const { data: stats } = useQuery({ queryKey: ['admin-ticket-stats'], @@ -214,7 +215,7 @@ export default function AdminTickets() {
- - - {isLoading ? ( -
-
-
- ) : ( -
- {/* Support System Mode */} -
- - -

{t('admin.tickets.supportModeDesc')}

-
- - {/* Cabinet Notifications */} -
-

- {t('admin.tickets.cabinetNotifications')} -

- - {/* User Notifications */} -
- -
- - {/* Admin Notifications */} -
- -
-
- -
-

- {t('admin.tickets.slaSettings')} -

- - {/* SLA Enabled */} -
- -
-
- - {/* SLA Minutes */} -
- - - setFormData({ ...formData, sla_minutes: parseInt(e.target.value) }) - } - className="input" - disabled={!formData.sla_enabled} - /> -

{t('admin.tickets.slaMinutesDesc')}

-
- - {/* Check Interval */} -
- - - setFormData({ ...formData, sla_check_interval_seconds: parseInt(e.target.value) }) - } - className="input" - disabled={!formData.sla_enabled} - /> -

{t('admin.tickets.checkIntervalDesc')}

-
- - {/* Reminder Cooldown */} -
- - - setFormData({ - ...formData, - sla_reminder_cooldown_minutes: parseInt(e.target.value), - }) - } - className="input" - disabled={!formData.sla_enabled} - /> -

- {t('admin.tickets.reminderCooldownDesc')} -

-
- - {/* Buttons */} -
- - -
- - {updateMutation.isError && ( -
- {t('admin.tickets.settingsUpdateError')} -
- )} -
- )} -
); }