Moving on implementing invitations

This commit is contained in:
Eric van der Vlist 2023-03-04 10:30:09 +01:00
parent 5ad98a860e
commit 04cd163906
2 changed files with 71 additions and 9 deletions

View File

@ -1,4 +1,6 @@
import { Component, createSignal } from 'solid-js'; import { Box, Button, TextField } from '@suid/material';
import { Component, createEffect, createSignal, Show } from 'solid-js';
import Dialog from '../dialog';
interface props {} interface props {}
@ -13,11 +15,15 @@ export const searchInvitation = () => {
const payload = hash.slice(1); const payload = hash.slice(1);
const decoded = atob(payload); const decoded = atob(payload);
const url = new URL(decoded); const url = new URL(decoded);
setInvitation(url); fetch(url)
.then((response) => response.json())
.then((data) => {
setInvitation({ url, data });
console.log({ console.log({
caller: 'Invitation / searchInvitation', caller: 'Invitation / searchInvitation',
hash, hash,
invitation: decoded, invitation: invitation(),
});
}); });
} catch { } catch {
console.warn({ console.warn({
@ -30,7 +36,62 @@ export const searchInvitation = () => {
}; };
const Invitation: Component<props> = (props) => { const Invitation: Component<props> = (props) => {
return <></>; createEffect(() => {
console.log({
caller: 'Invitation / createEffect',
invitation: invitation(),
});
});
const closeHandler = () => {};
const submitHandler = async () => {
try {
const response = await fetch(
`${invitation().url.href}/${invitation().code}`
);
const codeData = await response.json();
setInvitation({ ...invitation(), codeData });
} catch (error) {}
};
const codeChangeHandler = (event: any) => {
setInvitation({ ...invitation(), code: event.target.value });
};
return (
<Dialog
open={!!invitation()}
fullScreen={false}
closeHandler={closeHandler}
title='Invitation'
>
<Box
component='form'
sx={{
width: '100%',
'& .MuiTextField-root': { m: 1, width: '100%' },
paddingTop: '5px',
}}
noValidate
autoComplete='off'
>
<p>
Pour configurer cette application en tant que "{invitation().data.id}
", copier le code qui vous a été envoyé par mail à l'adresse "
{invitation().data.mail}" :{' '}
</p>
<TextField
required
label='Code'
type='number'
onChange={codeChangeHandler}
/>
<Button variant='contained' onClick={submitHandler}>
OK
</Button>
</Box>
</Dialog>
);
}; };
export default Invitation; export default Invitation;

View File

@ -46,7 +46,7 @@ import { Overlays } from '../overlays/Overlays';
import Finder, { findLocation } from '../finder'; import Finder, { findLocation } from '../finder';
import { ZoomIn } from '@suid/icons-material'; import { ZoomIn } from '@suid/icons-material';
import Note from '../note'; import Note from '../note';
import { searchInvitation } from '../invitation'; import Invitation, { searchInvitation } from '../invitation';
const [getState, setState] = createSignal({ const [getState, setState] = createSignal({
lon: 0, lon: 0,
@ -294,6 +294,7 @@ const Map: Component = () => {
//<OsmFetch map={getMap} /> //<OsmFetch map={getMap} />
// @ts-ignore // @ts-ignore
<div class='ol-map' ref={target}> <div class='ol-map' ref={target}>
<Invitation />
<Overlays map={getMap} /> <Overlays map={getMap} />
<Note /> <Note />
<Finder /> <Finder />