From 0bd162cc814d03bca0637b0776e5b38a8187a161 Mon Sep 17 00:00:00 2001
From: Joshua Rodriguez <97762447+joshua-rdrgz@users.noreply.github.com>
Date: Thu, 22 Feb 2024 15:49:31 -0600
Subject: [PATCH] Add invite-user dialog/modal button UI (#328)
Dialog shows form for users to invite other users
---
frontend/shared-components/index.tsx | 2 +
.../invite-user-btn.module.css | 5 ++
.../invite-user-btn/invite-user-btn.tsx | 27 ++++++++
.../sub-comps/invite-user-form.module.css | 4 ++
.../sub-comps/invite-user-form.tsx | 66 +++++++++++++++++++
.../invite-user-btn/sub-comps/select-role.tsx | 27 ++++++++
6 files changed, 131 insertions(+)
create mode 100644 frontend/shared-components/invite-user-btn/invite-user-btn.module.css
create mode 100644 frontend/shared-components/invite-user-btn/invite-user-btn.tsx
create mode 100644 frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.module.css
create mode 100644 frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.tsx
create mode 100644 frontend/shared-components/invite-user-btn/sub-comps/select-role.tsx
diff --git a/frontend/shared-components/index.tsx b/frontend/shared-components/index.tsx
index f11fe629d..2172b308f 100644
--- a/frontend/shared-components/index.tsx
+++ b/frontend/shared-components/index.tsx
@@ -6,6 +6,7 @@ import ExternalLink from "./external-link/external-link"
import * as Form from "./form/form"
import InfoTooltip from "./info-tooltip/info-tooltip"
import Input from "./input/input"
+import InviteUserBtn from "./invite-user-btn/invite-user-btn"
import Label from "./label/label"
import Layout from "./layout/layout"
import LinkButton from "./link-button/link-button"
@@ -29,6 +30,7 @@ export {
FormLevelError,
InfoTooltip,
Input,
+ InviteUserBtn,
Label,
Layout,
LinkButton,
diff --git a/frontend/shared-components/invite-user-btn/invite-user-btn.module.css b/frontend/shared-components/invite-user-btn/invite-user-btn.module.css
new file mode 100644
index 000000000..e2a5bcfc0
--- /dev/null
+++ b/frontend/shared-components/invite-user-btn/invite-user-btn.module.css
@@ -0,0 +1,5 @@
+.triggerBtn {
+ font-size: var(--size20);
+ font-weight: bold;
+ min-width: max-content;
+}
diff --git a/frontend/shared-components/invite-user-btn/invite-user-btn.tsx b/frontend/shared-components/invite-user-btn/invite-user-btn.tsx
new file mode 100644
index 000000000..50e312e74
--- /dev/null
+++ b/frontend/shared-components/invite-user-btn/invite-user-btn.tsx
@@ -0,0 +1,27 @@
+import classNames from "classnames"
+import { Dialog as D, PrimaryButton } from "../../shared-components"
+import styles from "./invite-user-btn.module.css"
+import InviteUserForm from "./sub-comps/invite-user-form"
+
+interface InviteUserBtnProps {
+ btnClassName?: string
+}
+
+export default function InviteUserBtn({ btnClassName }: InviteUserBtnProps) {
+ const { triggerBtn } = styles
+
+ return (
+
+
+ Invite User
+
+
+
+ Invite a User
+ Invite a user to this organization.
+
+
+
+
+ )
+}
diff --git a/frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.module.css b/frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.module.css
new file mode 100644
index 000000000..0143e4a83
--- /dev/null
+++ b/frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.module.css
@@ -0,0 +1,4 @@
+.submitBtn {
+ font-size: var(--size16);
+ min-width: max-content;
+}
diff --git a/frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.tsx b/frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.tsx
new file mode 100644
index 000000000..bae695ce9
--- /dev/null
+++ b/frontend/shared-components/invite-user-btn/sub-comps/invite-user-form.tsx
@@ -0,0 +1,66 @@
+import { zodResolver } from "@hookform/resolvers/zod"
+import { FieldValues, useForm } from "react-hook-form"
+import { z } from "zod"
+import { UserRoles } from "../../../models/profile"
+import { Form as F, Input, Dialog as D, PrimaryButton } from "../../../shared-components"
+import SelectRole from "./select-role"
+import styles from "./invite-user-form.module.css"
+
+type UserRolesKeys = keyof typeof UserRoles
+
+type InviteUserSchema = z.infer
+const inviteUserSchema = z.object({
+ email: z.string().email(),
+ role: z.enum(Object.keys(UserRoles) as [UserRolesKeys])
+})
+
+export default function InviteUserForm() {
+ const { submitBtn } = styles
+
+ const formMethods = useForm({
+ resolver: zodResolver(inviteUserSchema),
+ defaultValues: {
+ email: "",
+ role: "NONE"
+ }
+ })
+
+ const onSubmit = (values: FieldValues) => {
+ console.log("values: ", values)
+ }
+
+ return (
+
+ (
+
+ User's email
+
+
+
+
+
+ )}
+ />
+ (
+
+ User's role
+
+
+
+
+ )}
+ />
+
+
+ Invite User
+
+
+
+ )
+}
diff --git a/frontend/shared-components/invite-user-btn/sub-comps/select-role.tsx b/frontend/shared-components/invite-user-btn/sub-comps/select-role.tsx
new file mode 100644
index 000000000..0492e4820
--- /dev/null
+++ b/frontend/shared-components/invite-user-btn/sub-comps/select-role.tsx
@@ -0,0 +1,27 @@
+import { Select as S } from "../../../shared-components"
+import { UserRoles } from "../../../models/profile"
+import { capitalizeFirstChar } from "../../../helpers"
+
+const userRoles = Object.keys(UserRoles).filter((el) => isNaN(Number(el)))
+
+interface SelectRoleProps {
+ value: string
+ onChange(...event: any[]): void
+}
+
+export default function SelectRole({ value, onChange }: SelectRoleProps) {
+ return (
+
+
+
+
+
+ {userRoles.map((role) => (
+
+ {capitalizeFirstChar(role.toLowerCase())}
+
+ ))}
+
+
+ )
+}