Cosmetics

This commit is contained in:
Eric van der Vlist 2023-03-04 11:08:14 +01:00
parent 24fb46c0fb
commit 87b6e1710d
1 changed files with 25 additions and 14 deletions

View File

@ -13,6 +13,14 @@ interface props {}
const [invitation, setInvitation] = createSignal<any>(false); const [invitation, setInvitation] = createSignal<any>(false);
const fetchInvitation = () => {
fetch(invitation().url)
.then((response) => response.json())
.then((data) => {
setInvitation({ ...invitation(), data });
});
};
export const searchInvitation = () => { export const searchInvitation = () => {
const hash = location.hash; const hash = location.hash;
console.log({ caller: 'Invitation / searchInvitation', hash }); console.log({ caller: 'Invitation / searchInvitation', hash });
@ -22,16 +30,8 @@ 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);
fetch(url) setInvitation({ url });
.then((response) => response.json()) fetchInvitation();
.then((data) => {
setInvitation({ url, data });
console.log({
caller: 'Invitation / searchInvitation',
hash,
invitation: invitation(),
});
});
} catch { } catch {
console.warn({ console.warn({
caller: 'Invitation / searchInvitation', caller: 'Invitation / searchInvitation',
@ -63,7 +63,12 @@ const Invitation: Component<props> = (props) => {
failure: codeData.response !== 'OK', failure: codeData.response !== 'OK',
success: codeData.response === 'OK', success: codeData.response === 'OK',
}); });
} catch (error) {} } catch (error) {
setInvitation({
...invitation(),
failure: true,
});
}
}; };
const codeChangeHandler = (event: any) => { const codeChangeHandler = (event: any) => {
@ -74,14 +79,14 @@ const Invitation: Component<props> = (props) => {
setInvitation({ ...invitation(), failure: undefined }); setInvitation({ ...invitation(), failure: undefined });
}; };
const handleModalSuccessClose = () => { const handleCloseAll = () => {
setInvitation(false); setInvitation(false);
}; };
return ( return (
<> <>
<Dialog <Dialog
open={!!invitation()} open={!!invitation() && !!invitation().data}
fullScreen={false} fullScreen={false}
closeHandler={closeHandler} closeHandler={closeHandler}
title='Invitation' title='Invitation'
@ -111,6 +116,12 @@ const Invitation: Component<props> = (props) => {
<Button variant='contained' onClick={submitHandler}> <Button variant='contained' onClick={submitHandler}>
OK OK
</Button> </Button>
<Button variant='outlined' onClick={fetchInvitation}>
Renvoyer le code
</Button>
<Button variant='outlined' color='error' onClick={handleCloseAll}>
Annuler
</Button>
</Box> </Box>
</Dialog> </Dialog>
<Modal <Modal
@ -136,7 +147,7 @@ const Invitation: Component<props> = (props) => {
</Modal>{' '} </Modal>{' '}
<Modal <Modal
open={!!invitation().success} open={!!invitation().success}
onClose={handleModalSuccessClose} onClose={handleCloseAll}
aria-labelledby='modal-modal-title' aria-labelledby='modal-modal-title'
aria-describedby='modal-modal-description' aria-describedby='modal-modal-description'
> >