Skip to content

Commit

Permalink
Merge branch 'feature-invite-user' of https://github.com/uug-ai/facia…
Browse files Browse the repository at this point in the history
…l-access-control into feature-invite-user
  • Loading branch information
LuisMaja committed Jun 27, 2024
2 parents 8e1c94c + 1261384 commit 3513d6e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
15 changes: 0 additions & 15 deletions api/.env

This file was deleted.

46 changes: 42 additions & 4 deletions ui/src/app/dashboard/components/InviteUserDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
import Dialog from "@/components/Dialog";
import { Text, Input, Button } from "@/components/ui";
import React, { useState } from "react";
import { useAddUserMutation } from "@/lib/services/users/userApi";
import { useInviteUserMutation } from "@/lib/services/users/userApi";
import { useAppSelector } from "@/lib/hooks";
import { RootState } from "@/lib/store";

const InviteUserDialog: React.FC = () => {
const [addUser, { isLoading }] = useAddUserMutation();
const [inviteUser, { isLoading }] = useInviteUserMutation();
const isVisible = useAppSelector(
(store: RootState) => store.dialog.isVisible
);
const [email, setEmail] = useState("");
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [submitError, setSubmitError] = useState<string | null>(null);
const [isSubmitted, setIsSubmitted] = useState(false);

function handleClose() {
setEmail("");
setFirstName("");
setLastName("");
setIsSubmitted(false);
setSubmitError(null);
console.log("Dialog has closed");
Expand All @@ -28,7 +32,11 @@ const InviteUserDialog: React.FC = () => {
setSubmitError(null);

try {
await addUser({ email }).unwrap();
await inviteUser({
email: email,
firstname: firstName,
lastname: lastName,
}).unwrap();
setIsSubmitted(true);
console.log("Inviting user with email", email);
} catch (err) {
Expand All @@ -53,7 +61,7 @@ const InviteUserDialog: React.FC = () => {
) : (
<form onSubmit={handleSubmit}>
<Text as="label" htmlFor="email">
New user email
Email
</Text>
<Input
className="mb-4"
Expand All @@ -67,6 +75,36 @@ const InviteUserDialog: React.FC = () => {
}
required
/>
<Text as="label" htmlFor="firstName">
First Name
</Text>
<Input
className="mb-4"
type="firstName"
id="firstName"
name="firstName"
placeholder="firstName"
value={firstName}
onChange={(e: { target: { value: string } }) =>
setFirstName(e.target.value)
}
required
/>
<Text as="label" htmlFor="lastName">
Last Name
</Text>
<Input
className="mb-4"
type="lastName"
id="lastName"
name="lastName"
placeholder="lastName"
value={lastName}
onChange={(e: { target: { value: string } }) =>
setLastName(e.target.value)
}
required
/>
{submitError && (
<Text as="p" variant="error" className="text-red-700">
{submitError}
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/dashboard/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const UserTable = () => {
}
const mappedData =
data?.data.map((user: User) => ({
status: user.
id: user.id,
name: `${user.firstname} ${user.lastname}`,
email: user.email,
Expand Down
10 changes: 10 additions & 0 deletions ui/src/lib/services/users/userApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export const userApi = createApi({
}),
invalidatesTags: ["User"],
}),
inviteUser: build.mutation({
query: (user) => ({
url: "users/invite",
method: "POST",
headers: { "Content-Type": "application/json" },
body: user,
}),
invalidatesTags: ["User"],
}),
}),
});

Expand All @@ -54,4 +63,5 @@ export const {
useAddUserMutation,
useUpdateUserMutation,
useDeleteUserMutation,
useInviteUserMutation,
} = userApi;

0 comments on commit 3513d6e

Please sign in to comment.