mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-04-28 11:30:00 +00:00
- Replace getApiErrorKey with getApiErrorMessage in use-settings.ts
so error toasts show translated messages instead of raw i18n keys
- Update CLAUDE.md files to reflect the new t('section.key') pattern
and remove outdated Proxy-related gotchas
38 lines
No EOL
1.2 KiB
TypeScript
38 lines
No EOL
1.2 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { settingsApi } from '@/lib/api/settings'
|
|
import { QUERY_KEYS } from '@/lib/api/query-client'
|
|
import { useToast } from '@/lib/hooks/use-toast'
|
|
import { useTranslation } from '@/lib/hooks/use-translation'
|
|
import { getApiErrorMessage } from '@/lib/utils/error-handler'
|
|
import { SettingsResponse } from '@/lib/types/api'
|
|
|
|
export function useSettings() {
|
|
return useQuery({
|
|
queryKey: QUERY_KEYS.settings,
|
|
queryFn: () => settingsApi.get(),
|
|
})
|
|
}
|
|
|
|
export function useUpdateSettings() {
|
|
const queryClient = useQueryClient()
|
|
const { toast } = useToast()
|
|
const { t } = useTranslation()
|
|
|
|
return useMutation({
|
|
mutationFn: (data: Partial<SettingsResponse>) => settingsApi.update(data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.settings })
|
|
toast({
|
|
title: t('common.success'),
|
|
description: t('common.saveSuccess'),
|
|
})
|
|
},
|
|
onError: (error: unknown) => {
|
|
toast({
|
|
title: t('common.error'),
|
|
description: getApiErrorMessage(error, (key) => t(key), 'common.error'),
|
|
variant: 'destructive',
|
|
})
|
|
},
|
|
})
|
|
} |