1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13:00

update org store and add loading state + notifications to save action

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-05 18:30:03 +02:00
parent 1f451d07de
commit ef129b7595
2 changed files with 46 additions and 23 deletions

View file

@ -9,17 +9,34 @@
Input, Input,
Toggle, Toggle,
Dropzone, Dropzone,
notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import { organisation } from "stores/portal" 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 company = $organisation?.company
let logoUrl = $organisation.logoUrl let logoUrl = $organisation.logoUrl
async function saveConfig() { async function saveConfig() {
loading = true
const res = await organisation.save({ ...$organisation, company }) const res = await organisation.save({ ...$organisation, company })
console.log(res) if (res.status === 200) {
await organisation.init() notifications.success("General settings saved.")
console.log($organisation) } else {
notifications.danger("Error when saving settings.")
}
loading = false
} }
</script> </script>
@ -61,12 +78,16 @@
<div class="fields"> <div class="fields">
<div class="field"> <div class="field">
<Label>Send Analytics to Budibase</Label> <Label>Send Analytics to Budibase</Label>
<Toggle text="" /> <Toggle
text=""
bind:value={analyticsDisabled}
on:change={toggleAnalytics}
/>
</div> </div>
</div> </div>
</div> </div>
<div class="save"> <div class="save">
<Button on:click={saveConfig} cta>Save</Button> <Button disabled={loading} on:click={saveConfig} cta>Save</Button>
</div> </div>
</Layout> </Layout>
</div> </div>

View file

@ -3,32 +3,34 @@ import api from "builderStore/api"
export function createOrganisationStore() { export function createOrganisationStore() {
const { subscribe, set } = writable({}) 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 { return {
subscribe, subscribe,
save: async config => { save: async config => {
try { try {
const res = await api.post('/api/admin/configs', { type: 'settings', config}) await api.post('/api/admin/configs', { type: 'settings', config})
return await res.json() await init()
return { status: 200 }
} catch (error) { } catch (error) {
console.error(error) return { 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: ''
})
} }
}, },
init
} }
} }