update org store and add loading state + notifications to save action
This commit is contained in:
parent
1f451d07de
commit
ef129b7595
|
@ -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
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -61,12 +78,16 @@
|
|||
<div class="fields">
|
||||
<div class="field">
|
||||
<Label>Send Analytics to Budibase</Label>
|
||||
<Toggle text="" />
|
||||
<Toggle
|
||||
text=""
|
||||
bind:value={analyticsDisabled}
|
||||
on:change={toggleAnalytics}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="save">
|
||||
<Button on:click={saveConfig} cta>Save</Button>
|
||||
<Button disabled={loading} on:click={saveConfig} cta>Save</Button>
|
||||
</div>
|
||||
</Layout>
|
||||
</div>
|
||||
|
|
|
@ -4,22 +4,11 @@ import api from "builderStore/api"
|
|||
export function createOrganisationStore() {
|
||||
const { subscribe, set } = writable({})
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
save: async config => {
|
||||
try {
|
||||
const res = await api.post('/api/admin/configs', { type: 'settings', config})
|
||||
return await res.json()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
},
|
||||
init: async () => {
|
||||
async function init() {
|
||||
try {
|
||||
const response = await api.get(`/api/admin/configs/settings`)
|
||||
const json = await response.json()
|
||||
set(json)
|
||||
// set(json)
|
||||
} catch (error) {
|
||||
set({
|
||||
platformUrl: '',
|
||||
|
@ -28,7 +17,20 @@ export function createOrganisationStore() {
|
|||
company: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
save: async config => {
|
||||
try {
|
||||
await api.post('/api/admin/configs', { type: 'settings', config})
|
||||
await init()
|
||||
return { status: 200 }
|
||||
} catch (error) {
|
||||
return { error }
|
||||
}
|
||||
},
|
||||
init
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue