mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 09:33:46 +00:00
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:
@@ -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"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user