Apply some changes from hooks-migration branch

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-11-05 16:12:16 +01:00
parent 91a4950b7b
commit e62e09e387
5 changed files with 31 additions and 20 deletions

View File

@ -3,13 +3,16 @@ import { useQuery } from '@tanstack/react-query';
import { usePlHooksApiClient } from 'pl-hooks/contexts/api-client';
import { usePlHooksQueryClient } from 'pl-hooks/contexts/query-client';
import type { Translation } from 'pl-api';
const useStatusTranslation = (statusId: string, targetLanguage?: string) => {
const { client } = usePlHooksApiClient();
const queryClient = usePlHooksQueryClient();
return useQuery({
return useQuery<Translation | false>({
queryKey: ['statuses', 'translations', statusId, targetLanguage],
queryFn: () => client.statuses.translateStatus(statusId, targetLanguage),
queryFn: () => client.statuses.translateStatus(statusId, targetLanguage)
.then(translation => translation).catch(() => false),
enabled: !!targetLanguage,
}, queryClient);
};