add acceptInvite method to users store
This commit is contained in:
parent
bf1d13e5a6
commit
427592431d
|
@ -1,22 +1,24 @@
|
||||||
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()
|
||||||
set(json)
|
if (json.status === 400) {
|
||||||
} catch (error) {
|
set({ config: FALLBACK_CONFIG})
|
||||||
set({
|
} else {
|
||||||
platformUrl: "",
|
set(json)
|
||||||
logoUrl: "",
|
}
|
||||||
docsUrl: "",
|
|
||||||
company: "",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -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 New Issue