fix broken settings page
This commit is contained in:
parent
4f1db3fd62
commit
6885c7ad04
|
@ -25,9 +25,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let loading = false
|
let loading = false
|
||||||
|
|
||||||
let company
|
|
||||||
let logoUrl
|
|
||||||
let file
|
let file
|
||||||
|
|
||||||
async function uploadLogo() {
|
async function uploadLogo() {
|
||||||
|
@ -41,19 +38,18 @@
|
||||||
async function saveConfig() {
|
async function saveConfig() {
|
||||||
loading = true
|
loading = true
|
||||||
await toggleAnalytics()
|
await toggleAnalytics()
|
||||||
const res = await uploadLogo()
|
if (file) {
|
||||||
console.log(res)
|
await uploadLogo()
|
||||||
// console.log("company", company)
|
}
|
||||||
// const res = await organisation.save({
|
const res = await organisation.save({
|
||||||
// company: company || $organisation?.config?.company,
|
company: $organisation.company,
|
||||||
// // logoUrl,
|
platformUrl: $organisation.platformUrl,
|
||||||
// // platformUrl,
|
})
|
||||||
// })
|
if (res.status === 200) {
|
||||||
// if (res.status === 200) {
|
notifications.success("Settings saved.")
|
||||||
// notifications.success("General settings saved.")
|
} else {
|
||||||
// } else {
|
notifications.error(res.message)
|
||||||
// notifications.danger("Error when saving settings.")
|
}
|
||||||
// }
|
|
||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -76,18 +72,13 @@
|
||||||
<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
|
<Input thin bind:value={$organisation.company} />
|
||||||
thin
|
|
||||||
value={$organisation?.config?.company}
|
|
||||||
on:change={e => (company = e.detail)}
|
|
||||||
/>
|
|
||||||
</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={[file]}
|
||||||
gallery={false}
|
|
||||||
on:change={e => {
|
on:change={e => {
|
||||||
file = e.detail?.[0]
|
file = e.detail?.[0]
|
||||||
}}
|
}}
|
||||||
|
@ -103,12 +94,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
|
<Input thin bind:value={$organisation.platformUrl} />
|
||||||
thin
|
|
||||||
value={$organisation?.config?.platformUrl ||
|
|
||||||
"http://localhost:10000"}
|
|
||||||
on:change={e => (company = e.detail)}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,37 +1,40 @@
|
||||||
import { writable } from "svelte/store"
|
import { writable, get } from "svelte/store"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
|
||||||
const FALLBACK_CONFIG = {
|
const FALLBACK_CONFIG = {
|
||||||
platformUrl: "",
|
platformUrl: "",
|
||||||
logoUrl: "",
|
logoUrl: "",
|
||||||
docsUrl: "",
|
docsUrl: "",
|
||||||
company: "",
|
company: "http://localhost:10000",
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createOrganisationStore() {
|
export function createOrganisationStore() {
|
||||||
const { subscribe, set } = writable({})
|
const store = writable({})
|
||||||
|
const { subscribe, set } = store
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
const response = await api.get(`/api/admin/configs/settings`)
|
const res = await api.get(`/api/admin/configs/settings`)
|
||||||
const json = await response.json()
|
const json = await res.json()
|
||||||
if (json.status === 400) {
|
|
||||||
set({ config: FALLBACK_CONFIG})
|
if (json.status === 400) {
|
||||||
} else {
|
set(FALLBACK_CONFIG)
|
||||||
set(json)
|
} else {
|
||||||
}
|
set({...json.config, _rev: json._rev})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save(config) {
|
||||||
|
const res = await api.post("/api/admin/configs", { type: "settings", config, _rev: get(store)._rev } )
|
||||||
|
const json = await res.json()
|
||||||
|
console.log(json)
|
||||||
|
await init()
|
||||||
|
return { status: 200 }
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
save: async config => {
|
set,
|
||||||
try {
|
save,
|
||||||
await api.post("/api/admin/configs", { type: "settings", config })
|
|
||||||
await init()
|
|
||||||
return { status: 200 }
|
|
||||||
} catch (error) {
|
|
||||||
return { status: error }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
init,
|
init,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue