permissions on FE for email settings
This commit is contained in:
1 parent
710d506de2
commit
3c71583324
3 files changed
+21
-10
No files matched your search
@@ -21,7 +21,7 @@ const fetcher = async <T,>(url: string, config?: AxiosRequestConfig) => {
|
|||||||
return res.data;
|
return res.data;
|
||||||
};
|
};
|
||||||
export const useGet = <T,>(
|
export const useGet = <T,>(
|
||||||
url: string,
|
url: string | null,
|
||||||
axiosConfig?: AxiosRequestConfig,
|
axiosConfig?: AxiosRequestConfig,
|
||||||
swrConfig?: SWRConfiguration<T, Error>,
|
swrConfig?: SWRConfiguration<T, Error>,
|
||||||
extraConfig?: IExtraConfig
|
extraConfig?: IExtraConfig
|
||||||
@@ -183,7 +183,7 @@ export const useDelete = <R = any,>() => {
|
|||||||
return { deleteFn, loading, error };
|
return { deleteFn, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetOnDemand = <R = any>() => {
|
export const useGetOnDemand = <R = any,>() => {
|
||||||
const currentTeamId = useAppSelector((state) => state.auth.selectedTeamId);
|
const currentTeamId = useAppSelector((state) => state.auth.selectedTeamId);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ import { systemSettingsSchema } from "@/validation/zod";
|
|||||||
const SettingsPage = () => {
|
const SettingsPage = () => {
|
||||||
type FormValues = z.infer<typeof systemSettingsSchema>;
|
type FormValues = z.infer<typeof systemSettingsSchema>;
|
||||||
|
|
||||||
|
const user = useAppSelector((state) => state.auth.user);
|
||||||
|
|
||||||
|
const orgPermissions = user?.org?.permissions || [];
|
||||||
|
const hasMaster = orgPermissions.includes("master");
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const timezone = useAppSelector((state) => state.ui.timezone);
|
const timezone = useAppSelector((state) => state.ui.timezone);
|
||||||
@@ -35,7 +40,9 @@ const SettingsPage = () => {
|
|||||||
const { post, loading: posting } = usePost<Partial<FormValues>, any>();
|
const { post, loading: posting } = usePost<Partial<FormValues>, any>();
|
||||||
const { patch, loading: patching } = usePatch<Partial<FormValues>, any>();
|
const { patch, loading: patching } = usePatch<Partial<FormValues>, any>();
|
||||||
|
|
||||||
const { response, loading } = useGet<ApiResponse<any>>("/settings");
|
const { response, loading } = useGet<ApiResponse<any>>(
|
||||||
|
hasMaster ? "/settings" : null
|
||||||
|
);
|
||||||
const settings = response?.data || {};
|
const settings = response?.data || {};
|
||||||
const initialSettings = useMemo(() => settings, [settings]);
|
const initialSettings = useMemo(() => settings, [settings]);
|
||||||
|
|
||||||
@@ -84,12 +91,14 @@ const SettingsPage = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<SettingsForm
|
{hasMaster && (
|
||||||
onSubmit={onSubmit}
|
<SettingsForm
|
||||||
onTest={onTest}
|
onSubmit={onSubmit}
|
||||||
initialData={initialSettings}
|
onTest={onTest}
|
||||||
loading={posting || loading || patching}
|
initialData={initialSettings}
|
||||||
/>
|
loading={posting || loading || patching}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</BasePage>
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
import { Button, TextInput, Switch, TextLink } from "@/components/inputs";
|
import { Button, TextInput, Switch, TextLink } from "@/components/inputs";
|
||||||
import { ConfigBox } from "@/components/design-elements";
|
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 { useForm, Controller, type SubmitHandler } from "react-hook-form";
|
||||||
import { useInitForm } from "@/hooks/forms/UseInitSettingsForm";
|
import { useInitForm } from "@/hooks/forms/UseInitSettingsForm";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { Typography } from "@mui/material";
|
import { useAppSelector } from "@/hooks/AppHooks";
|
||||||
|
|
||||||
type FormValues = z.infer<typeof systemSettingsSchema>;
|
type FormValues = z.infer<typeof systemSettingsSchema>;
|
||||||
|
|
||||||
export const SettingsForm = ({
|
export const SettingsForm = ({
|
||||||
|
|||||||
Reference in new issue
Block a user