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 { useId } from 'hooks/useId';
|
||||
import { ADMIN, UPDATE_CORS } from '@server/types/permissions';
|
||||
import { useUiFlag } from 'hooks/useUiFlag';
|
||||
|
||||
interface ICorsFormProps {
|
||||
frontendApiOrigins: string[] | undefined;
|
||||
}
|
||||
|
||||
export const CorsForm = ({ frontendApiOrigins }: ICorsFormProps) => {
|
||||
const { setFrontendSettings } = useUiConfigApi();
|
||||
const { setFrontendSettings, setCors } = useUiConfigApi();
|
||||
const { setToastData, setToastApiError } = useToast();
|
||||
const [value, setValue] = useState(formatInputValue(frontendApiOrigins));
|
||||
const inputFieldId = useId();
|
||||
const helpTextId = useId();
|
||||
const isGranularPermissionsEnabled = useUiFlag('granularAdminPermissions');
|
||||
|
||||
const onSubmit = async (event: React.FormEvent) => {
|
||||
try {
|
||||
const split = parseInputValue(value);
|
||||
event.preventDefault();
|
||||
await setFrontendSettings(split);
|
||||
if (isGranularPermissionsEnabled) {
|
||||
await setCors(split);
|
||||
} else {
|
||||
await setFrontendSettings(split);
|
||||
}
|
||||
setValue(formatInputValue(split));
|
||||
setToastData({ text: 'Settings saved', type: 'success' });
|
||||
} catch (error) {
|
||||
|
@ -5,6 +5,9 @@ export const useUiConfigApi = () => {
|
||||
propagateErrors: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* @deprecated remove when `granularAdminPermissions` flag is removed
|
||||
*/
|
||||
const setFrontendSettings = async (
|
||||
frontendApiOrigins: string[],
|
||||
): Promise<void> => {
|
||||
@ -19,8 +22,18 @@ export const useUiConfigApi = () => {
|
||||
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 {
|
||||
setFrontendSettings,
|
||||
setCors,
|
||||
loading,
|
||||
errors,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user