/* * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; import PropTypes from "prop-types"; import { HELP_TEXTS, HTMODES, BANDS, ENCRYPTIONMODES } from "./constants"; import WifiGuestForm from "./WiFiGuestForm"; import WiFiQRCode from "./WiFiQRCode"; import PasswordInput from "../../bootstrap/PasswordInput"; import RadioSet from "../../bootstrap/RadioSet"; import Select from "../../bootstrap/Select"; import Switch from "../../bootstrap/Switch"; import TextInput from "../../bootstrap/TextInput"; WiFiForm.propTypes = { formData: PropTypes.shape({ devices: PropTypes.arrayOf(PropTypes.object) }) .isRequired, formErrors: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), setFormValue: PropTypes.func.isRequired, hasGuestNetwork: PropTypes.bool, }; WiFiForm.defaultProps = { formData: { devices: [] }, setFormValue: () => {}, hasGuestNetwork: true, }; export default function WiFiForm({ formData, formErrors, setFormValue, hasGuestNetwork, disabled, }) { return formData.devices.map((device, index) => ( )); } DeviceForm.propTypes = { formData: PropTypes.shape({ id: PropTypes.number.isRequired, enabled: PropTypes.bool.isRequired, SSID: PropTypes.string.isRequired, password: PropTypes.string.isRequired, hidden: PropTypes.bool.isRequired, band: PropTypes.string.isRequired, htmode: PropTypes.string.isRequired, channel: PropTypes.string.isRequired, guest_wifi: PropTypes.object.isRequired, encryption: PropTypes.string.isRequired, available_bands: PropTypes.array.isRequired, ieee80211w_disabled: PropTypes.bool, }), formErrors: PropTypes.object.isRequired, setFormValue: PropTypes.func.isRequired, hasGuestNetwork: PropTypes.bool, deviceIndex: PropTypes.number, divider: PropTypes.bool, }; DeviceForm.defaultProps = { formErrors: {}, hasGuestNetwork: true, }; function DeviceForm({ formData, formErrors, setFormValue, hasGuestNetwork, deviceIndex, divider, ...props }) { const deviceID = formData.id; const bnds = formData.available_bands; return ( <> {_(`Wi-Fi ${deviceID + 1}`)}} checked={formData.enabled} onChange={setFormValue((value) => ({ devices: { [deviceIndex]: { enabled: { $set: value } }, }, }))} switchHeading {...props} /> {formData.enabled && ( <> ({ devices: { [deviceIndex]: { SSID: { $set: value }, }, }, }))} {...props} > ({ devices: { [deviceIndex]: { password: { $set: value } }, }, }))} {...props} /> ({ devices: { [deviceIndex]: { hidden: { $set: value } }, }, }))} {...props} /> { // Find the selected band const selectedBand = bnds.find( (band) => band.band === value ); // Get the last item in the available HT modes for the selected band const bestHtmode = selectedBand.available_htmodes.slice(-1)[0]; return { devices: { [deviceIndex]: { band: { $set: value }, channel: { $set: "0" }, htmode: { $set: bestHtmode }, }, }, }; })} {...props} /> ({ devices: { [deviceIndex]: { channel: { $set: value } }, }, }))} {...props} />