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 2df75d9b28
commit fa3bb8c119
5 changed files with 85 additions and 823 deletions

View File

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

View File

@ -1,6 +1,6 @@
<script>
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.
// Check this onMount rather than a reactive statement to avoid trumping
@ -16,7 +16,12 @@
$admin.accountPortalUrl &&
!$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>

View File

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

View File

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

File diff suppressed because it is too large Load Diff