diff --git a/web/mock/api-config.mock.ts b/web/mock/api-config.mock.ts index 315600c1d..6e50b9aac 100644 --- a/web/mock/api-config.mock.ts +++ b/web/mock/api-config.mock.ts @@ -1,5 +1,13 @@ +import { JsonObject } from 'common/jsonTypes'; import { defineMock } from 'vite-plugin-mock-dev-server' +let hostname = "localhost"; +let authenticationSettings: JsonObject = { + "authEnabled": false, + "username": "", + "password": "" +}; + export default defineMock( [ { @@ -29,6 +37,44 @@ export default defineMock( }, delay: 600, }, + { + url: '/api/config/system/hostname', + response(req, resp) { + if (req.method === 'GET') { + const doc = { + "config": { + "value": hostname + }, + "schema": {}, + "description": "The hostname of the device." + }; + resp.end(JSON.stringify(doc)); + } else if (req.method === 'POST') { + const doc = req.body; + console.log(doc); + hostname = doc.value; + resp.end(); + } + } + }, + { + url: '/api/config/system/authentication', + response(req, resp) { + if (req.method === 'GET') { + const doc = { + "config": authenticationSettings, + "schema": {}, + "description": "Auth." + }; + resp.end(JSON.stringify(doc)); + } else if (req.method === 'POST') { + const doc = req.body; + console.log(doc); + authenticationSettings = doc; + resp.end(); + } + } + }, { url: '/api/config/System/WiFi Settings', method: 'GET', diff --git a/web/src/common/configAPIClient.ts b/web/src/common/configAPIClient.ts index 9850c05c8..b20f15be7 100644 --- a/web/src/common/configAPIClient.ts +++ b/web/src/common/configAPIClient.ts @@ -48,7 +48,7 @@ export async function saveConfigData( data: string, errorHandler: (e: Error) => void, contentType: string = "application/json", -): Promise { +): Promise { try { const response = await fetch(APP_CONFIG.config_path + path, { method: "POST", @@ -59,8 +59,11 @@ export async function saveConfigData( }); if (!response.ok) { errorHandler(Error(`HTTP Error ${response.status} ${response.statusText}`)); + return false; } } catch (e) { errorHandler(Error(`Error saving config data to server: ${e.message}`)); + return false; } + return true; } diff --git a/web/src/components/Form.tsx b/web/src/components/Form.tsx index 77db57991..3fa8157d5 100644 --- a/web/src/components/Form.tsx +++ b/web/src/components/Form.tsx @@ -16,12 +16,11 @@ interface FormInputProps { step?: number; disabled?: boolean; checked?: boolean; - onchange?: (e: JSX.TargetedEvent) => void; + onInput?: (e: JSX.TargetedEvent) => void; } export function FormInput(props: FormInputProps): JSX.Element { - const { isInputDirty, setInputDirty } = - useContext(InputDirtyContext); + return (