Redirect if its initialized, funtionallity of finalStep

This commit is contained in:
Belen Curcio
2017-02-07 17:44:27 -03:00
parent 5cdfc7bd1b
commit a3e1bd972c
8 changed files with 96 additions and 24 deletions
+20 -1
View File
@@ -27,7 +27,7 @@ const validation = (formData, dispatch, next) => {
if (cond) {
// Adding Error
dispatch(addError(name, 'Please, fill this field '));
dispatch(addError(name, 'This field is required.'));
} else {
dispatch(addError(name, ''));
}
@@ -88,3 +88,22 @@ export const submitUser = () => (dispatch, getState) => {
export const updateSettingsFormData = (name, value) => ({type: actions.UPDATE_FORMDATA_SETTINGS, name, value});
export const updateUserFormData = (name, value) => ({type: actions.UPDATE_FORMDATA_USER, name, value});
const checkInstallRequest = () => ({type: actions.CHECK_INSTALL_REQUEST});
const checkInstallSuccess = installed => ({type: actions.CHECK_INSTALL_SUCCESS, installed});
const checkInstallFailure = error => ({type: actions.CHECK_INSTALL_FAILURE, error});
export const checkInstall = next => dispatch => {
dispatch(checkInstallRequest());
coralApi('/setup/available')
.then(({available}) => {
dispatch(checkInstallSuccess(available));
if (!available) {
next();
}
})
.catch(error => {
console.error(error);
dispatch(checkInstallFailure(`${error.message}`));
});
};
@@ -10,3 +10,7 @@ export const INSTALL_SUCCESS = 'INSTALL_SUCCESS';
export const INSTALL_FAILURE = 'INSTALL_FAILURE';
export const UPDATE_FORMDATA_USER = 'UPDATE_FORMDATA_USER';
export const UPDATE_FORMDATA_SETTINGS = 'UPDATE_FORMDATA_SETTINGS';
export const CHECK_INSTALL_REQUEST = 'CHECK_INSTALL_REQUEST';
export const CHECK_INSTALL_SUCCESS = 'CHECK_INSTALL_SUCCESS';
export const CHECK_INSTALL_FAILURE = 'CHECK_INSTALL_FAILURE';
@@ -1,32 +1,63 @@
import React from 'react';
import React, {Component} from 'react';
import {connect} from 'react-redux';
import styles from './style.css';
import {Wizard, WizardNav} from 'coral-ui';
import {Layout} from '../../components/ui/Layout';
import {nextStep, previousStep, goToStep, updateUserFormData, updateSettingsFormData, submitSettings, submitUser} from '../../actions/install';
import {
nextStep,
previousStep,
goToStep,
updateUserFormData,
updateSettingsFormData,
submitSettings,
submitUser,
checkInstall
} from '../../actions/install';
import InitialStep from './components/Steps/InitialStep';
import AddOrganizationName from './components/Steps/AddOrganizationName';
import CreateYourAccount from './components/Steps/CreateYourAccount';
import FinalStep from './components/Steps/FinalStep';
const InstallContainer = props => {
const {install} = props;
class InstallContainer extends Component {
componentDidMount() {
const {checkInstall} = this.props;
checkInstall(() => {
this.context.router.push('/admin');
});
}
return (
<Layout restricted={true}>
<div className={styles.Install}>
<h2>Welcome to the Coral Project</h2>
{ install.step !== 0 ? <WizardNav items={install.navItems} currentStep={install.step} icon='check'/> : null }
<Wizard currentStep={install.step} {...props}>
<InitialStep/>
<AddOrganizationName/>
<CreateYourAccount/>
<FinalStep/>
</Wizard>
</div>
</Layout>
);
render() {
const {install} = this.props;
return (
<Layout restricted={true}>
<div className={styles.Install}>
{
!install.alreadyInstalled ? (
<div>
<h2>Welcome to the Coral Project</h2>
{ install.step !== 0 ? <WizardNav items={install.navItems} currentStep={install.step} icon='check'/> : null }
<Wizard currentStep={install.step} {...this.props}>
<InitialStep/>
<AddOrganizationName/>
<CreateYourAccount/>
<FinalStep/>
</Wizard>
</div>
) : (
<div>Talk is already installed</div>
)
}
</div>
</Layout>
);
}
}
InstallContainer.contextTypes = {
router: React.PropTypes.object
};
const mapStateToProps = state => ({
@@ -34,6 +65,7 @@ const mapStateToProps = state => ({
});
const mapDispatchToProps = dispatch => ({
checkInstall: next => dispatch(checkInstall(next)),
nextStep: () => dispatch(nextStep()),
previousStep: () => dispatch(previousStep()),
goToStep: step => dispatch(goToStep(step)),
@@ -1,17 +1,18 @@
import React from 'react';
import styles from './style.css';
import {Button} from 'coral-ui';
import {Link} from 'react-router';
const InitialStep = () => {
return (
<div className={styles.step}>
<div className={`${styles.step} ${styles.finalStep}`}>
<p>
Thanks for installing Talk! We sent an email to verify your email
address. While you finish setting the account, you can start engaging
with your readers now.
</p>
<Button>Launch Talk</Button>
<Button cStyle='black'>Close this Installer</Button>
<Button raised><Link to='/admin'>Launch Talk</Link></Button>
<Button cStyle='black' raised><a href="http://coralproject.net">Close this Installer</a></Button>
</div>
);
};
@@ -8,6 +8,8 @@ const InitialStep = props => {
<div className={styles.step}>
<p>
The remainder of the Talk installation will take about ten minutes.
Once you complete the following two steps, you will have a free
installation and provision of Mongo and Redis.
</p>
<Button cStyle='green' onClick={nextStep} raised>Get Started</Button>
</div>
@@ -18,6 +18,10 @@
> button {
min-width: 145px;
a {
text-decoration: none;
color: inherit;
}
}
.form {
@@ -57,6 +61,13 @@
}
}
.finalStep {
button {
width: 225px;
margin-right: 10px;
}
}
.error {
background: #FFEBEE;
color: #B71C1C;
+5 -1
View File
@@ -35,7 +35,8 @@ const initialState = Map({
step: 2
}],
installRequest: null,
installRequestError: null
installRequestError: null,
alreadyInstalled: false
});
export default function install (state = initialState, action) {
@@ -81,6 +82,9 @@ export default function install (state = initialState, action) {
installRequest: 'FAILURE',
installRequestError: action.error
});
case actions.CHECK_INSTALL_SUCCESS:
return state
.set('alreadyInstalled', !action.available);
default :
return state;
}
-1
View File
@@ -25,7 +25,6 @@ const WizardNav = props => {
};
WizardNav.propTypes = {
goToStep: PropTypes.func.isRequired,
currentStep: PropTypes.number.isRequired
};