mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
refactor: remove UI bootstrap endpoint (#1212)
This commit is contained in:
parent
4862ba9dc7
commit
840d5a54dd
@ -13,7 +13,7 @@ import React from 'react';
|
||||
import { useUsers } from 'hooks/api/getters/useUsers/useUsers';
|
||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||
import { EDIT } from 'constants/misc';
|
||||
import useUiBootstrap from 'hooks/api/getters/useUiBootstrap/useUiBootstrap';
|
||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||
|
||||
interface IUserForm {
|
||||
email: string;
|
||||
@ -49,7 +49,7 @@ const UserForm: React.FC<IUserForm> = ({
|
||||
}) => {
|
||||
const { classes: styles } = useStyles();
|
||||
const { roles } = useUsers();
|
||||
const { bootstrap } = useUiBootstrap();
|
||||
const { uiConfig } = useUiConfig();
|
||||
|
||||
// @ts-expect-error
|
||||
const sortRoles = (a, b) => {
|
||||
@ -127,7 +127,7 @@ const UserForm: React.FC<IUserForm> = ({
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
<ConditionallyRender
|
||||
condition={mode !== EDIT && bootstrap?.email}
|
||||
condition={mode !== EDIT && Boolean(uiConfig?.emailEnabled)}
|
||||
show={
|
||||
<FormControl>
|
||||
<Typography
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import useUiBootstrap from 'hooks/api/getters/useUiBootstrap/useUiBootstrap';
|
||||
import { useUsers } from 'hooks/api/getters/useUsers/useUsers';
|
||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||
|
||||
const useCreateUserForm = (
|
||||
initialName = '',
|
||||
initialEmail = '',
|
||||
initialRootRole = 1
|
||||
) => {
|
||||
const { bootstrap } = useUiBootstrap();
|
||||
const { uiConfig } = useUiConfig();
|
||||
const [name, setName] = useState(initialName);
|
||||
const [email, setEmail] = useState(initialEmail);
|
||||
const [sendEmail, setSendEmail] = useState(false);
|
||||
@ -25,8 +25,8 @@ const useCreateUserForm = (
|
||||
}, [initialEmail]);
|
||||
|
||||
useEffect(() => {
|
||||
setSendEmail(bootstrap?.email || false);
|
||||
}, [bootstrap?.email]);
|
||||
setSendEmail(uiConfig?.emailEnabled || false);
|
||||
}, [uiConfig?.emailEnabled]);
|
||||
|
||||
useEffect(() => {
|
||||
setRootRole(initialRootRole);
|
||||
|
@ -1,41 +0,0 @@
|
||||
import handleErrorResponses from '../httpErrorResponseHandler';
|
||||
import useSWR, { mutate, SWRConfiguration } from 'swr';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { formatApiPath } from 'utils/formatPath';
|
||||
|
||||
const useUiBootstrap = (options: SWRConfiguration = {}) => {
|
||||
// The point of the bootstrap is to get multiple datasets in one call. Therefore,
|
||||
// this needs to be refactored to seed other hooks with the correct data.
|
||||
const BOOTSTRAP_CACHE_KEY = `api/admin/ui-bootstrap`;
|
||||
|
||||
const fetcher = () => {
|
||||
const path = formatApiPath(`api/admin/ui-bootstrap`);
|
||||
|
||||
return fetch(path, {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(handleErrorResponses('ui bootstrap'))
|
||||
.then(res => res.json());
|
||||
};
|
||||
|
||||
const { data, error } = useSWR(BOOTSTRAP_CACHE_KEY, fetcher, options);
|
||||
const [loading, setLoading] = useState(!error && !data);
|
||||
|
||||
const refetchUiBootstrap = () => {
|
||||
mutate(BOOTSTRAP_CACHE_KEY);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(!error && !data);
|
||||
}, [data, error]);
|
||||
|
||||
return {
|
||||
bootstrap: data,
|
||||
error,
|
||||
loading,
|
||||
refetchUiBootstrap,
|
||||
};
|
||||
};
|
||||
|
||||
export default useUiBootstrap;
|
@ -12,6 +12,7 @@ export interface IUiConfig {
|
||||
versionInfo?: IVersionInfo;
|
||||
links: ILinks[];
|
||||
disablePasswordAuth?: boolean;
|
||||
emailEnabled?: boolean;
|
||||
toast?: IProclamationToast;
|
||||
segmentValuesLimit?: number;
|
||||
strategySegmentsLimit?: number;
|
||||
|
Loading…
Reference in New Issue
Block a user