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

Fix 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 48c323c1a1
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, idx) => (
<DeviceForm <DeviceForm
key={device.id} key={device.id}
formData={device} formData={device}
formErrors={(formErrors || [])[device.id]} deviceNumber={idx}
formErrors={(formErrors || [])[idx]}
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,
deviceNumber: 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, deviceNumber, ...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: { [deviceNumber]: { 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: {
[deviceNumber]: {
SSID: { $set: value },
},
},
}),
)} )}
{...props} {...props}
@ -121,7 +129,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ( (value) => (
{ devices: { [deviceID]: { password: { $set: value } } } } { devices: { [deviceNumber]: { password: { $set: value } } } }
), ),
)} )}
@ -135,7 +143,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ( (value) => (
{ devices: { [deviceID]: { hidden: { $set: value } } } } { devices: { [deviceNumber]: { hidden: { $set: value } } } }
), ),
)} )}
@ -152,7 +160,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ({ (value) => ({
devices: { devices: {
[deviceID]: { [deviceNumber]: {
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: { [deviceNumber]: { htmode: { $set: value } } } }
), ),
)} )}
@ -185,7 +193,7 @@ function DeviceForm({
onChange={setFormValue( onChange={setFormValue(
(value) => ( (value) => (
{ devices: { [deviceID]: { channel: { $set: value } } } } { devices: { [deviceNumber]: { channel: { $set: value } } } }
), ),
)} )}
@ -194,7 +202,7 @@ function DeviceForm({
{hasGuestNetwork && ( {hasGuestNetwork && (
<WifiGuestForm <WifiGuestForm
formData={{ id: deviceID, ...formData.guest_wifi }} formData={{ id: deviceNumber, ...formData.guest_wifi }}
formErrors={formErrors.guest_wifi || {}} formErrors={formErrors.guest_wifi || {}}
setFormValue={setFormValue} setFormValue={setFormValue}