From c8cc750be98a59f8aa7a034e56ded4cf743fff96 Mon Sep 17 00:00:00 2001 From: Vidyoot Senthil Date: Sat, 13 Jul 2024 23:58:34 -0500 Subject: [PATCH] bugfix: clear modal content on close + stylize users and invites tables to look the same as other tables --- .../src/components/InviteUserModal.tsx | 32 +- .../src/pages/Dashboard/UserManagment.tsx | 298 +++++++++--------- 2 files changed, 175 insertions(+), 155 deletions(-) diff --git a/frontends/dashboard/src/components/InviteUserModal.tsx b/frontends/dashboard/src/components/InviteUserModal.tsx index b94f6c4dcf..75991dc9f2 100644 --- a/frontends/dashboard/src/components/InviteUserModal.tsx +++ b/frontends/dashboard/src/components/InviteUserModal.tsx @@ -1,8 +1,8 @@ -import { Accessor, Show, useContext } from "solid-js"; +import { Accessor, createMemo, onMount, Show, useContext } from "solid-js"; import { createSignal } from "solid-js"; import { Dialog, DialogOverlay, DialogPanel, DialogTitle } from "terracotta"; import { UserContext } from "../contexts/UserContext"; -import { DefaultError } from "shared/types"; +import { DefaultError, fromI32ToUserRole } from "shared/types"; import { UserRole, fromUserRoleToI32, stringToUserRole } from "shared/types"; import { createToast } from "./ShowToasts"; @@ -20,6 +20,28 @@ export const InviteUserModal = (props: InviteUserModalProps) => { const userContext = useContext(UserContext); + const currentUserRole = createMemo(() => { + const selectedOrgId = userContext.selectedOrganizationId?.(); + if (!selectedOrgId) return 0; + return ( + userContext + .user?.() + ?.user_orgs.find( + (user_org) => user_org.organization_id === selectedOrgId, + )?.role ?? 0 + ); + }); + + onMount(() => { + setRole(fromI32ToUserRole(currentUserRole())); + }); + + const handleCloseModal = () => { + setEmail(""); + setRole(fromI32ToUserRole(currentUserRole())); + props.closeModal(); + }; + const inviteUser = (closeModal: () => void) => { setSendingEmail(true); void fetch(`${apiHost}/invitation`, { @@ -64,7 +86,7 @@ export const InviteUserModal = (props: InviteUserModalProps) => {
@@ -77,7 +99,7 @@ export const InviteUserModal = (props: InviteUserModalProps) => {
{ e.preventDefault(); - inviteUser(props.closeModal); + inviteUser(handleCloseModal); }} >
@@ -149,7 +171,7 @@ export const InviteUserModal = (props: InviteUserModalProps) => { diff --git a/frontends/dashboard/src/pages/Dashboard/UserManagment.tsx b/frontends/dashboard/src/pages/Dashboard/UserManagment.tsx index 236aefc181..e8357c4c5d 100644 --- a/frontends/dashboard/src/pages/Dashboard/UserManagment.tsx +++ b/frontends/dashboard/src/pages/Dashboard/UserManagment.tsx @@ -214,7 +214,7 @@ export const UserManagement = () => { setShowInvitations(!showInvitations()); }} type="button" - class="block rounded-md bg-neutral-100 px-3 py-2 text-center shadow-sm hover:bg-neutral-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-200" + class="block h-[42px] rounded-md border bg-neutral-100 px-3 py-2 text-center shadow-sm hover:bg-neutral-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-200" > {showInvitations() ? "Show Users" : "Show Invitations"} @@ -235,160 +235,158 @@ export const UserManagement = () => { setInviteUserModalOpen(true); }} type="button" - class="block rounded-md bg-magenta-500 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-magenta-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-magenta-600" + class="block h-[42px] rounded-md border bg-magenta-500 px-3 py-2 text-center text-sm font-semibold text-white shadow-sm hover:bg-magenta-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-magenta-600" > - Add user + Add User
-
-
- - - - - - - - - - - - - - {(user) => ( - - - - - - - - )} - - - - - - - - - - - - - - - {(invitation) => ( - - - - - - - )} - - - -
- Name - - Email - - Role - - Edit - - Delete -
- {user.name} - - {user.email} - - {fromI32ToUserRole(user.user_orgs[0].role) as string} - - - - -
- Email - - Role - - Status - - Delete -
- {invitation.email} - - {fromI32ToUserRole(invitation.role) as string} - - {invitation.used ? "Accepted" : "Not Accepted"} - - -
-
+
+ + + + + + + + + + + + + + {(user) => ( + + + + + + + + )} + + + + + + + + + + + + + + + {(invitation) => ( + + + + + + + )} + + + +
+ Name + + Email + + Role + + Edit + + Delete +
+ {user.name} + + {user.email} + + {fromI32ToUserRole(user.user_orgs[0].role) as string} + + + + +
+ Email + + Role + + Status + + Delete +
+ {invitation.email} + + {fromI32ToUserRole(invitation.role) as string} + + {invitation.used ? "Accepted" : "Not Accepted"} + + +