Spaces:
Sleeping
Sleeping
File size: 991 Bytes
f871fed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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 { 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()
return useMutation({
mutationFn: (data: Partial<SettingsResponse>) => settingsApi.update(data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.settings })
toast({
title: 'Success',
description: 'Settings updated successfully',
})
},
onError: () => {
toast({
title: 'Error',
description: 'Failed to update settings',
variant: 'destructive',
})
},
})
} |