signup flow now works correctly
This commit is contained in:
parent
2f10f51cd4
commit
667e70a706
|
@ -1,14 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
import Button from "components/common/Button.svelte"
|
import Button from "components/common/Button.svelte"
|
||||||
export let name,
|
export let name, _id
|
||||||
description = `A minimalist CRM which removes the noise and allows you to focus
|
|
||||||
on your business.`,
|
|
||||||
_id
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="apps-card">
|
<div class="apps-card">
|
||||||
<h3 class="app-title">{name}</h3>
|
<h3 class="app-title">{name}</h3>
|
||||||
<p class="app-desc">{description}</p>
|
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<a href={`/_builder/${_id}`} class="app-button">Open {name}</a>
|
<a href={`/_builder/${_id}`} class="app-button">Open {name}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { store, workflowStore, backendUiStore } from "builderStore"
|
||||||
import { string, object } from "yup"
|
import { string, object } from "yup"
|
||||||
import api from "builderStore/api"
|
import api, { get } from "builderStore/api"
|
||||||
import Form from "@svelteschool/svelte-forms"
|
import Form from "@svelteschool/svelte-forms"
|
||||||
import Spinner from "components/common/Spinner.svelte"
|
import Spinner from "components/common/Spinner.svelte"
|
||||||
import { API, Info, User } from "./Steps"
|
import { API, Info, User } from "./Steps"
|
||||||
|
@ -114,27 +115,48 @@
|
||||||
async function signUp() {
|
async function signUp() {
|
||||||
submitting = true
|
submitting = true
|
||||||
try {
|
try {
|
||||||
|
// Add API key if there is none.
|
||||||
if (!hasKey) {
|
if (!hasKey) {
|
||||||
await updateKey(["budibase", $createAppStore.values.apiKey])
|
await updateKey(["budibase", $createAppStore.values.apiKey])
|
||||||
}
|
}
|
||||||
const response = await post("/api/applications", {
|
|
||||||
|
// Create App
|
||||||
|
const appResp = await post("/api/applications", {
|
||||||
name: $createAppStore.values.applicationName,
|
name: $createAppStore.values.applicationName,
|
||||||
})
|
})
|
||||||
const res = await response.json()
|
const appJson = await appResp.json()
|
||||||
analytics.captureEvent("web_app_created", {
|
analytics.captureEvent("web_app_created", {
|
||||||
name,
|
name,
|
||||||
description,
|
appId: appJson._id,
|
||||||
appId: res._id,
|
|
||||||
})
|
})
|
||||||
console.log("App created!")
|
|
||||||
// $goto(`./${res._id}`)
|
// Select Correct Application/DB in prep for creating user
|
||||||
|
const applicationPkg = await get(`/api/${appJson._id}/appPackage`)
|
||||||
|
const pkg = await applicationPkg.json()
|
||||||
|
if (applicationPkg.ok) {
|
||||||
|
backendUiStore.actions.reset()
|
||||||
|
await store.setPackage(pkg)
|
||||||
|
workflowStore.actions.fetch()
|
||||||
|
} else {
|
||||||
|
throw new Error(pkg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create user
|
||||||
|
const user = {
|
||||||
|
name: $createAppStore.values.username,
|
||||||
|
username: $createAppStore.values.username,
|
||||||
|
password: $createAppStore.values.password,
|
||||||
|
accessLevelId: $createAppStore.values.accessLevelId,
|
||||||
|
}
|
||||||
|
const userResp = await api.post(`/api/users`, user)
|
||||||
|
const json = await userResp.json()
|
||||||
|
$goto(`./${appJson._id}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateKey([key, value]) {
|
async function updateKey([key, value]) {
|
||||||
console.log("Saving API Key")
|
|
||||||
const response = await api.put(`/api/keys/${key}`, { value })
|
const response = await api.put(`/api/keys/${key}`, { value })
|
||||||
const res = await response.json()
|
const res = await response.json()
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export { default as API } from './API.svelte'
|
export { default as API } from "./API.svelte"
|
||||||
export { default as Info } from './Info.svelte'
|
export { default as Info } from "./Info.svelte"
|
||||||
export { default as User } from './User.svelte'
|
export { default as User } from "./User.svelte"
|
||||||
|
|
|
@ -69,7 +69,6 @@ exports.create = async function(ctx) {
|
||||||
"@budibase/materialdesign-components",
|
"@budibase/materialdesign-components",
|
||||||
],
|
],
|
||||||
name: ctx.request.body.name,
|
name: ctx.request.body.name,
|
||||||
description: ctx.request.body.description,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { rev } = await db.put(newApplication)
|
const { rev } = await db.put(newApplication)
|
||||||
|
|
Loading…
Reference in New Issue