add acceptInvite method to users store

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-12 14:07:55 +02:00
parent ecc740b5a7
commit b610bf446e
2 changed files with 18 additions and 20 deletions

View File

@ -1,21 +1,23 @@
import { writable } from "svelte/store"
import api from "builderStore/api"
const FALLBACK_CONFIG = {
platformUrl: "",
logoUrl: "",
docsUrl: "",
company: "",
}
export function createOrganisationStore() {
const { subscribe, set } = writable({})
async function init() {
try {
const response = await api.get(`/api/admin/configs/settings`)
const json = await response.json()
if (json.status === 400) {
set({ config: FALLBACK_CONFIG})
} else {
set(json)
} catch (error) {
set({
platformUrl: "",
logoUrl: "",
docsUrl: "",
company: "",
})
}
}
@ -27,7 +29,7 @@ export function createOrganisationStore() {
await init()
return { status: 200 }
} catch (error) {
return { error }
return { status: error }
}
},
init,

View File

@ -15,6 +15,10 @@ export function createUsersStore() {
const response = await api.post(`/api/admin/users/invite`, { email })
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 }) {
const response = await api.post("/api/admin/users", { email, password, roles: {} })
@ -30,17 +34,9 @@ export function createUsersStore() {
return {
subscribe,
// save: async config => {
// try {
// await api.post("/api/admin/configs", { type: "settings", config })
// await init()
// return { status: 200 }
// } catch (error) {
// return { error }
// }
// },
init,
invite,
acceptInvite,
create,
del
}