mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-23 01:16:27 +02:00
cors form frontend
This commit is contained in:
parent
4bb80d2bff
commit
b68059c490
@ -7,23 +7,29 @@ import useToast from 'hooks/useToast';
|
|||||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
import { useId } from 'hooks/useId';
|
import { useId } from 'hooks/useId';
|
||||||
import { ADMIN, UPDATE_CORS } from '@server/types/permissions';
|
import { ADMIN, UPDATE_CORS } from '@server/types/permissions';
|
||||||
|
import { useUiFlag } from 'hooks/useUiFlag';
|
||||||
|
|
||||||
interface ICorsFormProps {
|
interface ICorsFormProps {
|
||||||
frontendApiOrigins: string[] | undefined;
|
frontendApiOrigins: string[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CorsForm = ({ frontendApiOrigins }: ICorsFormProps) => {
|
export const CorsForm = ({ frontendApiOrigins }: ICorsFormProps) => {
|
||||||
const { setFrontendSettings } = useUiConfigApi();
|
const { setFrontendSettings, setCors } = useUiConfigApi();
|
||||||
const { setToastData, setToastApiError } = useToast();
|
const { setToastData, setToastApiError } = useToast();
|
||||||
const [value, setValue] = useState(formatInputValue(frontendApiOrigins));
|
const [value, setValue] = useState(formatInputValue(frontendApiOrigins));
|
||||||
const inputFieldId = useId();
|
const inputFieldId = useId();
|
||||||
const helpTextId = useId();
|
const helpTextId = useId();
|
||||||
|
const isGranularPermissionsEnabled = useUiFlag('granularAdminPermissions');
|
||||||
|
|
||||||
const onSubmit = async (event: React.FormEvent) => {
|
const onSubmit = async (event: React.FormEvent) => {
|
||||||
try {
|
try {
|
||||||
const split = parseInputValue(value);
|
const split = parseInputValue(value);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
await setFrontendSettings(split);
|
if (isGranularPermissionsEnabled) {
|
||||||
|
await setCors(split);
|
||||||
|
} else {
|
||||||
|
await setFrontendSettings(split);
|
||||||
|
}
|
||||||
setValue(formatInputValue(split));
|
setValue(formatInputValue(split));
|
||||||
setToastData({ text: 'Settings saved', type: 'success' });
|
setToastData({ text: 'Settings saved', type: 'success' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -5,6 +5,9 @@ export const useUiConfigApi = () => {
|
|||||||
propagateErrors: true,
|
propagateErrors: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated remove when `granularAdminPermissions` flag is removed
|
||||||
|
*/
|
||||||
const setFrontendSettings = async (
|
const setFrontendSettings = async (
|
||||||
frontendApiOrigins: string[],
|
frontendApiOrigins: string[],
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
@ -19,8 +22,18 @@ export const useUiConfigApi = () => {
|
|||||||
await makeRequest(req.caller, req.id);
|
await makeRequest(req.caller, req.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setCors = async (frontendApiOrigins: string[]): Promise<void> => {
|
||||||
|
const req = createRequest(
|
||||||
|
'api/admin/ui-config/cors',
|
||||||
|
{ method: 'POST', body: JSON.stringify({ frontendApiOrigins }) },
|
||||||
|
'setCors',
|
||||||
|
);
|
||||||
|
await makeRequest(req.caller, req.id);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setFrontendSettings,
|
setFrontendSettings,
|
||||||
|
setCors,
|
||||||
loading,
|
loading,
|
||||||
errors,
|
errors,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user