import { Button, FormControl, FormControlLabel, styled, Switch, type Theme, Typography, Link, } 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/KeyboardArrowDownOutlined'; 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'; import type { FeatureNamingType } from 'interfaces/project'; import { FeatureNamingPatternInfo } from '../FeatureNamingPatternInfo/FeatureNamingPatternInfo'; 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>; featureNaming?: FeatureNamingType; validateToggleName?: () => void; handleSubmit: (e: any) => void; handleCancel: () => void; errors: { [key: string]: string }; mode: 'Create' | 'Edit'; clearErrors: () => void; } const StyledForm = styled('form')({ height: '100%', }); const StyledInputDescription = styled('p')(({ theme }) => ({ marginBottom: theme.spacing(1), })); 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, featureNaming, 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; }; const displayFeatureNamingInfo = Boolean(featureNaming?.pattern); React.useEffect(() => { if (featureNaming?.pattern && validateToggleName && name) { clearErrors(); validateToggleName(); } }, [featureNaming?.pattern]); 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;