mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 01:12:37 +10:00
feat: add copy invite link to invitation action menu (#360)
* +copy invite link to clipboard from invite action menu * -remove log to console for copy link action * Refactor copy invite link feature --------- Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
54d27af76a
commit
7fc1a782a7
@ -5,8 +5,10 @@ import { modals } from "@mantine/modals";
|
||||
import {
|
||||
useResendInvitationMutation,
|
||||
useRevokeInvitationMutation,
|
||||
useGetInviteLink,
|
||||
} from "@/features/workspace/queries/workspace-query.ts";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
interface Props {
|
||||
invitationId: string;
|
||||
@ -15,6 +17,17 @@ export default function InviteActionMenu({ invitationId }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const resendInvitationMutation = useResendInvitationMutation();
|
||||
const revokeInvitationMutation = useRevokeInvitationMutation();
|
||||
const { data: inviteLink, error, } = useGetInviteLink(invitationId);
|
||||
|
||||
const onCopyLink = async () => {
|
||||
if (error) {
|
||||
notifications.show({ message: error.message, color: "red" })
|
||||
} else {
|
||||
navigator.clipboard.writeText(inviteLink.inviteLink)
|
||||
notifications.show({ message: "Invite link copied to clipboard!"})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const onResend = async () => {
|
||||
await resendInvitationMutation.mutateAsync({ invitationId });
|
||||
@ -58,6 +71,8 @@ export default function InviteActionMenu({ invitationId }: Props) {
|
||||
|
||||
<Menu.Dropdown>
|
||||
<Menu.Item onClick={onResend}>{t("Resend invitation")}</Menu.Item>
|
||||
<Menu.Item onClick={onCopyLink}>Copy invite link</Menu.Item>
|
||||
<Menu.Item onClick={onResend}>Resend invitation</Menu.Item>
|
||||
<Menu.Divider />
|
||||
<Menu.Item
|
||||
c="red"
|
||||
|
||||
@ -14,6 +14,7 @@ import {
|
||||
resendInvitation,
|
||||
revokeInvitation,
|
||||
getWorkspace,
|
||||
getInviteLink,
|
||||
getWorkspacePublicData,
|
||||
} from "@/features/workspace/services/workspace-service";
|
||||
import { IPagination, QueryParams } from "@/lib/types.ts";
|
||||
@ -21,6 +22,7 @@ import { notifications } from "@mantine/notifications";
|
||||
import {
|
||||
ICreateInvite,
|
||||
IInvitation,
|
||||
IInvitationLink,
|
||||
IWorkspace,
|
||||
} from "@/features/workspace/types/workspace.types.ts";
|
||||
import { IUser } from "@/features/user/types/user.types.ts";
|
||||
@ -80,6 +82,15 @@ export function useWorkspaceInvitationsQuery(
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetInviteLink(
|
||||
invitationId: string
|
||||
): UseQueryResult<IInvitationLink,Error> {
|
||||
return useQuery({
|
||||
queryKey:["inviteLink",invitationId],
|
||||
queryFn: () => getInviteLink({ invitationId }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateInvitationMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import {
|
||||
IInvitation,
|
||||
IWorkspace,
|
||||
IAcceptInvite,
|
||||
IInvitationLink,
|
||||
} from "../types/workspace.types";
|
||||
import { IPagination, QueryParams } from "@/lib/types.ts";
|
||||
|
||||
@ -53,6 +54,13 @@ export async function acceptInvitation(data: IAcceptInvite): Promise<void> {
|
||||
await api.post<void>("/workspace/invites/accept", data);
|
||||
}
|
||||
|
||||
export async function getInviteLink(data: {
|
||||
invitationId: string;
|
||||
}): Promise<IInvitationLink> {
|
||||
const req = await api.post("/workspace/invites/link", data);
|
||||
return req.data;
|
||||
}
|
||||
|
||||
export async function resendInvitation(data: {
|
||||
invitationId: string;
|
||||
}): Promise<void> {
|
||||
|
||||
@ -28,6 +28,10 @@ export interface IInvitation {
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export interface IInvitationLink {
|
||||
inviteLink: string;
|
||||
}
|
||||
|
||||
export interface IAcceptInvite {
|
||||
invitationId: string;
|
||||
name: string;
|
||||
|
||||
Reference in New Issue
Block a user