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