mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-02 02:23:25 +00:00
Merge branch 'dev'
This commit is contained in:
45
apps/edr-freight-web/backoffice/src/hooks/useLogoSettings.ts
Normal file
45
apps/edr-freight-web/backoffice/src/hooks/useLogoSettings.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { logoSettingsService } from "@/services/logoSettings.service";
|
||||
import { useErrorHandler } from "@/shared/hooks/useErrorHandler";
|
||||
|
||||
const QUERY_KEY = ["logoSettings"];
|
||||
|
||||
export const useLogoSettingsQuery = () =>
|
||||
useQuery({
|
||||
queryKey: QUERY_KEY,
|
||||
queryFn: () => logoSettingsService.get(),
|
||||
});
|
||||
|
||||
export const useSetLogo = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
const { handleError } = useErrorHandler(t);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (logoImageBase64: string) =>
|
||||
logoSettingsService.set(logoImageBase64),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
|
||||
toast.success(t("logoSettings.updated", "Company logo updated"));
|
||||
},
|
||||
onError: handleError,
|
||||
});
|
||||
};
|
||||
|
||||
export const useClearLogo = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
const { handleError } = useErrorHandler(t);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => logoSettingsService.clear(),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: QUERY_KEY });
|
||||
toast.success(t("logoSettings.cleared", "Company logo removed"));
|
||||
},
|
||||
onError: handleError,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user