diff --git a/assets/js/components/Config/GeneralConfig.vue b/assets/js/components/Config/GeneralConfig.vue index e068919bf..c4f2a266c 100644 --- a/assets/js/components/Config/GeneralConfig.vue +++ b/assets/js/components/Config/GeneralConfig.vue @@ -99,8 +99,8 @@ export default { }, sponsorStatus() { const sponsor = store.state?.sponsor || {}; - const name = sponsor.status.name; - const expiresSoon = sponsor.status.expiresSoon; + const name = sponsor.status?.name; + const expiresSoon = sponsor.status?.expiresSoon; let textClass = ""; let badgeClass = ""; let title = name; diff --git a/assets/js/components/Config/SponsorModal.vue b/assets/js/components/Config/SponsorModal.vue index bcbd57151..3fee5e856 100644 --- a/assets/js/components/Config/SponsorModal.vue +++ b/assets/js/components/Config/SponsorModal.vue @@ -110,13 +110,13 @@ export default { return store?.state?.sponsor; }, token() { - return this.sponsor?.status.token; + return this.sponsor?.status?.token; }, fromYaml() { return this.sponsor?.fromYaml; }, name() { - return this.sponsor?.status.name || ""; + return this.sponsor?.status?.name || ""; }, showTokenForm() { return this.editMode || !this.token; diff --git a/assets/js/views/Config.vue b/assets/js/views/Config.vue index 892efa29c..b348d440f 100644 --- a/assets/js/views/Config.vue +++ b/assets/js/views/Config.vue @@ -793,21 +793,22 @@ export default defineComponent({ restart.restartNeeded = true; } }, + async loadConfig(path: string) { + const validateStatus = (code: number) => [200, 404].includes(code); + const response = await api.get(`/config/${path}`, { validateStatus }); + return response.status === 200 ? response.data : undefined; + }, async loadVehicles() { - const response = await api.get("/config/devices/vehicle"); - this.vehicles = response.data || []; + this.vehicles = (await this.loadConfig("devices/vehicle")) || []; }, async loadChargers() { - const response = await api.get("/config/devices/charger"); - this.chargers = response.data || []; + this.chargers = (await this.loadConfig("devices/charger")) || []; }, async loadMeters() { - const response = await api.get("/config/devices/meter"); - this.meters = response.data || []; + this.meters = (await this.loadConfig("devices/meter")) || []; }, async loadCircuits() { - const response = await api.get("/config/devices/circuit"); - const circuits = response.data || []; + const circuits = (await this.loadConfig("devices/circuit")) || []; // set lpc default title circuits.forEach((c: ConfigCircuit) => { if (c.name === "lpc" && !c.config?.title) { @@ -818,16 +819,13 @@ export default defineComponent({ this.circuits = circuits; }, async loadSite() { - const response = await api.get("/config/site", { - validateStatus: (status: number) => status < 500, - }); - if (response.status === 200) { - this.site = response.data; + const data = await this.loadConfig("site"); + if (data) { + this.site = data; } }, async loadLoadpoints() { - const response = await api.get("/config/loadpoints"); - this.loadpoints = response.data || []; + this.loadpoints = (await this.loadConfig("loadpoints")) || []; }, getMetersByNames(names: string[] | null): ConfigMeter[] { if (!names || !this.meters) {