Ghost/ghost/members-auth-pages/components/Modal.js
Fabien O'Carroll b1a1f61d5d Refactored auth pages for future flows (#10458)
no-issue

* Used camelCase for gateway method calls
* Added some components for building blocks of forms
* Added input specific components
* Added Form component
    This handles collecting the data to submit and sharing state between forms
* Added Pages component to handle urls
* Added the pages for the popup
* Added MembersProvider component
    This is designed to give its children access to gateway methods
* Added Modal component
    This wraps the pages and handles dispatching form submissions to the members gateway
* Refactored index.js to use new components/pages
* Fixed default page from Signup -> Signin
2019-05-07 17:15:50 +02:00

69 lines
2.5 KiB
JavaScript

import { Component } from 'preact';
import Pages from './Pages';
import SigninPage from '../pages/SigninPage';
import SignupPage from '../pages/SignupPage';
import RequestPasswordResetPage from '../pages/RequestPasswordResetPage';
import PasswordResetSentPage from '../pages/PasswordResetSentPage';
import ResetPasswordPage from '../pages/ResetPasswordPage';
export default class Modal extends Component {
constructor(props, context) {
super();
this.state = {
error: null,
containerClass: 'gm-page-overlay'
}
}
handleAction(promise) {
promise.then((success) => {
this.close(success);
}, (error) => {
this.setState({error});
});
}
render(props, state) {
const { queryToken } = props;
const { containerClass, error } = state;
const { members } = this.context;
const closeModal = () => this.close();
const clearError = () => this.setState({error: null});
const signin = (data) => this.handleAction(members.signin(data));
const signup = (data) => this.handleAction(members.signup(data));
const requestReset = (data) => this.handleAction(members.requestPasswordReset(data));
const resetPassword = (data) => this.handleAction(members.resetPassword(data));
return (
<Pages className={containerClass} onChange={clearError} onClick={closeModal}>
<SigninPage error={error} hash="" handleSubmit={signup} handleClose={closeModal}/>
<SigninPage error={error} hash="signin" handleSubmit={signin} handleClose={closeModal}/>
<SignupPage error={error} hash="signup" handleSubmit={signup} handleClose={closeModal}/>
<RequestPasswordResetPage error={error} hash="request-password-reset" handleSubmit={requestReset} handleClose={closeModal}/>
<PasswordResetSentPage error={error} hash="password-reset-sent" handleSubmit={requestReset} handleClose={closeModal}/>
<ResetPasswordPage error={error} hash="reset-password" handleSubmit={resetPassword} handleClose={closeModal}/>
</Pages>
);
}
close(success) {
this.setState({
containerClass: 'gm-page-overlay close'
});
window.setTimeout(() => {
this.setState({
containerClass: 'gm-page-overlay'
});
window.parent.postMessage({
msg: 'pls-close-auth-popup',
success
}, '*');
}, 700);
}
}