fix broken settings page

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-12 17:16:31 +02:00
parent 4f1db3fd62
commit 6885c7ad04
2 changed files with 36 additions and 47 deletions

View File

@ -25,9 +25,6 @@
}
let loading = false
let company
let logoUrl
let file
async function uploadLogo() {
@ -41,19 +38,18 @@
async function saveConfig() {
loading = true
await toggleAnalytics()
const res = await uploadLogo()
console.log(res)
// console.log("company", company)
// const res = await organisation.save({
// company: company || $organisation?.config?.company,
// // logoUrl,
// // platformUrl,
// })
// if (res.status === 200) {
// notifications.success("General settings saved.")
// } else {
// notifications.danger("Error when saving settings.")
// }
if (file) {
await uploadLogo()
}
const res = await organisation.save({
company: $organisation.company,
platformUrl: $organisation.platformUrl,
})
if (res.status === 200) {
notifications.success("Settings saved.")
} else {
notifications.error(res.message)
}
loading = false
}
</script>
@ -76,18 +72,13 @@
<div class="fields">
<div class="field">
<Label size="L">Organization name</Label>
<Input
thin
value={$organisation?.config?.company}
on:change={e => (company = e.detail)}
/>
<Input thin bind:value={$organisation.company} />
</div>
<div class="field logo">
<Label size="L">Logo</Label>
<div class="file">
<Dropzone
value={[file]}
gallery={false}
on:change={e => {
file = e.detail?.[0]
}}
@ -103,12 +94,7 @@
<div class="fields">
<div class="field">
<Label size="L">Platform URL</Label>
<Input
thin
value={$organisation?.config?.platformUrl ||
"http://localhost:10000"}
on:change={e => (company = e.detail)}
/>
<Input thin bind:value={$organisation.platformUrl} />
</div>
</div>
</div>

View File

@ -1,37 +1,40 @@
import { writable } from "svelte/store"
import { writable, get } from "svelte/store"
import api from "builderStore/api"
const FALLBACK_CONFIG = {
platformUrl: "",
logoUrl: "",
docsUrl: "",
company: "",
company: "http://localhost:10000",
}
export function createOrganisationStore() {
const { subscribe, set } = writable({})
const store = writable({})
const { subscribe, set } = store
async function init() {
const response = await api.get(`/api/admin/configs/settings`)
const json = await response.json()
if (json.status === 400) {
set({ config: FALLBACK_CONFIG})
} else {
set(json)
}
const res = await api.get(`/api/admin/configs/settings`)
const json = await res.json()
if (json.status === 400) {
set(FALLBACK_CONFIG)
} 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 {
subscribe,
save: async config => {
try {
await api.post("/api/admin/configs", { type: "settings", config })
await init()
return { status: 200 }
} catch (error) {
return { status: error }
}
},
set,
save,
init,
}
}