From a32faaa8373489bb14bd0b7dcf6f1a83a06fa603 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Sat, 4 Mar 2023 11:59:34 +0100 Subject: [PATCH] Saving the new account --- src/components/invitation/Invitation.tsx | 26 ++++++++++++++++++++++++ src/db/account.ts | 1 + src/workers/dispatcher-worker.ts | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/components/invitation/Invitation.tsx b/src/components/invitation/Invitation.tsx index b86e782..4a77fc0 100644 --- a/src/components/invitation/Invitation.tsx +++ b/src/components/invitation/Invitation.tsx @@ -7,6 +7,8 @@ import { Typography, } from '@suid/material'; import { Component, createEffect, createSignal, Show } from 'solid-js'; +import { parseUserId } from '../../lib/user-id'; +import dispatch from '../../workers/dispatcher-main'; import Dialog from '../dialog'; interface props {} @@ -18,6 +20,18 @@ const fetchInvitation = () => { .then((response) => response.json()) .then((data) => { setInvitation({ ...invitation(), data }); + return invitation(); + }) + .then(() => { + dispatch({ + action: 'getAccount', + params: { id: invitation().data.id }, + }).then((account) => { + console.log({ caller: 'Invitation / fetchInvitation', account }); + }); + }) + .catch((error) => { + console.error({ caller: 'Invitation / fetchInvitation', error }); }); }; @@ -63,6 +77,18 @@ const Invitation: Component = (props) => { failure: codeData.response !== 'OK', success: codeData.response === 'OK', }); + const user = invitation().codeData.user; + const id = user._id; + const account = { + id, + localDb: id, + name: id, + remoteDbServer: user.database, + remoteDbUser: user.username, + remoteDbPassword: user.password, + mail: user.mail, + }; + dispatch({ action: 'putAccount', params: { id, account } }); } catch (error) { setInvitation({ ...invitation(), diff --git a/src/db/account.ts b/src/db/account.ts index bed34d3..409574f 100644 --- a/src/db/account.ts +++ b/src/db/account.ts @@ -15,6 +15,7 @@ export const getAccounts = async () => { export const getAccount = async (params: any) => { const { id } = params; + console.log({ caller: 'getAccount', params }); const uri = getUri('account', { account: id }); return (await get(uri, true)).doc; }; diff --git a/src/workers/dispatcher-worker.ts b/src/workers/dispatcher-worker.ts index 69857f0..9a78116 100644 --- a/src/workers/dispatcher-worker.ts +++ b/src/workers/dispatcher-worker.ts @@ -3,6 +3,7 @@ import { initDb } from '../db'; import { getAccounts, getCurrentAccount, + getAccount, putAccount, putCurrentAccount, } from '../db/account'; @@ -69,6 +70,7 @@ onmessage = async function (e) { putSettings, getAccounts, + getAccount, putAccount, getCurrentAccount, putCurrentAccount,