import React, { ReactElement, useEffect, useState, useContext } from "react"; import { Form, Field } from "react-final-form"; import { useDispatch } from "react-redux"; import { isEmpty, isNil, isUndefined } from "lodash"; import Select from "react-select"; import { saveSettings } from "../../actions/settings.actions"; import { AirDCPPSocketContext } from "../../context/AirDCPPSocket"; export const AirDCPPHubsForm = (airDCPPClientUserSettings): ReactElement => { const dispatch = useDispatch(); const [hubList, setHubList] = useState([]); const airDCPPConfiguration = useContext(AirDCPPSocketContext); const { airDCPPState: { settings, socket }, } = airDCPPConfiguration; useEffect(() => { (async () => { if (!isEmpty(settings)) { const hubs = await socket.get(`hubs`); const hubSelectionOptions = hubs.map(({ hub_url, identity }) => ({ value: hub_url, label: identity.name, })); setHubList(hubSelectionOptions); } })(); }, []); const onSubmit = (values) => { if (!isUndefined(values.hubs)) { dispatch(saveSettings({ ...settings, hubs: values.hubs }, settings._id)); } }; const validate = async () => {}; const SelectAdapter = ({ input, ...rest }) => { return