From 4733b79d75ba39aa69156c13de964bfcaef4aa3a Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 14 May 2016 15:38:00 +0300 Subject: [PATCH] #26: incapsulate auth flow rejection logic into a separate component --- src/components/auth/BaseAuthBody.jsx | 1 - src/components/auth/RejectionLink.jsx | 25 +++++++++++++++++++ src/components/auth/activation/Activation.jsx | 9 ++----- .../auth/changePassword/ChangePassword.jsx | 23 +++-------------- .../auth/forgotPassword/ForgotPassword.jsx | 9 ++----- src/components/auth/password/Password.jsx | 10 ++------ .../auth/permissions/Permissions.jsx | 23 +++-------------- src/components/auth/register/Register.jsx | 9 ++----- src/routes.js | 19 +++++++------- src/services/authFlow/LoginState.js | 5 ---- tests/services/authFlow/LoginState.test.js | 8 ------ 11 files changed, 50 insertions(+), 91 deletions(-) create mode 100644 src/components/auth/RejectionLink.jsx diff --git a/src/components/auth/BaseAuthBody.jsx b/src/components/auth/BaseAuthBody.jsx index 8184376..0548188 100644 --- a/src/components/auth/BaseAuthBody.jsx +++ b/src/components/auth/BaseAuthBody.jsx @@ -11,7 +11,6 @@ export default class BaseAuthBody extends Component { static contextTypes = { clearErrors: PropTypes.func.isRequired, resolve: PropTypes.func.isRequired, - reject: PropTypes.func.isRequired, auth: PropTypes.shape({ error: PropTypes.string, scopes: PropTypes.array diff --git a/src/components/auth/RejectionLink.jsx b/src/components/auth/RejectionLink.jsx new file mode 100644 index 0000000..6af51f8 --- /dev/null +++ b/src/components/auth/RejectionLink.jsx @@ -0,0 +1,25 @@ +import React, { PropTypes } from 'react'; + +import { FormattedMessage as Message } from 'react-intl'; + +export default function RejectionLink(props, context) { + return ( + { + event.preventDefault(); + + context.reject(); + }}> + + + ); +} + +RejectionLink.displayName = 'RejectionLink'; +RejectionLink.propTypes = { + label: PropTypes.shape({ + id: PropTypes.string + }).isRequired +}; +RejectionLink.contextTypes = { + reject: PropTypes.func.isRequired +}; diff --git a/src/components/auth/activation/Activation.jsx b/src/components/auth/activation/Activation.jsx index 13f359b..3ef3158 100644 --- a/src/components/auth/activation/Activation.jsx +++ b/src/components/auth/activation/Activation.jsx @@ -1,8 +1,7 @@ import React from 'react'; -import { FormattedMessage as Message } from 'react-intl'; - import { Button } from 'components/ui/form'; +import RejectionLink from 'components/auth/RejectionLink'; import AuthTitle from 'components/auth/AuthTitle'; import messages from './Activation.intl.json'; @@ -13,10 +12,6 @@ export default function Activation() { Title: () => , Body, Footer: () =>