Merge pull request #15307 from Budibase/type-portal-org-store
Convert portal organisation store to TS
This commit is contained in:
commit
dd8956271d
|
@ -1,66 +0,0 @@
|
||||||
import { writable, get } from "svelte/store"
|
|
||||||
import { API } from "@/api"
|
|
||||||
import { auth } from "@/stores/portal"
|
|
||||||
import _ from "lodash"
|
|
||||||
|
|
||||||
const DEFAULT_CONFIG = {
|
|
||||||
platformUrl: "",
|
|
||||||
logoUrl: undefined,
|
|
||||||
faviconUrl: undefined,
|
|
||||||
emailBrandingEnabled: true,
|
|
||||||
testimonialsEnabled: true,
|
|
||||||
platformTitle: "Budibase",
|
|
||||||
loginHeading: undefined,
|
|
||||||
loginButton: undefined,
|
|
||||||
metaDescription: undefined,
|
|
||||||
metaImageUrl: undefined,
|
|
||||||
metaTitle: undefined,
|
|
||||||
docsUrl: undefined,
|
|
||||||
company: "Budibase",
|
|
||||||
oidc: undefined,
|
|
||||||
google: undefined,
|
|
||||||
googleDatasourceConfigured: undefined,
|
|
||||||
oidcCallbackUrl: "",
|
|
||||||
googleCallbackUrl: "",
|
|
||||||
isSSOEnforced: false,
|
|
||||||
loaded: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createOrganisationStore() {
|
|
||||||
const store = writable(DEFAULT_CONFIG)
|
|
||||||
const { subscribe, set } = store
|
|
||||||
|
|
||||||
async function init() {
|
|
||||||
const tenantId = get(auth).tenantId
|
|
||||||
const settingsConfigDoc = await API.getTenantConfig(tenantId)
|
|
||||||
set({ ...DEFAULT_CONFIG, ...settingsConfigDoc.config, loaded: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
async function save(config) {
|
|
||||||
// Delete non-persisted fields
|
|
||||||
const storeConfig = _.cloneDeep(get(store))
|
|
||||||
delete storeConfig.oidc
|
|
||||||
delete storeConfig.google
|
|
||||||
delete storeConfig.googleDatasourceConfigured
|
|
||||||
delete storeConfig.oidcCallbackUrl
|
|
||||||
delete storeConfig.googleCallbackUrl
|
|
||||||
|
|
||||||
// delete internal store field
|
|
||||||
delete storeConfig.loaded
|
|
||||||
|
|
||||||
await API.saveConfig({
|
|
||||||
type: "settings",
|
|
||||||
config: { ...storeConfig, ...config },
|
|
||||||
})
|
|
||||||
await init()
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
subscribe,
|
|
||||||
set,
|
|
||||||
save,
|
|
||||||
init,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const organisation = createOrganisationStore()
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
import { get } from "svelte/store"
|
||||||
|
import { API } from "@/api"
|
||||||
|
import { auth } from "@/stores/portal"
|
||||||
|
import {
|
||||||
|
ConfigType,
|
||||||
|
PublicSettingsInnerConfig,
|
||||||
|
SettingsBrandingConfig,
|
||||||
|
SettingsInnerConfig,
|
||||||
|
} from "@budibase/types"
|
||||||
|
import { BudiStore } from "../BudiStore"
|
||||||
|
|
||||||
|
interface LocalOrganisationState {
|
||||||
|
loaded: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
type SavedOrganisationState = SettingsInnerConfig & SettingsBrandingConfig
|
||||||
|
type OrganisationState = SavedOrganisationState &
|
||||||
|
PublicSettingsInnerConfig &
|
||||||
|
LocalOrganisationState
|
||||||
|
|
||||||
|
const DEFAULT_STATE: OrganisationState = {
|
||||||
|
platformUrl: "",
|
||||||
|
emailBrandingEnabled: true,
|
||||||
|
testimonialsEnabled: true,
|
||||||
|
platformTitle: "Budibase",
|
||||||
|
company: "Budibase",
|
||||||
|
google: false,
|
||||||
|
googleDatasourceConfigured: false,
|
||||||
|
oidc: false,
|
||||||
|
oidcCallbackUrl: "",
|
||||||
|
googleCallbackUrl: "",
|
||||||
|
loaded: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrganisationStore extends BudiStore<OrganisationState> {
|
||||||
|
constructor() {
|
||||||
|
super(DEFAULT_STATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
async init() {
|
||||||
|
const tenantId = get(auth).tenantId
|
||||||
|
const settingsConfigDoc = await API.getTenantConfig(tenantId)
|
||||||
|
this.set({ ...DEFAULT_STATE, ...settingsConfigDoc.config, loaded: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
async save(changes: Partial<SavedOrganisationState>) {
|
||||||
|
// Strip non persisted fields
|
||||||
|
const {
|
||||||
|
oidc,
|
||||||
|
google,
|
||||||
|
googleDatasourceConfigured,
|
||||||
|
oidcCallbackUrl,
|
||||||
|
googleCallbackUrl,
|
||||||
|
loaded,
|
||||||
|
...config
|
||||||
|
} = get(this.store)
|
||||||
|
|
||||||
|
// Save new config
|
||||||
|
const newConfig: SavedOrganisationState = {
|
||||||
|
...config,
|
||||||
|
...changes,
|
||||||
|
}
|
||||||
|
await API.saveConfig({
|
||||||
|
type: ConfigType.SETTINGS,
|
||||||
|
config: newConfig,
|
||||||
|
})
|
||||||
|
await this.init()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const organisation = new OrganisationStore()
|
|
@ -26,13 +26,11 @@ export interface SMTPConfig extends Config<SMTPInnerConfig> {}
|
||||||
export interface SettingsBrandingConfig {
|
export interface SettingsBrandingConfig {
|
||||||
faviconUrl?: string
|
faviconUrl?: string
|
||||||
faviconUrlEtag?: string
|
faviconUrlEtag?: string
|
||||||
|
|
||||||
emailBrandingEnabled?: boolean
|
emailBrandingEnabled?: boolean
|
||||||
testimonialsEnabled?: boolean
|
testimonialsEnabled?: boolean
|
||||||
platformTitle?: string
|
platformTitle?: string
|
||||||
loginHeading?: string
|
loginHeading?: string
|
||||||
loginButton?: string
|
loginButton?: string
|
||||||
|
|
||||||
metaDescription?: string
|
metaDescription?: string
|
||||||
metaImageUrl?: string
|
metaImageUrl?: string
|
||||||
metaTitle?: string
|
metaTitle?: string
|
||||||
|
@ -42,6 +40,7 @@ export interface SettingsInnerConfig {
|
||||||
platformUrl?: string
|
platformUrl?: string
|
||||||
company?: string
|
company?: string
|
||||||
logoUrl?: string // Populated on read
|
logoUrl?: string // Populated on read
|
||||||
|
docsUrl?: string
|
||||||
logoUrlEtag?: string
|
logoUrlEtag?: string
|
||||||
uniqueTenantId?: string
|
uniqueTenantId?: string
|
||||||
analyticsEnabled?: boolean
|
analyticsEnabled?: boolean
|
||||||
|
|
Loading…
Reference in New Issue