Saving the new account

This commit is contained in:
Eric van der Vlist 2023-03-04 11:59:34 +01:00
parent 87b6e1710d
commit a32faaa837
3 changed files with 29 additions and 0 deletions

View File

@ -7,6 +7,8 @@ import {
Typography, Typography,
} from '@suid/material'; } from '@suid/material';
import { Component, createEffect, createSignal, Show } from 'solid-js'; import { Component, createEffect, createSignal, Show } from 'solid-js';
import { parseUserId } from '../../lib/user-id';
import dispatch from '../../workers/dispatcher-main';
import Dialog from '../dialog'; import Dialog from '../dialog';
interface props {} interface props {}
@ -18,6 +20,18 @@ const fetchInvitation = () => {
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
setInvitation({ ...invitation(), 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> = (props) => {
failure: codeData.response !== 'OK', failure: codeData.response !== 'OK',
success: 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) { } catch (error) {
setInvitation({ setInvitation({
...invitation(), ...invitation(),

View File

@ -15,6 +15,7 @@ export const getAccounts = async () => {
export const getAccount = async (params: any) => { export const getAccount = async (params: any) => {
const { id } = params; const { id } = params;
console.log({ caller: 'getAccount', params });
const uri = getUri('account', { account: id }); const uri = getUri('account', { account: id });
return (await get(uri, true)).doc; return (await get(uri, true)).doc;
}; };

View File

@ -3,6 +3,7 @@ import { initDb } from '../db';
import { import {
getAccounts, getAccounts,
getCurrentAccount, getCurrentAccount,
getAccount,
putAccount, putAccount,
putCurrentAccount, putCurrentAccount,
} from '../db/account'; } from '../db/account';
@ -69,6 +70,7 @@ onmessage = async function (e) {
putSettings, putSettings,
getAccounts, getAccounts,
getAccount,
putAccount, putAccount,
getCurrentAccount, getCurrentAccount,
putCurrentAccount, putCurrentAccount,