export const ConditionsSettings: React.FunctionComponent = () => {
const dispatch = useDispatch()
const conditionsSettingsTypes = useSelector((state: RootState) => state.conditionsSettings.data)
const conditionsSettingsTypesValues = useSelector((state: RootState) => state.conditionsSettingsTypesValues.data)
const conditions = useSelector((state: RootState) => state.conditions.data)
const [condition, setCondition] = useState(1)
const [activeConditionType, setActiveConditionType] = useState(1)
const [, forceUpdate] = useState()
const activeConditionTypeHandler = (key: any) => {
setActiveConditionType(key)
}
const conditionHandler: any = (key: number) => {
setCondition(key)
}
useEffect(() => {
dispatch(loadConditionsSettings())
}, [])
useEffect(() => {
dispatch(loadConditionsTypesValues(condition))
}, [condition])
useEffect(() => {
dispatch(loadConditions())
}, [])
function renderCheckboxes(): ReactNode {
const values = conditionsSettingsTypesValues.map((item: ConditionsSettingsTypesValues) => {
return <Checkbox key={item.id}>{item.description}</Checkbox>
})
return values
}
function renderTabPanes(): ReactNode {
const types = conditionsSettingsTypes.map((item: ConditionsSettingsTabe) => {
return <TabPane tab={item.description} key={item.id}>{renderCheckboxes()}</TabPane>
})
return types
}
function renderConditionsTabPanes(): ReactNode {
const result = conditions.find((item: Conditions) => item.id === activeConditionType)
return <TabPane tab={result && result.description} key={result && result.id} />
}
return (
<div>
<Tabs centered onChange={activeConditionTypeHandler}>
{renderTabPanes()}
</Tabs>
<Tabs onChange={activeConditionTypeHandler}>
{renderConditionsTabPanes()}
</Tabs>
</div>
)
}
<Tabs centered onChange={activeConditionTypeHandler}>
{renderTabPanes()}
</Tabs>