set template URL in store instead of passing around param

This commit is contained in:
Martin McKeaveney 2021-11-03 12:43:52 +01:00
parent 822900d421
commit e7167713fc
5 changed files with 85 additions and 823 deletions

View File

@ -9,7 +9,7 @@
Checkbox, Checkbox,
} from "@budibase/bbui" } from "@budibase/bbui"
import { store, automationStore, hostingStore } from "builderStore" import { store, automationStore, hostingStore } from "builderStore"
import { admin } from "stores/portal" import { admin, auth } from "stores/portal"
import { string, mixed, object } from "yup" import { string, mixed, object } from "yup"
import api, { get, post } from "builderStore/api" import api, { get, post } from "builderStore/api"
import analytics, { Events } from "analytics" import analytics, { Events } from "analytics"
@ -139,6 +139,7 @@
} }
const userResp = await api.post(`/api/users/metadata/self`, user) const userResp = await api.post(`/api/users/metadata/self`, user)
await userResp.json() await userResp.json()
auth.resetInitTemplate()
$goto(`/builder/app/${appJson.instance._id}`) $goto(`/builder/app/${appJson.instance._id}`)
} catch (error) { } catch (error) {
console.error(error) console.error(error)
@ -146,6 +147,16 @@
submitting = false submitting = false
} }
} }
function getModalTitle() {
let title = "Create App"
if (template.fromFile) {
title = "Import App"
} else if (template.key) {
title = "Create app from template"
}
return title
}
</script> </script>
{#if showTemplateSelection} {#if showTemplateSelection}
@ -172,7 +183,7 @@
</ModalContent> </ModalContent>
{:else} {:else}
<ModalContent <ModalContent
title={template?.fromFile ? "Import app" : "Create app"} title={getModalTitle()}
confirmText={template?.fromFile ? "Import app" : "Create app"} confirmText={template?.fromFile ? "Import app" : "Create app"}
onConfirm={createNewApp} onConfirm={createNewApp}
onCancel={inline ? () => (template = null) : null} onCancel={inline ? () => (template = null) : null}

View File

@ -1,6 +1,6 @@
<script> <script>
import { auth, admin } from "stores/portal" import { auth, admin } from "stores/portal"
import { redirect } from "@roxi/routify" import { redirect, params } from "@roxi/routify"
// If already authenticated, redirect away from the auth section. // If already authenticated, redirect away from the auth section.
// Check this onMount rather than a reactive statement to avoid trumping // Check this onMount rather than a reactive statement to avoid trumping
@ -16,7 +16,12 @@
$admin.accountPortalUrl && $admin.accountPortalUrl &&
!$admin?.checklist?.sso?.checked !$admin?.checklist?.sso?.checked
) { ) {
window.location.href = $admin.accountPortalUrl const templateKey = $params["?template"]
let url = $admin.accountPortalUrl
if (templateKey) {
url += `?template=${templateKey}`
}
window.location.href = url
} }
</script> </script>

View File

@ -18,7 +18,7 @@
import { onMount } from "svelte" import { onMount } from "svelte"
import { apps, auth, admin } from "stores/portal" import { apps, auth, admin } from "stores/portal"
import download from "downloadjs" import download from "downloadjs"
import { goto, params } from "@roxi/routify" import { goto } from "@roxi/routify"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import AppCard from "components/start/AppCard.svelte" import AppCard from "components/start/AppCard.svelte"
import AppRow from "components/start/AppRow.svelte" import AppRow from "components/start/AppRow.svelte"
@ -201,10 +201,12 @@
await apps.load() await apps.load()
loaded = true loaded = true
// if the portal is loaded from an external URL console.log($auth)
const templateKey = $params["?template"] // if the portal is loaded from an external URL with a template param
if (!templateKey) return const templateKey = $auth.initTemplate
if (templateKey) {
createAppFromTemplateUrl(templateKey) createAppFromTemplateUrl(templateKey)
}
}) })
</script> </script>

View File

@ -33,6 +33,7 @@ export function createAuthStore() {
user: $store.user, user: $store.user,
tenantId: $store.tenantId, tenantId: $store.tenantId,
tenantSet: $store.tenantSet, tenantSet: $store.tenantSet,
initTemplate: $store.initTemplate,
loaded: $store.loaded, loaded: $store.loaded,
initials, initials,
isAdmin, isAdmin,
@ -80,8 +81,16 @@ export function createAuthStore() {
} }
} }
function updateInitTemplate(template) {
auth.update(store => {
store.initTemplate = template
return store
})
}
return { return {
subscribe: store.subscribe, subscribe: store.subscribe,
resetInitTemplate: () => updateInitTemplate(null),
setOrganisation: setOrganisation, setOrganisation: setOrganisation,
checkQueryString: async () => { checkQueryString: async () => {
const urlParams = new URLSearchParams(window.location.search) const urlParams = new URLSearchParams(window.location.search)
@ -89,6 +98,11 @@ export function createAuthStore() {
const tenantId = urlParams.get("tenantId") const tenantId = urlParams.get("tenantId")
await setOrganisation(tenantId) await setOrganisation(tenantId)
} }
// set the template to create an app from
if (urlParams.has("template")) {
updateInitTemplate(urlParams.get("template"))
}
}, },
setOrg: async tenantId => { setOrg: async tenantId => {
await setOrganisation(tenantId) await setOrganisation(tenantId)

File diff suppressed because it is too large Load Diff