introduces portal stores concept and adds an org one that handles configs

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-05 17:50:45 +02:00
parent 4253f87e82
commit 1f451d07de
5 changed files with 102 additions and 1247 deletions

View File

@ -1,5 +1,5 @@
<script> <script>
import { isActive, url } from "@roxi/routify" import { isActive, url, goto } from "@roxi/routify"
import { onMount } from "svelte" import { onMount } from "svelte"
import { import {
Icon, Icon,
@ -10,15 +10,12 @@
SideNavigation as Navigation, SideNavigation as Navigation,
SideNavigationItem as Item, SideNavigationItem as Item,
} from "@budibase/bbui" } from "@budibase/bbui"
import { organisation } from "stores/portal"
organisation.init()
let orgName, orgLogo, onBoardingProgress, user let onBoardingProgress, user
async function getInfo() { async function getInfo() {
// fetch orgInfo
orgName = "ACME Inc."
orgLogo = "https://via.placeholder.com/150"
// set onBoardingProgress
onBoardingProgress = 20 onBoardingProgress = 20
user = { name: "John Doe" } user = { name: "John Doe" }
} }
@ -43,8 +40,11 @@
<div class="nav"> <div class="nav">
<div class="branding"> <div class="branding">
<div class="name"> <div class="name">
<img src={orgLogo} alt="Logotype" /> <img
<span>{orgName}</span> src={$organisation?.logoUrl || "https://via.placeholder.com/50"}
alt="Logotype"
/>
<span>{$organisation?.company}</span>
</div> </div>
<div class="onboarding"> <div class="onboarding">
<ProgressCircle size="S" value={onBoardingProgress} /> <ProgressCircle size="S" value={onBoardingProgress} />
@ -88,6 +88,7 @@
} }
.branding { .branding {
display: grid; display: grid;
grid-gap: var(--spacing-s);
grid-template-columns: auto auto; grid-template-columns: auto auto;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
@ -127,4 +128,8 @@
width: 32px; width: 32px;
height: 32px; height: 32px;
} }
span {
overflow: hidden;
text-overflow: ellipsis;
}
</style> </style>

View File

@ -3,12 +3,24 @@
Layout, Layout,
Heading, Heading,
Body, Body,
Button,
Divider, Divider,
Label, Label,
Input, Input,
Toggle, Toggle,
Dropzone, Dropzone,
} from "@budibase/bbui" } from "@budibase/bbui"
import { organisation } from "stores/portal"
let company = $organisation?.company
let logoUrl = $organisation.logoUrl
async function saveConfig() {
const res = await organisation.save({ ...$organisation, company })
console.log(res)
await organisation.init()
console.log($organisation)
}
</script> </script>
<div class="container"> <div class="container">
@ -29,14 +41,14 @@
<div class="fields"> <div class="fields">
<div class="field"> <div class="field">
<Label>Organization name</Label> <Label>Organization name</Label>
<Input /> <Input thin bind:value={company} />
</div> </div>
<div class="field"> <!-- <div class="field">
<Label>Logo</Label> <Label>Logo</Label>
<div class="file"> <div class="file">
<Dropzone /> <Dropzone />
</div> </div>
</div> </div> -->
</div> </div>
</div> </div>
<Divider size="S" /> <Divider size="S" />
@ -46,11 +58,16 @@
>If you would like to send analytics that help us make Budibase better, >If you would like to send analytics that help us make Budibase better,
please let us know below.</Body please let us know below.</Body
> >
<div class="field"> <div class="fields">
<Label>Send Analytics to Budibase</Label> <div class="field">
<Toggle text="" /> <Label>Send Analytics to Budibase</Label>
<Toggle text="" />
</div>
</div> </div>
</div> </div>
<div class="save">
<Button on:click={saveConfig} cta>Save</Button>
</div>
</Layout> </Layout>
</div> </div>
@ -58,6 +75,7 @@
.fields { .fields {
display: grid; display: grid;
grid-gap: var(--spacing-m); grid-gap: var(--spacing-m);
margin-top: var(--spacing-xl);
} }
.field { .field {
display: grid; display: grid;
@ -69,4 +87,7 @@
.intro { .intro {
display: grid; display: grid;
} }
.save {
margin-left: auto;
}
</style> </style>

View File

@ -0,0 +1 @@
export { organisation } from "./organisation"

View File

@ -0,0 +1,35 @@
import { writable } from "svelte/store"
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 () => {
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: ''
})
}
},
}
}
export const organisation = createOrganisationStore()

File diff suppressed because it is too large Load Diff