diff --git a/src/api/buttonStyles.ts b/src/api/buttonStyles.ts index 1a67c17..c1ee6e2 100644 --- a/src/api/buttonStyles.ts +++ b/src/api/buttonStyles.ts @@ -33,6 +33,7 @@ export const BUTTON_SECTIONS = [ export type ButtonSection = (typeof BUTTON_SECTIONS)[number]; +// Bot-side locales (includes 'ua' for Ukrainian, mapped from ISO 'uk' internally). export const BOT_LOCALES = ['ru', 'en', 'ua', 'zh', 'fa'] as const; export type BotLocale = (typeof BOT_LOCALES)[number]; @@ -54,19 +55,23 @@ export const DEFAULT_BUTTON_STYLES: ButtonStylesConfig = { admin: { ...DEFAULT_SECTION, style: 'danger' }, }; +function normalizeConfig(data: ButtonStylesConfig): ButtonStylesConfig { + const result = {} as ButtonStylesConfig; + for (const section of BUTTON_SECTIONS) { + result[section] = { + ...DEFAULT_SECTION, + ...data[section], + labels: { ...(data[section]?.labels || {}) }, + }; + } + return result; +} + export const buttonStylesApi = { getStyles: async (): Promise => { try { const response = await apiClient.get('/cabinet/admin/button-styles'); - const data = response.data; - for (const section of BUTTON_SECTIONS) { - data[section] = { - ...DEFAULT_SECTION, - ...data[section], - labels: { ...(data[section]?.labels || {}) }, - }; - } - return data; + return normalizeConfig(response.data); } catch { return DEFAULT_BUTTON_STYLES; } @@ -77,11 +82,11 @@ export const buttonStylesApi = { '/cabinet/admin/button-styles', update, ); - return response.data; + return normalizeConfig(response.data); }, resetStyles: async (): Promise => { const response = await apiClient.post('/cabinet/admin/button-styles/reset'); - return response.data; + return normalizeConfig(response.data); }, }; diff --git a/src/components/admin/ButtonsTab.tsx b/src/components/admin/ButtonsTab.tsx index fd419ed..c428e4e 100644 --- a/src/components/admin/ButtonsTab.tsx +++ b/src/components/admin/ButtonsTab.tsx @@ -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 */}