mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-08-12 21:03:45 +02:00
Format all files with Prettier
This commit is contained in:
@@ -25,11 +25,10 @@ export default function ResetWiFiSettings({ ws, endpoint }) {
|
||||
|
||||
useEffect(() => {
|
||||
const module = "wifi";
|
||||
ws.subscribe(module)
|
||||
.bind(module, "reset", () => {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
});
|
||||
ws.subscribe(module).bind(module, "reset", () => {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
setTimeout(() => location.reload(), 1000);
|
||||
});
|
||||
}, [ws]);
|
||||
|
||||
const [postResetResponse, postReset] = useAPIPost(endpoint);
|
||||
@@ -38,7 +37,10 @@ export default function ResetWiFiSettings({ ws, endpoint }) {
|
||||
if (postResetResponse.state === API_STATE.ERROR) {
|
||||
setAlert(_("An error occurred during resetting Wi-Fi settings."));
|
||||
} else if (postResetResponse.state === API_STATE.SUCCESS) {
|
||||
setAlert(_("Wi-Fi settings are set to defaults."), ALERT_TYPES.SUCCESS);
|
||||
setAlert(
|
||||
_("Wi-Fi settings are set to defaults."),
|
||||
ALERT_TYPES.SUCCESS
|
||||
);
|
||||
}
|
||||
}, [postResetResponse, setAlert]);
|
||||
|
||||
@@ -63,7 +65,6 @@ current Wi-Fi configuration and restore the default values.
|
||||
forisFormSize
|
||||
loading={isLoading}
|
||||
disabled={isLoading}
|
||||
|
||||
onClick={onReset}
|
||||
>
|
||||
{_("Reset Wi-Fi Settings")}
|
||||
|
@@ -12,7 +12,10 @@ import PropTypes from "prop-types";
|
||||
import { ForisURLs } from "../../utils/forisUrls";
|
||||
import { Button } from "../../bootstrap/Button";
|
||||
import {
|
||||
Modal, ModalBody, ModalFooter, ModalHeader,
|
||||
Modal,
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
} from "../../bootstrap/Modal";
|
||||
import { createAndDownloadPdf, toQRCodeContent } from "./qrCodeHelpers";
|
||||
|
||||
@@ -36,11 +39,21 @@ export default function WiFiQRCode({ SSID, password }) {
|
||||
setModal(true);
|
||||
}}
|
||||
>
|
||||
<img width="20" src={QR_ICON_PATH} alt="QR" style={{ opacity: 0.67 }} />
|
||||
<img
|
||||
width="20"
|
||||
src={QR_ICON_PATH}
|
||||
alt="QR"
|
||||
style={{ opacity: 0.67 }}
|
||||
/>
|
||||
</button>
|
||||
{modal
|
||||
? <QRCodeModal setShown={setModal} shown={modal} SSID={SSID} password={password} />
|
||||
: null}
|
||||
{modal ? (
|
||||
<QRCodeModal
|
||||
setShown={setModal}
|
||||
shown={modal}
|
||||
SSID={SSID}
|
||||
password={password}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -52,9 +65,7 @@ QRCodeModal.propTypes = {
|
||||
setShown: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
function QRCodeModal({
|
||||
shown, setShown, SSID, password,
|
||||
}) {
|
||||
function QRCodeModal({ shown, setShown, SSID, password }) {
|
||||
return (
|
||||
<Modal setShown={setShown} shown={shown}>
|
||||
<ModalHeader setShown={setShown} title={_("Wi-Fi QR Code")} />
|
||||
|
@@ -19,9 +19,7 @@ WiFiSettings.propTypes = {
|
||||
hasGuestNetwork: PropTypes.bool,
|
||||
};
|
||||
|
||||
export function WiFiSettings({
|
||||
ws, endpoint, resetEndpoint, hasGuestNetwork,
|
||||
}) {
|
||||
export function WiFiSettings({ ws, endpoint, resetEndpoint, hasGuestNetwork }) {
|
||||
return (
|
||||
<>
|
||||
<ForisForm
|
||||
@@ -59,35 +57,41 @@ function prepDataToSubmit(formData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!device.guest_wifi.enabled) formData.devices[idx].guest_wifi = { enabled: false };
|
||||
if (!device.guest_wifi.enabled)
|
||||
formData.devices[idx].guest_wifi = { enabled: false };
|
||||
});
|
||||
return formData;
|
||||
}
|
||||
|
||||
export function validator(formData) {
|
||||
const formErrors = formData.devices.map(
|
||||
(device) => {
|
||||
if (!device.enabled) return {};
|
||||
const formErrors = formData.devices.map((device) => {
|
||||
if (!device.enabled) return {};
|
||||
|
||||
const errors = {};
|
||||
if (device.SSID.length > 32) errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||
if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty");
|
||||
const errors = {};
|
||||
if (device.SSID.length > 32)
|
||||
errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||
if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty");
|
||||
|
||||
if (device.password.length < 8) errors.password = _("Password must contain at least 8 symbols");
|
||||
if (device.password.length < 8)
|
||||
errors.password = _("Password must contain at least 8 symbols");
|
||||
|
||||
if (!device.guest_wifi.enabled) return errors;
|
||||
if (!device.guest_wifi.enabled) return errors;
|
||||
|
||||
const guest_wifi_errors = {};
|
||||
if (device.guest_wifi.SSID.length > 32) guest_wifi_errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||
if (device.guest_wifi.SSID.length === 0) guest_wifi_errors.SSID = _("SSID can't be empty");
|
||||
const guest_wifi_errors = {};
|
||||
if (device.guest_wifi.SSID.length > 32)
|
||||
guest_wifi_errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||
if (device.guest_wifi.SSID.length === 0)
|
||||
guest_wifi_errors.SSID = _("SSID can't be empty");
|
||||
|
||||
if (device.guest_wifi.password.length < 8) guest_wifi_errors.password = _("Password must contain at least 8 symbols");
|
||||
if (device.guest_wifi.password.length < 8)
|
||||
guest_wifi_errors.password = _(
|
||||
"Password must contain at least 8 symbols"
|
||||
);
|
||||
|
||||
if (guest_wifi_errors.SSID || guest_wifi_errors.password) {
|
||||
errors.guest_wifi = guest_wifi_errors;
|
||||
}
|
||||
return errors;
|
||||
},
|
||||
);
|
||||
if (guest_wifi_errors.SSID || guest_wifi_errors.password) {
|
||||
errors.guest_wifi = guest_wifi_errors;
|
||||
}
|
||||
return errors;
|
||||
});
|
||||
return JSON.stringify(formErrors).match(/\[[{},?]+\]/) ? null : formErrors;
|
||||
}
|
||||
|
@@ -22,19 +22,34 @@ describe("<ResetWiFiSettings/>", () => {
|
||||
let getAllByText;
|
||||
|
||||
beforeEach(() => {
|
||||
({ getAllByText } = render(<ResetWiFiSettings ws={webSockets} endpoint={endpoint} />));
|
||||
({ getAllByText } = render(
|
||||
<ResetWiFiSettings ws={webSockets} endpoint={endpoint} />
|
||||
));
|
||||
});
|
||||
|
||||
it("should display alert on open ports - success", async () => {
|
||||
fireEvent.click(getAllByText("Reset Wi-Fi Settings")[1]);
|
||||
expect(mockAxios.post).toBeCalledWith(endpoint, undefined, expect.anything());
|
||||
expect(mockAxios.post).toBeCalledWith(
|
||||
endpoint,
|
||||
undefined,
|
||||
expect.anything()
|
||||
);
|
||||
mockAxios.mockResponse({ data: { foo: "bar" } });
|
||||
await wait(() => expect(mockSetAlert).toBeCalledWith("Wi-Fi settings are set to defaults.", ALERT_TYPES.SUCCESS));
|
||||
await wait(() =>
|
||||
expect(mockSetAlert).toBeCalledWith(
|
||||
"Wi-Fi settings are set to defaults.",
|
||||
ALERT_TYPES.SUCCESS
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should display alert on open ports - failure", async () => {
|
||||
fireEvent.click(getAllByText("Reset Wi-Fi Settings")[1]);
|
||||
mockJSONError();
|
||||
await wait(() => expect(mockSetAlert).toBeCalledWith("An error occurred during resetting Wi-Fi settings."));
|
||||
await wait(() =>
|
||||
expect(mockSetAlert).toBeCalledWith(
|
||||
"An error occurred during resetting Wi-Fi settings."
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -292,11 +292,7 @@ export function wifiSettingsFixture() {
|
||||
radar: false,
|
||||
},
|
||||
],
|
||||
available_htmodes: [
|
||||
"NOHT",
|
||||
"HT20",
|
||||
"HT40",
|
||||
],
|
||||
available_htmodes: ["NOHT", "HT20", "HT40"],
|
||||
hwmode: "11g",
|
||||
},
|
||||
],
|
||||
@@ -327,9 +323,9 @@ const oneDevice = {
|
||||
htmode: "HT40",
|
||||
hwmode: "11a",
|
||||
id: 0,
|
||||
password: "TestPass"
|
||||
}
|
||||
]
|
||||
password: "TestPass",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const twoDevices = {
|
||||
@@ -343,7 +339,7 @@ const twoDevices = {
|
||||
htmode: "HT40",
|
||||
hwmode: "11a",
|
||||
id: 0,
|
||||
password: "TestPass"
|
||||
password: "TestPass",
|
||||
},
|
||||
{
|
||||
SSID: "Turris2",
|
||||
@@ -354,9 +350,9 @@ const twoDevices = {
|
||||
htmode: "HT40",
|
||||
hwmode: "11a",
|
||||
id: 0,
|
||||
password: "TestPass"
|
||||
}
|
||||
]
|
||||
password: "TestPass",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const threeDevices = {
|
||||
@@ -370,7 +366,7 @@ const threeDevices = {
|
||||
htmode: "HT40",
|
||||
hwmode: "11a",
|
||||
id: 0,
|
||||
password: "TestPass"
|
||||
password: "TestPass",
|
||||
},
|
||||
{
|
||||
SSID: "Turris2",
|
||||
@@ -381,7 +377,7 @@ const threeDevices = {
|
||||
htmode: "HT40",
|
||||
hwmode: "11a",
|
||||
id: 0,
|
||||
password: "TestPass"
|
||||
password: "TestPass",
|
||||
},
|
||||
{
|
||||
SSID: "Turris3",
|
||||
@@ -392,9 +388,9 @@ const threeDevices = {
|
||||
htmode: "HT40",
|
||||
hwmode: "11a",
|
||||
id: 0,
|
||||
password: ""
|
||||
}
|
||||
]
|
||||
password: "",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export {oneDevice, twoDevices, threeDevices};
|
||||
export { oneDevice, twoDevices, threeDevices };
|
||||
|
@@ -22,7 +22,9 @@ export const HELP_TEXTS = {
|
||||
password: _(`
|
||||
WPA2 pre-shared key, that is required to connect to the network.
|
||||
`),
|
||||
hidden: _("If set, network is not visible when scanning for available networks."),
|
||||
hidden: _(
|
||||
"If set, network is not visible when scanning for available networks."
|
||||
),
|
||||
hwmode: _(`
|
||||
The 2.4 GHz band is more widely supported by clients, but tends to have more interference. The 5 GHz band is a
|
||||
newer standard and may not be supported by all your devices. It usually has less interference, but the signal
|
||||
|
Reference in New Issue
Block a user