From 807a26bd5e71137aeed581f3742ee5065828c177 Mon Sep 17 00:00:00 2001 From: cballevre Date: Tue, 27 Jun 2023 18:30:59 +0200 Subject: [PATCH] feat: Add AuthentificationDialog --- .../AuthentificationDialog.jsx | 109 ++++++++++++++++++ react/CozyDialogs/SpecificDialogs/Readme.md | 58 ++++++++++ react/CozyDialogs/SpecificDialogs/index.jsx | 1 + .../SpecificDialogs/locales/en.json | 14 +++ .../SpecificDialogs/locales/fr.json | 14 +++ react/CozyDialogs/index.jsx | 5 +- 6 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 react/CozyDialogs/SpecificDialogs/AuthentificationDialog.jsx diff --git a/react/CozyDialogs/SpecificDialogs/AuthentificationDialog.jsx b/react/CozyDialogs/SpecificDialogs/AuthentificationDialog.jsx new file mode 100644 index 0000000000..c1b82ec760 --- /dev/null +++ b/react/CozyDialogs/SpecificDialogs/AuthentificationDialog.jsx @@ -0,0 +1,109 @@ +import React, { useMemo, useState } from 'react' +import PropTypes from 'prop-types' + +import PermissionDialog from '../PermissionDialog' +import Buttons from '../../Buttons' +import { useI18n } from '../../I18n' +import Typography from '../../Typography' +import { useClient } from 'cozy-client' +import CozyAuthentificationIcon from '../../Icons/CozyAuthentification' +import PasswordField from '../../PasswordField' + +import withSpecificDialogsLocales from './withSpecificDialogsLocales' + +/** + * Dialog used to authenticate a user in the cozy system. + * The authentication logic is implemented in the applications. + */ +const AuthentificationDialog = ({ + onClose, + onSubmit, + isLoading, + isOIDC, + error +}) => { + const { t } = useI18n() + const client = useClient() + const [password, setPassword] = useState('') + + const handleSubmit = e => { + e.preventDefault() + onSubmit(password) + } + + const onPasswordChange = e => { + setPassword(e.currentTarget.value) + } + + const passphraseResetUrl = useMemo(() => { + const url = new URL('/auth/passphrase_reset', client.getStackClient().uri) + return url.href + }, [client]) + + return ( + + + {t('authentification-dialog.subtitle')} + + + + {t('authentification-dialog.forgotten-password')} + + + } + actions={ + + } + /> + ) +} + +AuthentificationDialog.defaultProps = { + isOIDC: false +} + +AuthentificationDialog.propTypes = { + /** A function call on clicking the close button */ + onClose: PropTypes.func, + /** A function call on submitting the form with the password entered */ + onSubmit: PropTypes.func, + /** Waiting status, e.g. processing of form submission */ + isLoading: PropTypes.bool, + /** Show specific wording for OIDC */ + isOIDC: PropTypes.bool, + /** Error key to display a message */ + error: PropTypes.string +} + +export default withSpecificDialogsLocales(AuthentificationDialog) diff --git a/react/CozyDialogs/SpecificDialogs/Readme.md b/react/CozyDialogs/SpecificDialogs/Readme.md index c7c5f0691b..0d60f3203f 100644 --- a/react/CozyDialogs/SpecificDialogs/Readme.md +++ b/react/CozyDialogs/SpecificDialogs/Readme.md @@ -21,3 +21,61 @@ const [open, setOpen] = useState(isTesting()); { setOpen(true) }} label="Open InstallFlagshipAppDialog" /> ``` + +### Authentification dialog + +Dialog used to authenticate a user in the cozy system. The authentication logic is implemented in the applications. + +```jsx +import { AuthentificationDialog } from 'cozy-ui/transpiled/react/CozyDialogs' +import Button from 'cozy-ui/transpiled/react/Buttons' +import DemoProvider from 'cozy-ui/docs/components/DemoProvider' +import Variants from 'cozy-ui/docs/components/Variants' +import FormControlLabel from 'cozy-ui/transpiled/react/FormControlLabel' +import RadioGroup from 'cozy-ui/transpiled/react/RadioGroup' +import Radio from 'cozy-ui/transpiled/react/Radios' +import FormControl from 'cozy-ui/transpiled/react/FormControl' +import FormLabel from 'cozy-ui/transpiled/react/FormLabel' + +initialState = { showModal: false }; + +const initialVariants = [{ + closable: true, + loading: false, + oidc: false +}] + +const initialErrors = [{ + default: true, + invalid_password: false, + server: false +}] + +const onClose = () => setState({ showModal: false }) + +const onAuthentification = () => { + alert('authentification') + setState({ showModal: false }) +}; + + + {variant => ( + + {error => ( + +