Skip to content

Commit

Permalink
Merge pull request #15307 from Budibase/type-portal-org-store
Browse files Browse the repository at this point in the history
Convert portal organisation store to TS
  • Loading branch information
aptkingston authored Jan 9, 2025
2 parents 7ce57e0 + 0d4e6e2 commit dd89562
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 68 deletions.
66 changes: 0 additions & 66 deletions packages/builder/src/stores/portal/organisation.js

This file was deleted.

71 changes: 71 additions & 0 deletions packages/builder/src/stores/portal/organisation.ts
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 1 addition & 2 deletions packages/types/src/documents/global/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ export interface SMTPConfig extends Config<SMTPInnerConfig> {}
export interface SettingsBrandingConfig {
faviconUrl?: string
faviconUrlEtag?: string

emailBrandingEnabled?: boolean
testimonialsEnabled?: boolean
platformTitle?: string
loginHeading?: string
loginButton?: string

metaDescription?: string
metaImageUrl?: string
metaTitle?: string
Expand All @@ -42,6 +40,7 @@ export interface SettingsInnerConfig {
platformUrl?: string
company?: string
logoUrl?: string // Populated on read
docsUrl?: string
logoUrlEtag?: string
uniqueTenantId?: string
analyticsEnabled?: boolean
Expand Down

0 comments on commit dd89562

Please sign in to comment.