From 5449bedf119baa3e31ecac79944efb2afde5bbc6 Mon Sep 17 00:00:00 2001 From: Ricardo Costa Date: Wed, 19 Jun 2024 16:31:37 +0100 Subject: [PATCH] Progress on Workspace Member Management --- code/client/src/App.tsx | 8 ++-- .../src/domain/workspaces/useWorkspaces.ts | 15 +++++++ code/client/src/services/auth/authService.ts | 6 ++- .../services/workspace/workspaceService.ts | 17 +++++++ .../src/ui/components/dialog/Dialog.tsx | 4 +- .../src/ui/components/header/Header.scss | 4 ++ .../src/ui/components/header/Header.tsx | 18 ++++---- .../src/ui/components/sidebar/Sidebar.tsx | 1 - .../src/ui/contexts/auth/AuthContext.tsx | 9 +++- code/client/src/ui/contexts/auth/utils.ts | 22 ---------- .../Login.scss => landing/Landing.scss} | 4 +- .../{login/Login.tsx => landing/Landing.tsx} | 19 ++++---- code/client/src/ui/pages/profile/Profile.scss | 7 +++ code/client/src/ui/pages/profile/Profile.tsx | 44 +++++++++++++++++++ .../components/ManageMembersDialog.tsx | 44 +++++++++++++++++++ .../src/ui/pages/workspaces/Workspaces.tsx | 5 ++- .../components/WorkspaceContextMenu.tsx | 29 ++++++++---- .../workspaces/components/WorkspaceView.tsx | 24 ++++++++-- code/server/sql/create_tables.sql | 9 ++-- .../http/handlers/usersHandlers.ts | 6 +++ .../http/handlers/workspacesHandlers.ts | 27 +++++++++++- .../http/middlewares/authMiddleware.ts | 7 ++- code/server/src/controllers/http/router.ts | 5 +-- code/server/src/databases/memory/Memory.ts | 4 +- .../src/databases/memory/MemoryUsersDB.ts | 14 ++++-- .../databases/postgres/PostgresResourcesDB.ts | 3 -- .../src/databases/postgres/PostgresUsersDB.ts | 10 +++-- code/server/src/databases/types.ts | 20 ++++++++- code/server/src/services/Services.ts | 11 ++--- code/server/src/services/UsersService.ts | 8 +++- code/server/src/services/WorkspacesService.ts | 8 ++++ code/shared/src/users/types.ts | 11 ++++- code/shared/src/workspace/types/workspace.ts | 3 +- 33 files changed, 330 insertions(+), 96 deletions(-) delete mode 100644 code/client/src/ui/contexts/auth/utils.ts rename code/client/src/ui/pages/{login/Login.scss => landing/Landing.scss} (93%) rename code/client/src/ui/pages/{login/Login.tsx => landing/Landing.tsx} (82%) create mode 100644 code/client/src/ui/pages/profile/Profile.scss create mode 100644 code/client/src/ui/pages/profile/Profile.tsx create mode 100644 code/client/src/ui/pages/workspace/components/ManageMembersDialog.tsx diff --git a/code/client/src/App.tsx b/code/client/src/App.tsx index aed182f4..d786e65e 100644 --- a/code/client/src/App.tsx +++ b/code/client/src/App.tsx @@ -10,8 +10,9 @@ import { WorkspaceProvider } from '@ui/contexts/workspace/WorkspaceContext'; import Workspaces from '@ui/pages/workspaces/Workspaces'; import { CommunicationProvider } from '@ui/contexts/communication/CommunicationContext'; import Home from '@ui/pages/home/Home'; -import Login from '@ui/pages/login/Login'; import AuthProvider from '@ui/contexts/auth/AuthContext'; +import Profile from '@ui/pages/profile/Profile'; +import Landing from '@ui/pages/landing/Landing'; function App() { return ( @@ -23,8 +24,9 @@ function App() {
+ } /> @@ -32,7 +34,7 @@ function App() { } /> - } /> + } /> { return await http.get(`/users/${id}`); } @@ -16,6 +17,7 @@ function authService(http: HttpCommunication) { async function deleteUser(id: string) { await http.delete(`/users/${id}`); + Cookies.remove('token'); } return { diff --git a/code/client/src/services/workspace/workspaceService.ts b/code/client/src/services/workspace/workspaceService.ts index 24fb9f72..3350fbd3 100644 --- a/code/client/src/services/workspace/workspaceService.ts +++ b/code/client/src/services/workspace/workspaceService.ts @@ -1,6 +1,7 @@ import { HttpCommunication } from '@services/communication/http/httpCommunication'; import { WorkspaceInputModel, WorkspaceMeta } from '@notespace/shared/src/workspace/types/workspace'; import { Workspace } from '@notespace/shared/src/workspace/types/workspace'; +import { UserData } from '@notespace/shared/src/users/types'; function workspaceService(http: HttpCommunication) { async function getWorkspace(id: string): Promise { @@ -23,12 +24,28 @@ function workspaceService(http: HttpCommunication) { await http.put(`/workspaces/${id}`, newProps); } + async function getWorkspaceMembers(id: string): Promise { + const workspace: WorkspaceMeta = await http.get(`/workspaces/${id}`); + return workspace.members; + } + + async function addWorkspaceMember(id: string, email: string): Promise { + await http.post(`/workspaces/${id}/members`, { email }); + } + + async function removeWorkspaceMember(id: string, email: string): Promise { + await http.delete(`/workspaces/${id}/members`, { email }); + } + return { getWorkspace, getWorkspaces, createWorkspace, deleteWorkspace, updateWorkspace, + getWorkspaceMembers, + addWorkspaceMember, + removeWorkspaceMember, }; } diff --git a/code/client/src/ui/components/dialog/Dialog.tsx b/code/client/src/ui/components/dialog/Dialog.tsx index 840684c1..7802b94b 100644 --- a/code/client/src/ui/components/dialog/Dialog.tsx +++ b/code/client/src/ui/components/dialog/Dialog.tsx @@ -21,10 +21,11 @@ interface DialogProps { fields: Field[]; onSubmit: (values: { [key: string]: any }) => void; submitText?: string; + extraContent?: React.ReactNode; children: React.ReactNode; } -function Dialog({ title, fields, onSubmit, submitText, children }: DialogProps) { +function Dialog({ title, fields, onSubmit, submitText, extraContent, children }: DialogProps) { const [open, setOpen] = useState(false); const [values, setValues] = useState<{ [key: string]: any }>( fields.reduce((obj, item) => ({ ...obj, [item.name]: item.type === 'checkbox' ? false : '' }), {}) @@ -82,6 +83,7 @@ function Dialog({ title, fields, onSubmit, submitText, children }: DialogProps) /> ) )} + {extraContent} diff --git a/code/client/src/ui/components/header/Header.scss b/code/client/src/ui/components/header/Header.scss index bb5a4291..94103245 100644 --- a/code/client/src/ui/components/header/Header.scss +++ b/code/client/src/ui/components/header/Header.scss @@ -11,6 +11,10 @@ justify-content: space-between; align-items: center; + a { + padding-left: 10vh; + } + div { display: flex; align-items: center; diff --git a/code/client/src/ui/components/header/Header.tsx b/code/client/src/ui/components/header/Header.tsx index d837db09..8bac00ee 100644 --- a/code/client/src/ui/components/header/Header.tsx +++ b/code/client/src/ui/components/header/Header.tsx @@ -6,16 +6,16 @@ function Header() { const { currentUser, logout } = useAuth(); return (
-

+ NoteSpace
- {currentUser ? ( -
-

{currentUser?.displayName}

- -
- ) : ( - Login - )} +
+ {currentUser && ( + <> + {currentUser?.displayName} + + + )} +
); diff --git a/code/client/src/ui/components/sidebar/Sidebar.tsx b/code/client/src/ui/components/sidebar/Sidebar.tsx index bfa26a0b..15d089ce 100644 --- a/code/client/src/ui/components/sidebar/Sidebar.tsx +++ b/code/client/src/ui/components/sidebar/Sidebar.tsx @@ -29,7 +29,6 @@ function Sidebar() { )} - NoteSpace