add acceptInvite method to users store
This commit is contained in:
parent
ecc740b5a7
commit
b610bf446e
2 changed files with 18 additions and 20 deletions
|
@ -1,21 +1,23 @@
|
||||||
import { writable } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
|
||||||
|
const FALLBACK_CONFIG = {
|
||||||
|
platformUrl: "",
|
||||||
|
logoUrl: "",
|
||||||
|
docsUrl: "",
|
||||||
|
company: "",
|
||||||
|
}
|
||||||
|
|
||||||
export function createOrganisationStore() {
|
export function createOrganisationStore() {
|
||||||
const { subscribe, set } = writable({})
|
const { subscribe, set } = writable({})
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
|
||||||
const response = await api.get(`/api/admin/configs/settings`)
|
const response = await api.get(`/api/admin/configs/settings`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
if (json.status === 400) {
|
||||||
|
set({ config: FALLBACK_CONFIG})
|
||||||
|
} else {
|
||||||
set(json)
|
set(json)
|
||||||
} catch (error) {
|
|
||||||
set({
|
|
||||||
platformUrl: "",
|
|
||||||
logoUrl: "",
|
|
||||||
docsUrl: "",
|
|
||||||
company: "",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +29,7 @@ export function createOrganisationStore() {
|
||||||
await init()
|
await init()
|
||||||
return { status: 200 }
|
return { status: 200 }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { error }
|
return { status: error }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
init,
|
init,
|
||||||
|
|
|
@ -15,6 +15,10 @@ export function createUsersStore() {
|
||||||
const response = await api.post(`/api/admin/users/invite`, { email })
|
const response = await api.post(`/api/admin/users/invite`, { email })
|
||||||
return await response.json()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
async function acceptInvite(inviteCode, password) {
|
||||||
|
const response = await api.post("/api/admin/users/invite/accept", { inviteCode, password })
|
||||||
|
return await response.json()
|
||||||
|
}
|
||||||
|
|
||||||
async function create({ email, password }) {
|
async function create({ email, password }) {
|
||||||
const response = await api.post("/api/admin/users", { email, password, roles: {} })
|
const response = await api.post("/api/admin/users", { email, password, roles: {} })
|
||||||
|
@ -30,17 +34,9 @@ export function createUsersStore() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
// save: async config => {
|
|
||||||
// try {
|
|
||||||
// await api.post("/api/admin/configs", { type: "settings", config })
|
|
||||||
// await init()
|
|
||||||
// return { status: 200 }
|
|
||||||
// } catch (error) {
|
|
||||||
// return { error }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
init,
|
init,
|
||||||
invite,
|
invite,
|
||||||
|
acceptInvite,
|
||||||
create,
|
create,
|
||||||
del
|
del
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue