import { Button, FormControl, FormControlLabel, styled, Switch, Theme, Typography, } from '@mui/material'; import FeatureTypeSelect from '../FeatureView/FeatureSettings/FeatureSettingsMetadata/FeatureTypeSelect/FeatureTypeSelect'; import { CF_DESC_ID, CF_NAME_ID, CF_TYPE_ID } from 'utils/testIds'; import useFeatureTypes from 'hooks/api/getters/useFeatureTypes/useFeatureTypes'; import { KeyboardArrowDownOutlined } from '@mui/icons-material'; import { projectFilterGenerator } from 'utils/projectFilterGenerator'; import FeatureProjectSelect from '../FeatureView/FeatureSettings/FeatureSettingsProject/FeatureProjectSelect/FeatureProjectSelect'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { trim } from 'component/common/util'; import Input from 'component/common/Input/Input'; import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions'; import { useNavigate } from 'react-router-dom'; import React from 'react'; import { useAuthPermissions } from 'hooks/api/getters/useAuth/useAuthPermissions'; interface IFeatureToggleForm { type: string; name: string; description: string; project: string; impressionData: boolean; setType: React.Dispatch>; setName: React.Dispatch>; setDescription: React.Dispatch>; setProject: React.Dispatch>; setImpressionData: React.Dispatch>; validateToggleName?: () => void; handleSubmit: (e: any) => void; handleCancel: () => void; errors: { [key: string]: string }; mode: 'Create' | 'Edit'; clearErrors: () => void; } const StyledForm = styled('form')({ display: 'flex', flexDirection: 'column', height: '100%', }); const StyledContainer = styled('div')({ maxWidth: '400px', }); const StyledInputDescription = styled('p')(({ theme }) => ({ marginBottom: theme.spacing(1), color: theme.palette.text.secondary, })); const StyledInput = styled(Input)(({ theme }) => ({ width: '100%', marginBottom: theme.spacing(2), })); const StyledFormControl = styled(FormControl)(({ theme }) => ({ width: '100%', marginBottom: theme.spacing(2), })); const styledSelectInput = (theme: Theme) => ({ marginBottom: theme.spacing(2), minWidth: '400px', [theme.breakpoints.down('sm')]: { minWidth: '379px', }, }); const StyledTypeDescription = styled('p')(({ theme }) => ({ fontSize: theme.fontSizes.smallBody, color: theme.palette.text.secondary, top: '-13px', position: 'relative', })); const StyledButtonContainer = styled('div')({ marginTop: 'auto', display: 'flex', justifyContent: 'flex-end', }); const StyledRow = styled('div')(({ theme }) => ({ display: 'flex', alignItems: 'center', marginTop: theme.spacing(1), })); const StyledCancelButton = styled(Button)(({ theme }) => ({ marginLeft: theme.spacing(3), })); const styledTypography = (theme: Theme) => ({ margin: theme.spacing(1, 0), }); const FeatureForm: React.FC = ({ children, type, name, description, project, setType, setName, setDescription, setProject, validateToggleName, setImpressionData, impressionData, handleSubmit, handleCancel, errors, mode, clearErrors, }) => { const { featureTypes } = useFeatureTypes(); const navigate = useNavigate(); const { permissions } = useAuthPermissions(); const editable = mode !== 'Edit'; const renderToggleDescription = () => { return featureTypes.find(toggle => toggle.id === type)?.description; }; return ( What would you like to call your toggle? clearErrors()} value={name} onChange={e => setName(trim(e.target.value))} data-testid={CF_NAME_ID} onBlur={validateToggleName} /> What kind of feature toggle do you want? {renderToggleDescription()} In which project do you want to save the toggle? } /> { setProject(projectId); navigate(`/projects/${projectId}/create-toggle`, { replace: true, }); }} enabled={editable} filter={projectFilterGenerator(permissions, CREATE_FEATURE)} IconComponent={KeyboardArrowDownOutlined} sx={styledSelectInput} /> How would you describe your feature toggle? setDescription(e.target.value)} /> Impression Data

When you enable impression data for a feature toggle, your client SDKs will emit events you can listen for every time this toggle gets triggered. Learn more in{' '} the impression data documentation

setImpressionData(!impressionData) } checked={impressionData} /> } label="Enable impression data" />
{children} Cancel
); }; export default FeatureForm;