import React from 'react'; import { useFormik } from 'formik'; import { useDispatch } from 'react-redux'; import StyledWrapper from './StyledWrapper'; import toast from 'react-hot-toast'; import { updateBrunoConfig } from 'providers/ReduxStore/slices/collections/actions'; import cloneDeep from 'lodash/cloneDeep'; import { useBetaFeature, BETA_FEATURES } from 'utils/beta-features'; const PresetsSettings = ({ collection }) => { const dispatch = useDispatch(); const isGrpcEnabled = useBetaFeature(BETA_FEATURES.GRPC); const { brunoConfig: { presets: presets = {} } } = collection; const formik = useFormik({ enableReinitialize: true, initialValues: { requestType: presets.requestType === 'grpc' && !isGrpcEnabled ? 'http' : presets.requestType || 'http', requestUrl: presets.requestUrl || '' }, onSubmit: (newPresets) => { // If gRPC is disabled but the preset is set to grpc, change it to http if (!isGrpcEnabled && newPresets.requestType === 'grpc') { newPresets.requestType = 'http'; } const brunoConfig = cloneDeep(collection.brunoConfig); brunoConfig.presets = newPresets; dispatch(updateBrunoConfig(brunoConfig, collection.uid)); toast.success('Collection presets updated'); } }); return (
These presets will be used as the default values for new requests in this collection.
{isGrpcEnabled && ( <> )}
); }; export default PresetsSettings;