diff --git a/web/src/App.tsx b/web/src/App.tsx index 63f253a..9401f55 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -7,7 +7,7 @@ function App() { return ( - + ); } diff --git a/web/src/components/Header.tsx b/web/src/components/Header.tsx index 2201de9..47090e9 100644 --- a/web/src/components/Header.tsx +++ b/web/src/components/Header.tsx @@ -32,10 +32,10 @@ const Header: React.FC = () => { actions={ <> - My Account + Setting { + const user = useAppSelector((state) => state.user).user as User; + const [showEditUserinfoDialog, setShowEditUserinfoDialog] = useState(false); + const [showChangePasswordDialog, setShowChangePasswordDialog] = useState(false); + + return ( + <> + + Account + {user.nickname} + + Email: + {user.email} + + + setShowEditUserinfoDialog(true)}> + Edit + + setShowChangePasswordDialog(true)}> + Change password + + + + + {showEditUserinfoDialog && setShowEditUserinfoDialog(false)} />} + + {showChangePasswordDialog && setShowChangePasswordDialog(false)} />} + > + ); +}; + +export default AccountSection; diff --git a/web/src/components/setting/WorkspaceSection.tsx b/web/src/components/setting/WorkspaceSection.tsx new file mode 100644 index 0000000..ec8c928 --- /dev/null +++ b/web/src/components/setting/WorkspaceSection.tsx @@ -0,0 +1,32 @@ +import { Switch } from "@mui/joy"; +import { useEffect, useState } from "react"; +import { getSystemStatus, upsertWorkspaceSetting } from "../../helpers/api"; + +const WorkspaceSection: React.FC = () => { + const [disallowSignUp, setDisallowSignUp] = useState(false); + + useEffect(() => { + getSystemStatus().then(({ data }) => { + setDisallowSignUp(data.disallowSignUp); + }); + }, []); + + const handleDisallowSignUpChange = async (value: boolean) => { + await upsertWorkspaceSetting("disallow-signup", JSON.stringify(value)); + setDisallowSignUp(value); + }; + + return ( + <> + + Workspace settings + + Allow sign up + handleDisallowSignUpChange(event.target.checked)} /> + + + > + ); +}; + +export default WorkspaceSection; diff --git a/web/src/helpers/api.ts b/web/src/helpers/api.ts index 8fcd0d0..50adfca 100644 --- a/web/src/helpers/api.ts +++ b/web/src/helpers/api.ts @@ -64,3 +64,10 @@ export function patchShortcut(shortcutPatch: ShortcutPatch) { export function deleteShortcutById(shortcutId: ShortcutId) { return axios.delete(`/api/v1/shortcut/${shortcutId}`); } + +export function upsertWorkspaceSetting(key: string, value: string) { + return axios.post(`/api/v1/workspace/setting`, { + key, + value, + }); +} diff --git a/web/src/pages/Setting.tsx b/web/src/pages/Setting.tsx new file mode 100644 index 0000000..76fd4bb --- /dev/null +++ b/web/src/pages/Setting.tsx @@ -0,0 +1,17 @@ +import { useAppSelector } from "../stores"; +import AccountSection from "../components/setting/AccountSection"; +import WorkspaceSection from "../components/setting/WorkspaceSection"; + +const Setting: React.FC = () => { + const user = useAppSelector((state) => state.user).user as User; + const isAdmin = user.role === "ADMIN"; + + return ( + + + {isAdmin && } + + ); +}; + +export default Setting; diff --git a/web/src/routers/index.tsx b/web/src/routers/index.tsx index 3210fc1..65b68f0 100644 --- a/web/src/routers/index.tsx +++ b/web/src/routers/index.tsx @@ -4,7 +4,7 @@ import { userService } from "../services"; import Root from "../layouts/Root"; import Auth from "../pages/Auth"; import Home from "../pages/Home"; -import Account from "../pages/Account"; +import Setting from "../pages/Setting"; const router = createBrowserRouter([ { @@ -33,8 +33,8 @@ const router = createBrowserRouter([ }, }, { - path: "/account", - element: , + path: "/setting", + element: , loader: async () => { try { await userService.initialState(); diff --git a/web/src/types/modules/system.d.ts b/web/src/types/modules/system.d.ts index a48b06c..bc16037 100644 --- a/web/src/types/modules/system.d.ts +++ b/web/src/types/modules/system.d.ts @@ -5,4 +5,5 @@ interface Profile { interface SystemStatus { profile: Profile; + disallowSignUp: boolean; }
Account
{user.nickname}
+ Email: + {user.email} +
Workspace settings