Finished translations / bug fixes
This commit is contained in:
@@ -1,16 +1,28 @@
|
||||
import { FC, useState } from 'react'
|
||||
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'
|
||||
|
||||
export const Preferences: FC = () => {
|
||||
interface Handle {
|
||||
addGroup(preferredName: string, exported?: string[], mall?: string[]): boolean
|
||||
}
|
||||
|
||||
const PreferencesBase: ForwardRefRenderFunction<Handle> = (_, 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(
|
||||
i18n(intl, 'page.home.group.add.default_group_name')
|
||||
)
|
||||
const [newGroupValue, setNewGroupValue] = useState(DEFAULT_NAME)
|
||||
return (
|
||||
<>
|
||||
<fieldset>
|
||||
@@ -49,7 +61,7 @@ export const Preferences: FC = () => {
|
||||
disabled={!newGroupValue}
|
||||
onClick={() => {
|
||||
addGroup(newGroupValue)
|
||||
setNewGroupValue('New group')
|
||||
setNewGroupValue(DEFAULT_NAME)
|
||||
}}
|
||||
>
|
||||
<I18n id={'page.home.group.add.button_text'} values={{ name: newGroupValue }} />
|
||||
@@ -58,3 +70,5 @@ export const Preferences: FC = () => {
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export const Preferences = forwardRef(PreferencesBase)
|
||||
|
||||
Reference in New Issue
Block a user