From ef129b759539bbb45cca9a98e7a8a5293d02eef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Wed, 5 May 2021 18:30:03 +0200 Subject: [PATCH] update org store and add loading state + notifications to save action --- .../src/pages/portal/settings/general.svelte | 31 ++++++++++++--- .../builder/src/stores/portal/organisation.js | 38 ++++++++++--------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/packages/builder/src/pages/portal/settings/general.svelte b/packages/builder/src/pages/portal/settings/general.svelte index cb7e6e6d70..77da761962 100644 --- a/packages/builder/src/pages/portal/settings/general.svelte +++ b/packages/builder/src/pages/portal/settings/general.svelte @@ -9,17 +9,34 @@ Input, Toggle, Dropzone, + notifications, } from "@budibase/bbui" import { organisation } from "stores/portal" + import analytics from "analytics" + let analyticsDisabled = analytics.disabled() + + function toggleAnalytics() { + if (analyticsDisabled) { + analytics.optIn() + } else { + analytics.optOut() + } + } + + let loading = false let company = $organisation?.company let logoUrl = $organisation.logoUrl async function saveConfig() { + loading = true const res = await organisation.save({ ...$organisation, company }) - console.log(res) - await organisation.init() - console.log($organisation) + if (res.status === 200) { + notifications.success("General settings saved.") + } else { + notifications.danger("Error when saving settings.") + } + loading = false } @@ -61,12 +78,16 @@
- +
- +
diff --git a/packages/builder/src/stores/portal/organisation.js b/packages/builder/src/stores/portal/organisation.js index 7ff32ea859..bef899d186 100644 --- a/packages/builder/src/stores/portal/organisation.js +++ b/packages/builder/src/stores/portal/organisation.js @@ -3,32 +3,34 @@ import api from "builderStore/api" export function createOrganisationStore() { const { subscribe, set } = writable({}) + + async function init() { + try { + const response = await api.get(`/api/admin/configs/settings`) + const json = await response.json() + set(json) + } catch (error) { + set({ + platformUrl: '', + logoUrl: '', + docsUrl: '', + company: '' + }) + } + } return { subscribe, save: async config => { try { - const res = await api.post('/api/admin/configs', { type: 'settings', config}) - return await res.json() + await api.post('/api/admin/configs', { type: 'settings', config}) + await init() + return { status: 200 } } catch (error) { - console.error(error) - } - }, - init: async () => { - try { - const response = await api.get(`/api/admin/configs/settings`) - const json = await response.json() - set(json) - // set(json) - } catch (error) { - set({ - platformUrl: '', - logoUrl: '', - docsUrl: '', - company: '' - }) + return { error } } }, + init } }