Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const EditFieldDialog = ({ field, onSubmit, ...props }: Props) => {
const [current, setCurrent] = useState(null);
const [isNewField, setIsNewField] = useState(false);
const [screen, setScreen] = useState();
const { getFieldPlugin } = useFormEditor();
const i18n = useI18N();
useEffect(() => {
setCurrent(cloneDeep(field));
if (field) {
setIsNewField(!field._id);
setScreen(field.type ? "fieldOptions" : "fieldType");
}
}, [field]);
const onClose = useCallback(() => {
setCurrent(null);
props.onClose();
});
let render = null;
let headerTitle = t`Field Settings`;
const ValidatorsTab = props => {
const i18n = useI18N();
const { getFieldPlugin } = useFormEditor();
const {
field,
form: { Bind }
} = props;
const fieldType = getFieldPlugin({ name: field.name });
const validators = useMemo(() => {
return getPlugins("form-editor-field-validator")
.map(plugin => plugin.validator)
.map(validator => {
if (fieldType.field.validators.includes(validator.name)) {
return { optional: true, validator: validator };
} else if (fieldType.field.validators.includes(`!${validator.name}`)) {
return { optional: false, validator: validator };