mirror of
https://github.com/docmost/docmost.git
synced 2025-11-15 06:11:08 +10:00
implement new invitation system
* fix comments on the frontend * move jwt token service to its own module * other fixes and updates
This commit is contained in:
@ -6,12 +6,21 @@ import {
|
||||
} from "@tanstack/react-query";
|
||||
import {
|
||||
changeMemberRole,
|
||||
getInvitationById,
|
||||
getPendingInvitations,
|
||||
getWorkspace,
|
||||
getWorkspaceMembers,
|
||||
createInvitation,
|
||||
resendInvitation,
|
||||
revokeInvitation,
|
||||
} from "@/features/workspace/services/workspace-service";
|
||||
import { QueryParams } from "@/lib/types.ts";
|
||||
import { IPagination, QueryParams } from "@/lib/types.ts";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
import { IWorkspace } from "@/features/workspace/types/workspace.types.ts";
|
||||
import {
|
||||
ICreateInvite,
|
||||
IInvitation,
|
||||
IWorkspace,
|
||||
} from "@/features/workspace/types/workspace.types.ts";
|
||||
|
||||
export function useWorkspace(): UseQueryResult<IWorkspace, Error> {
|
||||
return useQuery({
|
||||
@ -44,3 +53,85 @@ export function useChangeMemberRoleMutation() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useWorkspaceInvitationsQuery(
|
||||
params?: QueryParams,
|
||||
): UseQueryResult<IPagination<IInvitation>, Error> {
|
||||
return useQuery({
|
||||
queryKey: ["invitations", params],
|
||||
queryFn: () => getPendingInvitations(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateInvitationMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<void, Error, ICreateInvite>({
|
||||
mutationFn: (data) => createInvitation(data),
|
||||
onSuccess: (data, variables) => {
|
||||
notifications.show({ message: "Invitation successfully" });
|
||||
// TODO: mutate cache
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["invitations"],
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
const errorMessage = error["response"]?.data?.message;
|
||||
notifications.show({ message: errorMessage, color: "red" });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useResendInvitationMutation() {
|
||||
return useMutation<
|
||||
void,
|
||||
Error,
|
||||
{
|
||||
invitationId: string;
|
||||
}
|
||||
>({
|
||||
mutationFn: (data) => resendInvitation(data),
|
||||
onSuccess: (data, variables) => {
|
||||
notifications.show({ message: "Invitation mail sent" });
|
||||
},
|
||||
onError: (error) => {
|
||||
const errorMessage = error["response"]?.data?.message;
|
||||
notifications.show({ message: errorMessage, color: "red" });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useRevokeInvitationMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<
|
||||
void,
|
||||
Error,
|
||||
{
|
||||
invitationId: string;
|
||||
}
|
||||
>({
|
||||
mutationFn: (data) => revokeInvitation(data),
|
||||
onSuccess: (data, variables) => {
|
||||
notifications.show({ message: "Invitation revoked" });
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["invitations"],
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
const errorMessage = error["response"]?.data?.message;
|
||||
notifications.show({ message: errorMessage, color: "red" });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetInvitationQuery(
|
||||
invitationId: string,
|
||||
): UseQueryResult<any, Error> {
|
||||
return useQuery({
|
||||
// eslint-disable-next-line @tanstack/query/exhaustive-deps
|
||||
queryKey: ["invitations", invitationId],
|
||||
queryFn: () => getInvitationById({ invitationId }),
|
||||
enabled: !!invitationId,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user