Share - WIP

This commit is contained in:
Philipinho
2025-04-09 13:26:50 +01:00
parent a9f370660b
commit 18e8c4cbaf
19 changed files with 514 additions and 6 deletions

View File

@ -0,0 +1,65 @@
import {
useMutation,
useQuery,
UseQueryResult,
} from "@tanstack/react-query";
import { notifications } from "@mantine/notifications";
import { validate as isValidUuid } from "uuid";
import { useTranslation } from "react-i18next";
import {
ICreateShare,
IShareInput,
} from "@/features/share/types/share.types.ts";
import {
createShare,
deleteShare,
getShare,
updateShare,
} from "@/features/share/services/share-service.ts";
import { IPage } from "@/features/page/types/page.types.ts";
export function useShareQuery(
shareInput: Partial<IShareInput>,
): UseQueryResult<IPage, Error> {
const query = useQuery({
queryKey: ["shares", shareInput],
queryFn: () => getShare(shareInput),
enabled: !!shareInput.shareId,
staleTime: 5 * 60 * 1000,
});
return query;
}
export function useCreateShareMutation() {
const { t } = useTranslation();
return useMutation<any, Error, ICreateShare>({
mutationFn: (data) => createShare(data),
onSuccess: (data) => {},
onError: (error) => {
notifications.show({ message: t("Failed to share page"), color: "red" });
},
});
}
export function useUpdateShareMutation() {
return useMutation<any, Error, Partial<IShareInput>>({
mutationFn: (data) => updateShare(data),
});
}
export function useDeleteShareMutation() {
const { t } = useTranslation();
return useMutation({
mutationFn: (shareId: string) => deleteShare(shareId),
onSuccess: () => {
notifications.show({ message: t("Share deleted successfully") });
},
onError: (error) => {
notifications.show({
message: t("Failed to delete share"),
color: "red",
});
},
});
}