fix: normalize all API responses, add error handling and reset confirmation

- Extract normalizeConfig() for consistent response normalization
- Add onError handlers to mutations with useNotify
- Add window.confirm before destructive reset action
- Add resetConfirm translation key to all locales
This commit is contained in:
Fringg
2026-02-13 00:41:00 +03:00
parent 1a0a5ff453
commit 150a1b2dba
6 changed files with 33 additions and 12 deletions

View File

@@ -10,6 +10,7 @@ import {
BOT_LOCALES,
} from '../../api/buttonStyles';
import { Toggle } from './Toggle';
import { useNotify } from '../../platform/hooks/useNotify';
type StyleValue = 'primary' | 'success' | 'danger' | 'default';
@@ -40,6 +41,7 @@ function stylesEqual(a: ButtonStylesConfig, b: ButtonStylesConfig): boolean {
export function ButtonsTab() {
const { t } = useTranslation();
const queryClient = useQueryClient();
const notify = useNotify();
const { data: serverStyles } = useQuery({
queryKey: ['button-styles'],
@@ -73,6 +75,9 @@ export function ButtonsTab() {
setDraftStyles(data);
queryClient.setQueryData(['button-styles'], data);
},
onError: () => {
notify.error(t('common.error'));
},
});
const resetMutation = useMutation({
@@ -82,6 +87,9 @@ export function ButtonsTab() {
setDraftStyles(data);
queryClient.setQueryData(['button-styles'], data);
},
onError: () => {
notify.error(t('common.error'));
},
});
const updateSection = useCallback(
@@ -333,7 +341,11 @@ export function ButtonsTab() {
{/* Reset */}
<div className="flex justify-end">
<button
onClick={() => resetMutation.mutate()}
onClick={() => {
if (window.confirm(t('admin.buttons.resetConfirm'))) {
resetMutation.mutate();
}
}}
disabled={resetMutation.isPending}
className="rounded-xl bg-dark-700 px-4 py-2 text-sm text-dark-300 transition-colors hover:bg-dark-600 disabled:opacity-50"
>