From b610bf446e62aeaee699904bf1842727237f203f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Wed, 12 May 2021 14:07:55 +0200 Subject: [PATCH] add acceptInvite method to users store --- .../builder/src/stores/portal/organisation.js | 24 ++++++++++--------- packages/builder/src/stores/portal/users.js | 14 ++++------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/builder/src/stores/portal/organisation.js b/packages/builder/src/stores/portal/organisation.js index 7926121ea3..19ef091f21 100644 --- a/packages/builder/src/stores/portal/organisation.js +++ b/packages/builder/src/stores/portal/organisation.js @@ -1,22 +1,24 @@ 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() - set(json) - } catch (error) { - set({ - platformUrl: "", - logoUrl: "", - docsUrl: "", - company: "", - }) - } + if (json.status === 400) { + set({ config: FALLBACK_CONFIG}) + } else { + set(json) + } } return { @@ -27,7 +29,7 @@ export function createOrganisationStore() { await init() return { status: 200 } } catch (error) { - return { error } + return { status: error } } }, init, diff --git a/packages/builder/src/stores/portal/users.js b/packages/builder/src/stores/portal/users.js index d5833c43e1..606a888316 100644 --- a/packages/builder/src/stores/portal/users.js +++ b/packages/builder/src/stores/portal/users.js @@ -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 }