-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15307 from Budibase/type-portal-org-store
Convert portal organisation store to TS
- Loading branch information
Showing
3 changed files
with
72 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters