import { forwardRef, ForwardRefRenderFunction, useImperativeHandle, useState } from 'react' import { FactorySelect } from '../FactorySelect/FactorySelect' import { useGroups } from '../../contexts/GroupProvider' import { i18n, I18n } from '../../shared/I18n/I18n' import { useIntl } from 'react-intl' interface Handle { addGroup(preferredName: string, exported?: string[], mall?: string[]): boolean } const PreferencesBase: ForwardRefRenderFunction = (_, forwardedRef) => { const intl = useIntl() const DEFAULT_NAME = i18n(intl, 'page.home.group.add.default_group_name') useImperativeHandle(forwardedRef, () => ({ addGroup(preferredName: string, exported?: string[], mall?: string[]) { const name = newGroupValue !== DEFAULT_NAME ? newGroupValue : preferredName const result = addGroup(name, exported, mall) result && setNewGroupValue(DEFAULT_NAME) return result } })) const { addGroup, baseFactories, setBaseFactories, ignoredFactories, setIgnoredFactories } = useGroups() const [newGroupValue, setNewGroupValue] = useState(DEFAULT_NAME) return ( <>
setNewGroupValue(e.target.value)} />
) } export const Preferences = forwardRef(PreferencesBase)