Skip to content

Commit f93d60f

Browse files
committed
feat: add invite link for copying and sending to user
fix: add space between the two buttons
1 parent c6965e5 commit f93d60f

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/api/query-hooks/useUserAPI.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import {
99
} from "../services/users";
1010

1111
export function useInviteUser(
12-
options: UseMutationOptions<any, AxiosError, InviteUserPayload>
12+
options: UseMutationOptions<
13+
{
14+
link: string;
15+
},
16+
AxiosError,
17+
InviteUserPayload
18+
>
1319
) {
1420
return useMutation({
1521
...options,

src/pages/UsersPage.tsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import UserForm from "@flanksource-ui/components/Users/UserForm";
77
import { SearchLayout } from "@flanksource-ui/ui/Layout/SearchLayout";
88
import { useQuery } from "@tanstack/react-query";
99
import { useRef, useState } from "react";
10+
import { FaCopy } from "react-icons/fa";
1011
import { ImUserPlus } from "react-icons/im";
1112
import { getRegisteredUsers } from "../api/services/users";
12-
import { Modal } from "../components";
13+
import { Button, Modal } from "../components";
1314
import { AuthorizationAccessCheck } from "../components/Permissions/AuthorizationAccessCheck";
1415
import { toastError, toastSuccess } from "../components/Toast/toast";
1516
import { UserList } from "../components/Users/UserList";
@@ -25,6 +26,7 @@ export function UsersPage() {
2526
const [isOpen, setIsOpen] = useState(false);
2627
const [editUser, setEditUser] = useState<RegisteredUser>();
2728
const containerRef = useRef<HTMLDivElement>(null);
29+
const [inviteLink, setInviteLink] = useState<string>();
2830

2931
const {
3032
isLoading,
@@ -41,10 +43,10 @@ export function UsersPage() {
4143
});
4244

4345
const { mutate: inviteUserFunction, isLoading: isInviting } = useInviteUser({
44-
onSuccess: () => {
46+
onSuccess: (data) => {
4547
refetch();
46-
toastSuccess(`user invited successfully`);
4748
setIsOpen(false);
49+
setInviteLink(data.link);
4850
},
4951
onError: (error) => {
5052
toastError(error.message);
@@ -146,6 +148,48 @@ export function UsersPage() {
146148
/>
147149
</Modal>
148150

151+
{inviteLink && (
152+
<Modal
153+
title="Invite Link"
154+
onClose={() => {
155+
setInviteLink(undefined);
156+
}}
157+
open={!!inviteLink}
158+
bodyClass=""
159+
>
160+
<div className="flex flex-col gap-2 bg-white p-4 text-sm">
161+
<p>
162+
User has been invited successfully. Please share the link with
163+
the user.
164+
</p>
165+
<div className="relative flex flex-col space-y-4 py-3 text-blue-500">
166+
<Button
167+
className="btn-white absolute right-0 top-0 whitespace-pre-line bg-white text-black"
168+
onClick={() => {
169+
navigator.clipboard.writeText(inviteLink!);
170+
toastSuccess("Link copied to clipboard");
171+
}}
172+
title="Copy Invite Link"
173+
>
174+
<FaCopy />
175+
</Button>
176+
177+
{inviteLink}
178+
</div>
179+
<div className="flex flex-row justify-end gap-2">
180+
<Button
181+
className="btn-white"
182+
onClick={() => {
183+
setInviteLink(undefined);
184+
}}
185+
>
186+
Close
187+
</Button>
188+
</div>
189+
</div>
190+
</Modal>
191+
)}
192+
149193
{editUser && (
150194
<Modal
151195
title="Edit User"

0 commit comments

Comments
 (0)