mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-28 07:50:32 +05:30
#22: decpouple ApplicationsIndex from HOCs. Create ContactLink component
This commit is contained in:
parent
e66840a391
commit
f6b925122f
22
src/components/contact/ContactLink.js
Normal file
22
src/components/contact/ContactLink.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// @flow
|
||||||
|
import React from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { create as createPopup } from 'components/ui/popup/actions';
|
||||||
|
import ContactForm from './ContactForm';
|
||||||
|
|
||||||
|
function ContactLink({createContactPopup, ...props}: {
|
||||||
|
createContactPopup: () => void,
|
||||||
|
props: Object
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<a href="#" onClick={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
createContactPopup();
|
||||||
|
}} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(null, {
|
||||||
|
createContactPopup: () => createPopup(ContactForm),
|
||||||
|
})(ContactLink);
|
3
src/components/contact/index.js
Normal file
3
src/components/contact/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// @flow
|
||||||
|
|
||||||
|
export { default as ContactLink } from './ContactLink';
|
@ -1,17 +1,13 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import type { Node } from 'react';
|
import type { Node } from 'react';
|
||||||
import type { Location } from 'react-router';
|
|
||||||
import type { OauthAppResponse } from 'services/api/oauth';
|
import type { OauthAppResponse } from 'services/api/oauth';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } 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 { connect } from 'react-redux';
|
|
||||||
import { withRouter } from 'react-router';
|
|
||||||
import { create as createPopup } from 'components/ui/popup/actions';
|
|
||||||
import ContactForm from 'components/contact/ContactForm';
|
|
||||||
import { LinkButton } from 'components/ui/form';
|
import { LinkButton } from 'components/ui/form';
|
||||||
import { COLOR_GREEN, COLOR_BLUE } from 'components/ui';
|
import { COLOR_GREEN, COLOR_BLUE } from 'components/ui';
|
||||||
import { restoreScroll } from 'components/ui/scroll/scroll';
|
import { restoreScroll } from 'components/ui/scroll/scroll';
|
||||||
|
import { ContactLink } from 'components/contact';
|
||||||
|
|
||||||
import styles from './applicationsIndex.scss';
|
import styles from './applicationsIndex.scss';
|
||||||
import messages from './ApplicationsIndex.intl.json';
|
import messages from './ApplicationsIndex.intl.json';
|
||||||
@ -21,11 +17,10 @@ import toolsIcon from './icons/tools.svg';
|
|||||||
import ApplicationItem from './ApplicationItem';
|
import ApplicationItem from './ApplicationItem';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
location: Location,
|
clientId?: ?string,
|
||||||
displayForGuest: bool,
|
displayForGuest: bool,
|
||||||
applications: Array<OauthAppResponse>,
|
applications: Array<OauthAppResponse>,
|
||||||
isLoading: bool,
|
isLoading: bool,
|
||||||
createContactPopup: () => void,
|
|
||||||
deleteApp: (string) => Promise<any>,
|
deleteApp: (string) => Promise<any>,
|
||||||
resetApp: (string, bool) => Promise<any>,
|
resetApp: (string, bool) => Promise<any>,
|
||||||
};
|
};
|
||||||
@ -34,7 +29,7 @@ type State = {
|
|||||||
expandedApp: ?string,
|
expandedApp: ?string,
|
||||||
};
|
};
|
||||||
|
|
||||||
class ApplicationsIndex extends Component<Props, State> {
|
export default class ApplicationsIndex extends Component<Props, State> {
|
||||||
state = {
|
state = {
|
||||||
expandedApp: null,
|
expandedApp: null,
|
||||||
};
|
};
|
||||||
@ -42,13 +37,11 @@ class ApplicationsIndex extends Component<Props, State> {
|
|||||||
appsRefs: {[key: string]: ?HTMLDivElement} = {};
|
appsRefs: {[key: string]: ?HTMLDivElement} = {};
|
||||||
|
|
||||||
componentDidUpdate(prevProps: Props) {
|
componentDidUpdate(prevProps: Props) {
|
||||||
const { applications, isLoading, location } = this.props;
|
const { applications, isLoading, clientId } = this.props;
|
||||||
|
|
||||||
if (isLoading !== prevProps.isLoading && applications.length) {
|
if (isLoading !== prevProps.isLoading && applications.length) {
|
||||||
const hash = location.hash.substr(1);
|
if (clientId && applications.some((app) => app.clientId === clientId)) {
|
||||||
|
requestAnimationFrame(() => this.onTileClick(clientId));
|
||||||
if (hash !== '' && applications.some((app) => app.clientId === hash)) {
|
|
||||||
requestAnimationFrame(() => this.onTileClick(hash));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,9 +155,9 @@ class ApplicationsIndex extends Component<Props, State> {
|
|||||||
<div className={styles.welcomeParagraph}>
|
<div className={styles.welcomeParagraph}>
|
||||||
<Message {...messages.ifYouHaveAnyTroubles} values={{
|
<Message {...messages.ifYouHaveAnyTroubles} values={{
|
||||||
feedback: (
|
feedback: (
|
||||||
<a href="#" onClick={this.onContact}>
|
<ContactLink>
|
||||||
<Message {...messages.feedback} />
|
<Message {...messages.feedback} />
|
||||||
</a>
|
</ContactLink>
|
||||||
),
|
),
|
||||||
}} />
|
}} />
|
||||||
</div>
|
</div>
|
||||||
@ -185,14 +178,4 @@ class ApplicationsIndex extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onContact = (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
this.props.createContactPopup();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withRouter(connect(null, {
|
|
||||||
createContactPopup: () => createPopup(ContactForm),
|
|
||||||
})(ApplicationsIndex));
|
|
||||||
|
@ -3,9 +3,9 @@ import React, { Component } from 'react';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { FormattedMessage as Message } from 'react-intl';
|
import { FormattedMessage as Message } from 'react-intl';
|
||||||
import ContactForm from 'components/contact/ContactForm';
|
|
||||||
import LanguageSwitcher from 'components/languageSwitcher';
|
import LanguageSwitcher from 'components/languageSwitcher';
|
||||||
import { create as createPopup } from 'components/ui/popup/actions';
|
import { create as createPopup } from 'components/ui/popup/actions';
|
||||||
|
import { ContactLink } from 'components/contact';
|
||||||
|
|
||||||
import styles from './footerMenu.scss';
|
import styles from './footerMenu.scss';
|
||||||
import messages from './footerMenu.intl.json';
|
import messages from './footerMenu.intl.json';
|
||||||
@ -23,9 +23,9 @@ class FooterMenu extends Component<{
|
|||||||
<Message {...messages.rules} />
|
<Message {...messages.rules} />
|
||||||
</Link>
|
</Link>
|
||||||
{' | '}
|
{' | '}
|
||||||
<a href="#" onClick={this.onContact}>
|
<ContactLink>
|
||||||
<Message {...messages.contactUs} />
|
<Message {...messages.contactUs} />
|
||||||
</a>
|
</ContactLink>
|
||||||
{' | '}
|
{' | '}
|
||||||
<Link to="/dev">
|
<Link to="/dev">
|
||||||
<Message {...messages.forDevelopers} />
|
<Message {...messages.forDevelopers} />
|
||||||
@ -41,13 +41,9 @@ class FooterMenu extends Component<{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onContact = (event) => {
|
onLanguageSwitcher = (event: SyntheticMouseEvent<HTMLElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.props.createContactPopup();
|
|
||||||
};
|
|
||||||
|
|
||||||
onLanguageSwitcher = (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
this.props.createLanguageSwitcherPopup();
|
this.props.createLanguageSwitcherPopup();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -55,6 +51,5 @@ class FooterMenu extends Component<{
|
|||||||
// mark this component, as not pure, because it is stateless,
|
// mark this component, as not pure, because it is stateless,
|
||||||
// but should be re-rendered, if current lang was changed
|
// but should be re-rendered, if current lang was changed
|
||||||
export default connect(null, {
|
export default connect(null, {
|
||||||
createContactPopup: () => createPopup(ContactForm),
|
|
||||||
createLanguageSwitcherPopup: () => createPopup(LanguageSwitcher),
|
createLanguageSwitcherPopup: () => createPopup(LanguageSwitcher),
|
||||||
}, null, {pure: false})(FooterMenu);
|
}, null, {pure: false})(FooterMenu);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// @flow
|
||||||
|
import type { ElementType } from 'react';
|
||||||
export const POPUP_CREATE = 'POPUP_CREATE';
|
export const POPUP_CREATE = 'POPUP_CREATE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,7 +9,10 @@ export const POPUP_CREATE = 'POPUP_CREATE';
|
|||||||
*
|
*
|
||||||
* @return {object}
|
* @return {object}
|
||||||
*/
|
*/
|
||||||
export function create(payload) {
|
export function create(payload: ElementType | {
|
||||||
|
Popup: ElementType,
|
||||||
|
disableOverlayClose?: bool,
|
||||||
|
}) {
|
||||||
if (typeof payload === 'function') {
|
if (typeof payload === 'function') {
|
||||||
payload = {
|
payload = {
|
||||||
Popup: payload
|
Popup: payload
|
||||||
@ -21,7 +26,7 @@ export function create(payload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const POPUP_DESTROY = 'POPUP_DESTROY';
|
export const POPUP_DESTROY = 'POPUP_DESTROY';
|
||||||
export function destroy(popup) {
|
export function destroy(popup: ElementType) {
|
||||||
return {
|
return {
|
||||||
type: POPUP_DESTROY,
|
type: POPUP_DESTROY,
|
||||||
payload: popup
|
payload: popup
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React, { Component } from 'react';
|
|
||||||
|
|
||||||
import ApplicationsIndex from 'components/dev/apps/ApplicationsIndex';
|
|
||||||
|
|
||||||
import type { User } from 'components/user';
|
import type { User } from 'components/user';
|
||||||
import type { OauthAppResponse } from 'services/api/oauth';
|
import type { OauthAppResponse } from 'services/api/oauth';
|
||||||
|
import type { Location } from 'react-router';
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { fetchAvailableApps, resetApp, deleteApp } from 'components/dev/apps/actions';
|
||||||
|
import ApplicationsIndex from 'components/dev/apps/ApplicationsIndex';
|
||||||
|
|
||||||
class ApplicationsListPage extends Component<{
|
class ApplicationsListPage extends Component<{
|
||||||
|
location: Location,
|
||||||
user: User,
|
user: User,
|
||||||
apps: Array<OauthAppResponse>,
|
apps: Array<OauthAppResponse>,
|
||||||
fetchAvailableApps: () => Promise<*>,
|
fetchAvailableApps: () => Promise<void>,
|
||||||
deleteApp: (string) => Promise<*>,
|
deleteApp: (string) => Promise<void>,
|
||||||
resetApp: (string, bool) => Promise<*>,
|
resetApp: (string, bool) => Promise<void>,
|
||||||
}, {
|
}, {
|
||||||
isLoading: bool,
|
isLoading: bool,
|
||||||
}> {
|
}> {
|
||||||
static displayName = 'ApplicationsListPage';
|
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
appsList: [],
|
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentWillMount() {
|
componentDidMount() {
|
||||||
!this.props.user.isGuest && this.loadApplicationsList();
|
!this.props.user.isGuest && this.loadApplicationsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { user, apps, resetApp, deleteApp } = this.props;
|
const { user, apps, resetApp, deleteApp, location } = this.props;
|
||||||
const { isLoading } = this.state;
|
const { isLoading } = this.state;
|
||||||
|
const clientId = location.hash.substr(1) || null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ApplicationsIndex
|
<ApplicationsIndex
|
||||||
@ -37,6 +37,7 @@ class ApplicationsListPage extends Component<{
|
|||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
deleteApp={deleteApp}
|
deleteApp={deleteApp}
|
||||||
resetApp={resetApp}
|
resetApp={resetApp}
|
||||||
|
clientId={clientId}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -48,9 +49,6 @@ class ApplicationsListPage extends Component<{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { fetchAvailableApps, resetApp, deleteApp } from 'components/dev/apps/actions';
|
|
||||||
|
|
||||||
export default connect((state) => ({
|
export default connect((state) => ({
|
||||||
user: state.user,
|
user: state.user,
|
||||||
apps: state.apps.available,
|
apps: state.apps.available,
|
||||||
|
Loading…
Reference in New Issue
Block a user