Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert portal admin store to typescript #15170

Merged
merged 8 commits into from
Dec 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
const disabled = () => {
return {
SEND_EMAIL_SMTP: {
disabled: !$admin.checklist.smtp.checked,
disabled: !$admin.checklist?.smtp?.checked,
message: "Please configure SMTP",
},
COLLECT: {
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/src/pages/builder/admin/_layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$: useAccountPortal = cloud && !$admin.disableAccountPortal

onMount(() => {
if ($admin?.checklist?.adminUser.checked || useAccountPortal) {
if ($admin?.checklist?.adminUser?.checked || useAccountPortal) {
$redirect("../")
} else {
loaded = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<Button
secondary
on:click={deleteSmtp}
disabled={!$admin.checklist.smtp.checked}
disabled={!$admin.checklist?.smtp?.checked}
>
Reset
</Button>
Expand Down
7 changes: 1 addition & 6 deletions packages/builder/src/stores/portal/admin.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { it, expect, describe, beforeEach, vi } from "vitest"
import { DEFAULT_CONFIG, createAdminStore } from "./admin"
import { createAdminStore } from "./admin"

import { writable, get } from "svelte/store"
import { API } from "api"
Expand Down Expand Up @@ -45,11 +45,6 @@ describe("admin store", () => {
ctx.returnedStore = createAdminStore()
})

it("inits the writable store with the default config", () => {
expect(writable).toHaveBeenCalledTimes(1)
expect(writable).toHaveBeenCalledWith(DEFAULT_CONFIG)
})

it("returns the created store", ctx => {
expect(ctx.returnedStore).toEqual({
subscribe: expect.toBe(ctx.writableReturn.subscribe),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ import { writable, get } from "svelte/store"
import { API } from "api"
import { auth } from "stores/portal"
import { banner } from "@budibase/bbui"
import {
ConfigChecklistResponse,
GetEnvironmentResponse,
SystemStatusResponse,
} from "@budibase/types"

export const DEFAULT_CONFIG = {
loaded: false,
multiTenancy: false,
cloud: false,
isDev: false,
disableAccountPortal: false,
accountPortalUrl: "",
importComplete: false,
checklist: {
apps: { checked: false },
smtp: { checked: false },
adminUser: { checked: false },
sso: { checked: false },
},
maintenance: [],
offlineMode: false,
interface PortalAdminStore extends GetEnvironmentResponse {
loaded: boolean
checklist?: ConfigChecklistResponse
status?: SystemStatusResponse
}

export function createAdminStore() {
const admin = writable(DEFAULT_CONFIG)
const admin = writable<PortalAdminStore>({
loaded: false,
multiTenancy: false,
cloud: false,
isDev: false,
disableAccountPortal: false,
offlineMode: false,
maintenance: [],
})

async function init() {
await getChecklist()
Expand Down
Loading