1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-24 00:01:36 +01:00

Fix a Wi-Fi Form bug with additional Wi-Fi modules

This commit is contained in:
Aleksandr Gumroian 2020-07-17 12:15:40 +02:00
parent 57f1ccced8
commit cea8aa0c12
No known key found for this signature in database
GPG Key ID: 9E77849C64F0A733

View File

@ -31,18 +31,19 @@ WiFiForm.propTypes = {
WiFiForm.defaultProps = { WiFiForm.defaultProps = {
formData: { devices: [] }, formData: { devices: [] },
setFormValue: () => {}, setFormValue: () => { },
hasGuestNetwork: true, hasGuestNetwork: true,
}; };
export default function WiFiForm({ export default function WiFiForm({
formData, formErrors, setFormValue, hasGuestNetwork, disabled, formData, formErrors, setFormValue, hasGuestNetwork, disabled,
}) { }) {
return formData.devices.map((device) => ( return formData.devices.map((device, index) => (
<DeviceForm <DeviceForm
key={device.id} key={device.id}
formData={device} formData={device}
formErrors={(formErrors || [])[device.id]} deviceIndex={index}
formErrors={(formErrors || [])[index]}
setFormValue={setFormValue} setFormValue={setFormValue}
hasGuestNetwork={hasGuestNetwork} hasGuestNetwork={hasGuestNetwork}
disabled={disabled} disabled={disabled}
@ -65,6 +66,7 @@ DeviceForm.propTypes = {
formErrors: PropTypes.object.isRequired, formErrors: PropTypes.object.isRequired,
setFormValue: PropTypes.func.isRequired, setFormValue: PropTypes.func.isRequired,
hasGuestNetwork: PropTypes.bool, hasGuestNetwork: PropTypes.bool,
deviceIndex: PropTypes.number,
}; };
DeviceForm.defaultProps = { DeviceForm.defaultProps = {
@ -73,7 +75,7 @@ DeviceForm.defaultProps = {
}; };
function DeviceForm({ function DeviceForm({
formData, formErrors, setFormValue, hasGuestNetwork, ...props formData, formErrors, setFormValue, hasGuestNetwork, deviceIndex, ...props
}) { }) {
const deviceID = formData.id; const deviceID = formData.id;
return ( return (
@ -84,7 +86,7 @@ function DeviceForm({
checked={formData.enabled} checked={formData.enabled}
onChange={setFormValue( onChange={setFormValue(
(value) => ({ devices: { [deviceID]: { enabled: { $set: value } } } }), (value) => ({ devices: { [deviceIndex]: { enabled: { $set: value } } } }),
)} )}
{...props} {...props}
@ -98,7 +100,13 @@ function DeviceForm({
error={formErrors.SSID || null} error={formErrors.SSID || null}
required required
onChange={setFormValue( onChange={setFormValue(
(value) => ({ devices: { [deviceID]: { SSID: { $set: value } } } }), (value) => ({
devices: {
[deviceIndex]: {
SSID: { $set: value },
},
},
}),
)} )}
{...props} {...props}
@ -121,7 +129,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ( (value) => (
{ devices: { [deviceID]: { password: { $set: value } } } } { devices: { [deviceIndex]: { password: { $set: value } } } }
), ),
)} )}
@ -135,7 +143,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ( (value) => (
{ devices: { [deviceID]: { hidden: { $set: value } } } } { devices: { [deviceIndex]: { hidden: { $set: value } } } }
), ),
)} )}
@ -152,7 +160,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ({ (value) => ({
devices: { devices: {
[deviceID]: { [deviceIndex]: {
hwmode: { $set: value }, hwmode: { $set: value },
channel: { $set: "0" }, channel: { $set: "0" },
}, },
@ -171,7 +179,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ( (value) => (
{ devices: { [deviceID]: { htmode: { $set: value } } } } { devices: { [deviceIndex]: { htmode: { $set: value } } } }
), ),
)} )}
@ -185,7 +193,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ( (value) => (
{ devices: { [deviceID]: { channel: { $set: value } } } } { devices: { [deviceIndex]: { channel: { $set: value } } } }
), ),
)} )}
@ -194,7 +202,7 @@ function DeviceForm({
{hasGuestNetwork && ( {hasGuestNetwork && (
<WifiGuestForm <WifiGuestForm
formData={{ id: deviceID, ...formData.guest_wifi }} formData={{ id: deviceIndex, ...formData.guest_wifi }}
formErrors={formErrors.guest_wifi || {}} formErrors={formErrors.guest_wifi || {}}
setFormValue={setFormValue} setFormValue={setFormValue}