From 3c715833240e1f3f7b38da3e850f2f42244b962f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 21 Nov 2025 14:26:41 -0800 Subject: [PATCH] permissions on FE for email settings --- client/src/hooks/UseApi.tsx | 4 ++-- client/src/pages/settings/Settings.tsx | 23 +++++++++++++++------- client/src/pages/settings/SettingsForm.tsx | 4 +++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/client/src/hooks/UseApi.tsx b/client/src/hooks/UseApi.tsx index 271bbbcef..0f6b18fa6 100644 --- a/client/src/hooks/UseApi.tsx +++ b/client/src/hooks/UseApi.tsx @@ -21,7 +21,7 @@ const fetcher = async (url: string, config?: AxiosRequestConfig) => { return res.data; }; export const useGet = ( - url: string, + url: string | null, axiosConfig?: AxiosRequestConfig, swrConfig?: SWRConfiguration, extraConfig?: IExtraConfig @@ -183,7 +183,7 @@ export const useDelete = () => { return { deleteFn, loading, error }; }; -export const useGetOnDemand = () => { +export const useGetOnDemand = () => { const currentTeamId = useAppSelector((state) => state.auth.selectedTeamId); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); diff --git a/client/src/pages/settings/Settings.tsx b/client/src/pages/settings/Settings.tsx index 15f907dab..9b651b837 100644 --- a/client/src/pages/settings/Settings.tsx +++ b/client/src/pages/settings/Settings.tsx @@ -20,6 +20,11 @@ import { systemSettingsSchema } from "@/validation/zod"; const SettingsPage = () => { type FormValues = z.infer; + const user = useAppSelector((state) => state.auth.user); + + const orgPermissions = user?.org?.permissions || []; + const hasMaster = orgPermissions.includes("master"); + const theme = useTheme(); const dispatch = useAppDispatch(); const timezone = useAppSelector((state) => state.ui.timezone); @@ -35,7 +40,9 @@ const SettingsPage = () => { const { post, loading: posting } = usePost, any>(); const { patch, loading: patching } = usePatch, any>(); - const { response, loading } = useGet>("/settings"); + const { response, loading } = useGet>( + hasMaster ? "/settings" : null + ); const settings = response?.data || {}; const initialSettings = useMemo(() => settings, [settings]); @@ -84,12 +91,14 @@ const SettingsPage = () => { } /> - + {hasMaster && ( + + )} ); }; diff --git a/client/src/pages/settings/SettingsForm.tsx b/client/src/pages/settings/SettingsForm.tsx index 5fd8d8dee..12c002e70 100644 --- a/client/src/pages/settings/SettingsForm.tsx +++ b/client/src/pages/settings/SettingsForm.tsx @@ -1,5 +1,6 @@ import Stack from "@mui/material/Stack"; import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; import { Button, TextInput, Switch, TextLink } from "@/components/inputs"; import { ConfigBox } from "@/components/design-elements"; @@ -11,7 +12,8 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { useForm, Controller, type SubmitHandler } from "react-hook-form"; import { useInitForm } from "@/hooks/forms/UseInitSettingsForm"; import { useEffect } from "react"; -import { Typography } from "@mui/material"; +import { useAppSelector } from "@/hooks/AppHooks"; + type FormValues = z.infer; export const SettingsForm = ({