import * as React from 'react'; import { conditionallyTransition } from 'wdk-client/Actions/UserActions'; import PageController from 'wdk-client/Core/Controllers/PageController'; import { wrappable } from 'wdk-client/Utils/ComponentUtils'; import NotFound from 'wdk-client/Views/NotFound/NotFound'; import { RootState } from 'wdk-client/Core/State/Types'; import { connect } from 'react-redux'; type PageContent = { tabTitle: string, pageTitle: string, pageContent: React.ReactNode } const ActionCreators = { conditionallyTransition }; type StateProps = Pick; type DispatchProps = typeof ActionCreators; type OwnProps = { messageKey: string; requestUrl?: string; }; type MergeProps = { ownProps: OwnProps; dispatchProps: DispatchProps; stateProps: StateProps; }; class UserMessageController extends PageController { getContactUrl() { return 'mailto:help@veupathdb.org'; } getMessagePageContent() : PageContent { switch (this.props.ownProps.messageKey) { case 'password-reset-successful': return { tabTitle: "Password Reset", pageTitle: "Success!", pageContent: ( You will receive an email shortly containing a new, temporary password. ) }; case 'login-error': let prevPageUrl = this.props.ownProps.requestUrl; return { tabTitle: "Login Problem", pageTitle: "Unable to log in", pageContent: (

An error has occurred and you could not be logged into this site. If this problem persists, please contact us.

{prevPageUrl == null ? '' :

To return to your previous page, click here.

}
) }; default: return { tabTitle: "Page Not Found", pageTitle: "", pageContent: () }; } } loadData() { // if registered user is logged in, show profile instead of password reset message if (this.props.ownProps.messageKey == 'password-reset-successful') { this.props.dispatchProps.conditionallyTransition(user => !user.isGuest, '/user/profile'); } } isRenderDataLoaded(): boolean { return this.props.stateProps.config != null; } getActionCreators() { return ActionCreators; } getTitle() { return this.getMessagePageContent().tabTitle; } renderView() { let content = this.getMessagePageContent(); return (

{content.pageTitle}

{content.pageContent}
); } } const enhance = connect( (state: RootState) => ({ config: state.globalData.config }), ActionCreators, (stateProps, dispatchProps, ownProps) => ({ stateProps, dispatchProps, ownProps }) ); export default enhance(wrappable(UserMessageController));