diff --git a/packages/builder/src/pages/builder/portal/settings/general.svelte b/packages/builder/src/pages/builder/portal/settings/general.svelte index cd5709d493..bfd6c57b8d 100644 --- a/packages/builder/src/pages/builder/portal/settings/general.svelte +++ b/packages/builder/src/pages/builder/portal/settings/general.svelte @@ -14,45 +14,52 @@ import { organisation } from "stores/portal" import { post } from "builderStore/api" import analytics from "analytics" - let analyticsDisabled = analytics.disabled() - - function toggleAnalytics() { - if (analyticsDisabled) { - analytics.optIn() - } else { - analytics.optOut() - } - } + import { writable } from "svelte/store" + const values = writable({ + analytics: !analytics.disabled(), + company: $organisation.company, + platformUrl: $organisation.platformUrl, + logo: $organisation.logoUrl + ? { url: $organisation.logoUrl, type: "image", name: "Logo" } + : null, + }) let loading = false - let file = $organisation.logoUrl - ? { url: $organisation.logoUrl, type: "image", name: "Logo" } - : null - async function uploadLogo() { + async function uploadLogo(file) { let data = new FormData() data.append("file", file) - const res = await post("/api/admin/configs/upload/settings/logo", data, {}) return await res.json() } async function saveConfig() { loading = true - await toggleAnalytics() - if (file) { - await uploadLogo() + + // Set analytics preference + if ($values.analytics) { + analytics.optIn() + } else { + analytics.optOut() + } + + // Upload logo if required + if ($values.logo && !$values.logo.url) { + await uploadLogo($values.logo) await organisation.init() } + + // Update settings const res = await organisation.save({ - company: $organisation.company, - platformUrl: $organisation.platformUrl, + company: $values.company ?? "", + platformUrl: $values.platformUrl ?? "", }) if (res.status === 200) { - notifications.success("Settings saved.") + notifications.success("Settings saved successfully") } else { notifications.error(res.message) } + loading = false } @@ -73,15 +80,15 @@