mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-16 18:19:55 +05:30
Использование контекста вместо props в компонентах аутентификации
This commit is contained in:
parent
a88e958c7c
commit
518901fb57
@ -1,4 +1,4 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
@ -11,15 +11,7 @@ import styles from './activation.scss';
|
|||||||
import messages from './Activation.messages';
|
import messages from './Activation.messages';
|
||||||
|
|
||||||
class Body extends BaseAuthBody {
|
class Body extends BaseAuthBody {
|
||||||
static propTypes = {
|
static displayName = 'ActivationBody';
|
||||||
...BaseAuthBody.propTypes,
|
|
||||||
auth: PropTypes.shape({
|
|
||||||
error: PropTypes.string,
|
|
||||||
login: PropTypes.shape({
|
|
||||||
login: PropTypes.stirng
|
|
||||||
})
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -31,7 +23,7 @@ class Body extends BaseAuthBody {
|
|||||||
|
|
||||||
<div className={styles.descriptionText}>
|
<div className={styles.descriptionText}>
|
||||||
<Message {...messages.activationMailWasSent} values={{
|
<Message {...messages.activationMailWasSent} values={{
|
||||||
email: (<b>{this.props.user.email}</b>)
|
email: (<b>{this.context.user.email}</b>)
|
||||||
}} />
|
}} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,8 +11,8 @@ export default class AppInfo extends Component {
|
|||||||
static displayName = 'AppInfo';
|
static displayName = 'AppInfo';
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string,
|
||||||
description: PropTypes.string.isRequired,
|
description: PropTypes.string,
|
||||||
onGoToAuth: PropTypes.func.isRequired
|
onGoToAuth: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,29 +4,32 @@
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
|
|
||||||
import AuthError from './AuthError';
|
import AuthError from './AuthError';
|
||||||
|
import { userShape } from 'components/user/User';
|
||||||
|
|
||||||
export default class BaseAuthBody extends Component {
|
export default class BaseAuthBody extends Component {
|
||||||
static propTypes = {
|
static contextTypes = {
|
||||||
clearErrors: PropTypes.func.isRequired,
|
clearErrors: PropTypes.func.isRequired,
|
||||||
resolve: PropTypes.func.isRequired,
|
resolve: PropTypes.func.isRequired,
|
||||||
reject: PropTypes.func.isRequired,
|
reject: PropTypes.func.isRequired,
|
||||||
auth: PropTypes.shape({
|
auth: PropTypes.shape({
|
||||||
error: PropTypes.string
|
error: PropTypes.string,
|
||||||
})
|
scopes: PropTypes.array
|
||||||
|
}),
|
||||||
|
user: userShape
|
||||||
};
|
};
|
||||||
|
|
||||||
renderErrors() {
|
renderErrors() {
|
||||||
return this.props.auth.error
|
return this.context.auth.error
|
||||||
? <AuthError error={this.props.auth.error} onClose={this.onClearErrors} />
|
? <AuthError error={this.context.auth.error} onClose={this.onClearErrors} />
|
||||||
: ''
|
: ''
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
onFormSubmit() {
|
onFormSubmit() {
|
||||||
this.props.resolve(this.serialize());
|
this.context.resolve(this.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
onClearErrors = this.props.clearErrors;
|
onClearErrors = this.context.clearErrors;
|
||||||
|
|
||||||
form = {};
|
form = {};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
@ -12,16 +12,7 @@ import messages from './ForgotPassword.messages';
|
|||||||
import styles from './forgotPassword.scss';
|
import styles from './forgotPassword.scss';
|
||||||
|
|
||||||
class Body extends BaseAuthBody {
|
class Body extends BaseAuthBody {
|
||||||
static propTypes = {
|
static displayName = 'ForgotPasswordBody';
|
||||||
...BaseAuthBody.propTypes,
|
|
||||||
//login: PropTypes.func.isRequired,
|
|
||||||
auth: PropTypes.shape({
|
|
||||||
error: PropTypes.string,
|
|
||||||
login: PropTypes.shape({
|
|
||||||
email: PropTypes.stirng
|
|
||||||
})
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// Если юзер вводил своё мыло во время попытки авторизации, то почему бы его сюда автоматически не подставить?
|
// Если юзер вводил своё мыло во время попытки авторизации, то почему бы его сюда автоматически не подставить?
|
||||||
render() {
|
render() {
|
||||||
@ -50,7 +41,6 @@ class Body extends BaseAuthBody {
|
|||||||
|
|
||||||
onFormSubmit() {
|
onFormSubmit() {
|
||||||
// TODO: обработчик отправки письма с инструкцией по смене аккаунта
|
// TODO: обработчик отправки письма с инструкцией по смене аккаунта
|
||||||
//this.props.login(this.serialize());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
@ -12,15 +12,7 @@ import messages from './Login.messages';
|
|||||||
import passwordMessages from './Password.messages';
|
import passwordMessages from './Password.messages';
|
||||||
|
|
||||||
class Body extends BaseAuthBody {
|
class Body extends BaseAuthBody {
|
||||||
static propTypes = {
|
static displayName = 'LoginBody';
|
||||||
...BaseAuthBody.propTypes,
|
|
||||||
auth: PropTypes.shape({
|
|
||||||
error: PropTypes.string,
|
|
||||||
login: PropTypes.shape({
|
|
||||||
login: PropTypes.stirng
|
|
||||||
})
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
@ -10,6 +10,7 @@ import {helpLinks as helpLinksStyles} from 'components/auth/helpLinks.scss';
|
|||||||
import panelStyles from 'components/ui/panel.scss';
|
import panelStyles from 'components/ui/panel.scss';
|
||||||
import icons from 'components/ui/icons.scss';
|
import icons from 'components/ui/icons.scss';
|
||||||
import authFlow from 'services/authFlow';
|
import authFlow from 'services/authFlow';
|
||||||
|
import { userShape } from 'components/user/User';
|
||||||
|
|
||||||
import * as actions from './actions';
|
import * as actions from './actions';
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ class PanelTransition extends Component {
|
|||||||
static displayName = 'PanelTransition';
|
static displayName = 'PanelTransition';
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
// context props
|
||||||
auth: PropTypes.shape({
|
auth: PropTypes.shape({
|
||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
login: PropTypes.shape({
|
login: PropTypes.shape({
|
||||||
@ -28,8 +30,13 @@ class PanelTransition extends Component {
|
|||||||
password: PropTypes.string
|
password: PropTypes.string
|
||||||
})
|
})
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
user: userShape.isRequired,
|
||||||
setError: React.PropTypes.func.isRequired,
|
setError: React.PropTypes.func.isRequired,
|
||||||
clearErrors: React.PropTypes.func.isRequired,
|
clearErrors: React.PropTypes.func.isRequired,
|
||||||
|
resolve: React.PropTypes.func.isRequired,
|
||||||
|
reject: React.PropTypes.func.isRequired,
|
||||||
|
|
||||||
|
// local props
|
||||||
path: PropTypes.string.isRequired,
|
path: PropTypes.string.isRequired,
|
||||||
Title: PropTypes.element.isRequired,
|
Title: PropTypes.element.isRequired,
|
||||||
Body: PropTypes.element.isRequired,
|
Body: PropTypes.element.isRequired,
|
||||||
@ -37,6 +44,30 @@ class PanelTransition extends Component {
|
|||||||
Links: PropTypes.element.isRequired
|
Links: PropTypes.element.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static childContextTypes = {
|
||||||
|
auth: PropTypes.shape({
|
||||||
|
error: PropTypes.string,
|
||||||
|
login: PropTypes.shape({
|
||||||
|
login: PropTypes.string,
|
||||||
|
password: PropTypes.string
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
user: userShape,
|
||||||
|
clearErrors: React.PropTypes.func,
|
||||||
|
resolve: PropTypes.func,
|
||||||
|
reject: PropTypes.func
|
||||||
|
};
|
||||||
|
|
||||||
|
getChildContext() {
|
||||||
|
return {
|
||||||
|
auth: this.props.auth,
|
||||||
|
user: this.props.user,
|
||||||
|
clearErrors: this.props.clearErrors,
|
||||||
|
resolve: this.props.resolve,
|
||||||
|
reject: this.props.reject
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
height: {},
|
height: {},
|
||||||
contextHeight: 0
|
contextHeight: 0
|
||||||
@ -236,7 +267,7 @@ class PanelTransition extends Component {
|
|||||||
<div key={`header${key}`} style={style}>
|
<div key={`header${key}`} style={style}>
|
||||||
{hasBackButton ? backButton : null}
|
{hasBackButton ? backButton : null}
|
||||||
<div style={scrollStyle}>
|
<div style={scrollStyle}>
|
||||||
{React.cloneElement(Title, this.props)}
|
{Title}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -264,7 +295,6 @@ class PanelTransition extends Component {
|
|||||||
return (
|
return (
|
||||||
<ReactHeight key={`body${key}`} style={style} onHeightReady={this.onUpdateHeight}>
|
<ReactHeight key={`body${key}`} style={style} onHeightReady={this.onUpdateHeight}>
|
||||||
{React.cloneElement(Body, {
|
{React.cloneElement(Body, {
|
||||||
...this.props,
|
|
||||||
ref: (body) => {
|
ref: (body) => {
|
||||||
this.body = body;
|
this.body = body;
|
||||||
}
|
}
|
||||||
@ -280,7 +310,7 @@ class PanelTransition extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={`footer${key}`} style={style}>
|
<div key={`footer${key}`} style={style}>
|
||||||
{React.cloneElement(Footer, this.props)}
|
{Footer}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -292,7 +322,7 @@ class PanelTransition extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={`links${key}`} style={style}>
|
<div key={`links${key}`} style={style}>
|
||||||
{React.cloneElement(Links, this.props)}
|
{Links}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
@ -13,19 +13,10 @@ import styles from './password.scss';
|
|||||||
import messages from './Password.messages';
|
import messages from './Password.messages';
|
||||||
|
|
||||||
class Body extends BaseAuthBody {
|
class Body extends BaseAuthBody {
|
||||||
static propTypes = {
|
static displayName = 'PasswordBody';
|
||||||
...BaseAuthBody.propTypes,
|
|
||||||
auth: PropTypes.shape({
|
|
||||||
error: PropTypes.string,
|
|
||||||
login: PropTypes.shape({
|
|
||||||
login: PropTypes.stirng,
|
|
||||||
password: PropTypes.stirng
|
|
||||||
})
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {user} = this.props;
|
const {user} = this.context;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -2,7 +2,6 @@ import React, { PropTypes } from 'react';
|
|||||||
|
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
import { Link } from 'react-router';
|
|
||||||
|
|
||||||
import buttons from 'components/ui/buttons.scss';
|
import buttons from 'components/ui/buttons.scss';
|
||||||
import { Input } from 'components/ui/Form';
|
import { Input } from 'components/ui/Form';
|
||||||
@ -14,9 +13,7 @@ import icons from 'components/ui/icons.scss';
|
|||||||
import styles from './passwordChange.scss';
|
import styles from './passwordChange.scss';
|
||||||
|
|
||||||
class Body extends BaseAuthBody {
|
class Body extends BaseAuthBody {
|
||||||
static propTypes = {
|
static displayName = 'PasswordChangeBody';
|
||||||
...BaseAuthBody.propTypes
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -52,7 +49,7 @@ class Body extends BaseAuthBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function PasswordChange() {
|
export default function PasswordChange() {
|
||||||
return {
|
const componentsMap = {
|
||||||
Title: () => ( // TODO: separate component for PageTitle
|
Title: () => ( // TODO: separate component for PageTitle
|
||||||
<Message {...passwordChangedMessages.changePasswordTitle}>
|
<Message {...passwordChangedMessages.changePasswordTitle}>
|
||||||
{(msg) => <span>{msg}<Helmet title={msg} /></span>}
|
{(msg) => <span>{msg}<Helmet title={msg} /></span>}
|
||||||
@ -64,14 +61,20 @@ export default function PasswordChange() {
|
|||||||
<Message {...passwordChangedMessages.change} />
|
<Message {...passwordChangedMessages.change} />
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
Links: (props) => (
|
Links: (props, context) => (
|
||||||
<a href="#" onClick={(event) => {
|
<a href="#" onClick={(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
props.reject();
|
context.reject();
|
||||||
}}>
|
}}>
|
||||||
<Message {...passwordChangedMessages.skipThisStep} />
|
<Message {...passwordChangedMessages.skipThisStep} />
|
||||||
</a>
|
</a>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentsMap.Links.contextTypes = {
|
||||||
|
reject: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
return componentsMap;
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,11 @@ import styles from './permissions.scss';
|
|||||||
import messages from './Permissions.messages';
|
import messages from './Permissions.messages';
|
||||||
|
|
||||||
class Body extends BaseAuthBody {
|
class Body extends BaseAuthBody {
|
||||||
static propTypes = {
|
static displayName = 'PermissionsBody';
|
||||||
...BaseAuthBody.propTypes,
|
|
||||||
auth: PropTypes.shape({
|
|
||||||
error: PropTypes.string,
|
|
||||||
scopes: PropTypes.array.isRequired
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {user} = this.props;
|
const {user} = this.context;
|
||||||
const scopes = this.props.auth.scopes;
|
const scopes = this.context.auth.scopes;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -61,7 +55,7 @@ class Body extends BaseAuthBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Permissions() {
|
export default function Permissions() {
|
||||||
return {
|
const componentsMap = {
|
||||||
Title: () => ( // TODO: separate component for PageTitle
|
Title: () => ( // TODO: separate component for PageTitle
|
||||||
<Message {...messages.permissionsTitle}>
|
<Message {...messages.permissionsTitle}>
|
||||||
{(msg) => <span>{msg}<Helmet title={msg} /></span>}
|
{(msg) => <span>{msg}<Helmet title={msg} /></span>}
|
||||||
@ -73,14 +67,20 @@ export default function Permissions() {
|
|||||||
<Message {...messages.approve} />
|
<Message {...messages.approve} />
|
||||||
</button>
|
</button>
|
||||||
),
|
),
|
||||||
Links: (props) => (
|
Links: (props, context) => (
|
||||||
<a href="#" onClick={(event) => {
|
<a href="#" onClick={(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
props.reject();
|
context.reject();
|
||||||
}}>
|
}}>
|
||||||
<Message {...messages.decline} />
|
<Message {...messages.decline} />
|
||||||
</a>
|
</a>
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentsMap.Links.contextTypes = {
|
||||||
|
reject: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
return componentsMap;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
@ -13,20 +13,7 @@ import activationMessages from './Activation.messages';
|
|||||||
// TODO: password and username can be validate for length and sameness
|
// TODO: password and username can be validate for length and sameness
|
||||||
|
|
||||||
class Body extends BaseAuthBody {
|
class Body extends BaseAuthBody {
|
||||||
static propTypes = {
|
static displayName = 'RegisterBody';
|
||||||
...BaseAuthBody.propTypes,
|
|
||||||
register: PropTypes.func.isRequired,
|
|
||||||
auth: PropTypes.shape({
|
|
||||||
error: PropTypes.string,
|
|
||||||
register: PropTypes.shape({
|
|
||||||
email: PropTypes.string,
|
|
||||||
username: PropTypes.stirng,
|
|
||||||
password: PropTypes.stirng,
|
|
||||||
rePassword: PropTypes.stirng,
|
|
||||||
rulesAgreement: PropTypes.boolean
|
|
||||||
})
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
@ -14,7 +14,7 @@ export class Input extends Component {
|
|||||||
id: PropTypes.string
|
id: PropTypes.string
|
||||||
}),
|
}),
|
||||||
icon: PropTypes.string,
|
icon: PropTypes.string,
|
||||||
color: PropTypes.oneOf(['green', 'blue', 'red'])
|
color: PropTypes.oneOf(['green', 'blue', 'red', 'lightViolet', 'darkBlue'])
|
||||||
};
|
};
|
||||||
|
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
|
Loading…
Reference in New Issue
Block a user