Fix general settings page not saving, fix analytics options
This commit is contained in:
parent
445471efa7
commit
b3b57c9a0e
|
@ -14,45 +14,52 @@
|
||||||
import { organisation } from "stores/portal"
|
import { organisation } from "stores/portal"
|
||||||
import { post } from "builderStore/api"
|
import { post } from "builderStore/api"
|
||||||
import analytics from "analytics"
|
import analytics from "analytics"
|
||||||
let analyticsDisabled = analytics.disabled()
|
import { writable } from "svelte/store"
|
||||||
|
|
||||||
function toggleAnalytics() {
|
const values = writable({
|
||||||
if (analyticsDisabled) {
|
analytics: !analytics.disabled(),
|
||||||
analytics.optIn()
|
company: $organisation.company,
|
||||||
} else {
|
platformUrl: $organisation.platformUrl,
|
||||||
analytics.optOut()
|
logo: $organisation.logoUrl
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let loading = false
|
|
||||||
let file = $organisation.logoUrl
|
|
||||||
? { url: $organisation.logoUrl, type: "image", name: "Logo" }
|
? { url: $organisation.logoUrl, type: "image", name: "Logo" }
|
||||||
: null
|
: null,
|
||||||
|
})
|
||||||
|
let loading = false
|
||||||
|
|
||||||
async function uploadLogo() {
|
async function uploadLogo(file) {
|
||||||
let data = new FormData()
|
let data = new FormData()
|
||||||
data.append("file", file)
|
data.append("file", file)
|
||||||
|
|
||||||
const res = await post("/api/admin/configs/upload/settings/logo", data, {})
|
const res = await post("/api/admin/configs/upload/settings/logo", data, {})
|
||||||
return await res.json()
|
return await res.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveConfig() {
|
async function saveConfig() {
|
||||||
loading = true
|
loading = true
|
||||||
await toggleAnalytics()
|
|
||||||
if (file) {
|
// Set analytics preference
|
||||||
await uploadLogo()
|
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()
|
await organisation.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update settings
|
||||||
const res = await organisation.save({
|
const res = await organisation.save({
|
||||||
company: $organisation.company,
|
company: $values.company ?? "",
|
||||||
platformUrl: $organisation.platformUrl,
|
platformUrl: $values.platformUrl ?? "",
|
||||||
})
|
})
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
notifications.success("Settings saved.")
|
notifications.success("Settings saved successfully")
|
||||||
} else {
|
} else {
|
||||||
notifications.error(res.message)
|
notifications.error(res.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -73,15 +80,15 @@
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<Label size="L">Organization name</Label>
|
<Label size="L">Organization name</Label>
|
||||||
<Input thin bind:value={$organisation.company} />
|
<Input thin bind:value={$values.company} />
|
||||||
</div>
|
</div>
|
||||||
<div class="field logo">
|
<div class="field logo">
|
||||||
<Label size="L">Logo</Label>
|
<Label size="L">Logo</Label>
|
||||||
<div class="file">
|
<div class="file">
|
||||||
<Dropzone
|
<Dropzone
|
||||||
value={[file]}
|
value={[$values.logo]}
|
||||||
on:change={e => {
|
on:change={e => {
|
||||||
file = e.detail?.[0]
|
$values.logo = e.detail?.[0]
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -95,7 +102,7 @@
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<Label size="L">Platform URL</Label>
|
<Label size="L">Platform URL</Label>
|
||||||
<Input thin bind:value={$organisation.platformUrl} />
|
<Input thin bind:value={$values.platformUrl} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Divider size="S" />
|
<Divider size="S" />
|
||||||
|
@ -110,7 +117,7 @@
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<Label size="L">Send Analytics to Budibase</Label>
|
<Label size="L">Send Analytics to Budibase</Label>
|
||||||
<Toggle text="" value={!analyticsDisabled} />
|
<Toggle text="" bind:value={$values.analytics} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
Loading…
Reference in New Issue