From a3e1bd972c571099bfb8ece55bad5e82b95396ff Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 7 Feb 2017 17:44:27 -0300 Subject: [PATCH] Redirect if its initialized, funtionallity of finalStep --- client/coral-admin/src/actions/install.js | 21 +++++- client/coral-admin/src/constants/install.js | 4 ++ .../containers/Install/InstallContainer.js | 68 ++++++++++++++----- .../Install/components/Steps/FinalStep.js | 7 +- .../Install/components/Steps/InitialStep.js | 2 + .../Install/components/Steps/style.css | 11 +++ client/coral-admin/src/reducers/install.js | 6 +- client/coral-ui/components/WizardNav.js | 1 - 8 files changed, 96 insertions(+), 24 deletions(-) diff --git a/client/coral-admin/src/actions/install.js b/client/coral-admin/src/actions/install.js index c7c673105..dbeb52c8e 100644 --- a/client/coral-admin/src/actions/install.js +++ b/client/coral-admin/src/actions/install.js @@ -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}`)); + }); +}; diff --git a/client/coral-admin/src/constants/install.js b/client/coral-admin/src/constants/install.js index 06d047adc..b3fd7e0d0 100644 --- a/client/coral-admin/src/constants/install.js +++ b/client/coral-admin/src/constants/install.js @@ -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'; diff --git a/client/coral-admin/src/containers/Install/InstallContainer.js b/client/coral-admin/src/containers/Install/InstallContainer.js index 869901e3e..7a8634180 100644 --- a/client/coral-admin/src/containers/Install/InstallContainer.js +++ b/client/coral-admin/src/containers/Install/InstallContainer.js @@ -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 ( - -
-

Welcome to the Coral Project

- { install.step !== 0 ? : null } - - - - - - -
-
- ); + render() { + const {install} = this.props; + + return ( + +
+ { + !install.alreadyInstalled ? ( +
+

Welcome to the Coral Project

+ { install.step !== 0 ? : null } + + + + + + +
+ ) : ( +
Talk is already installed
+ ) + } +
+
+ ); + } +} + +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)), diff --git a/client/coral-admin/src/containers/Install/components/Steps/FinalStep.js b/client/coral-admin/src/containers/Install/components/Steps/FinalStep.js index 04cdafebd..e549ebe63 100644 --- a/client/coral-admin/src/containers/Install/components/Steps/FinalStep.js +++ b/client/coral-admin/src/containers/Install/components/Steps/FinalStep.js @@ -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 ( -
+

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.

- - + +
); }; diff --git a/client/coral-admin/src/containers/Install/components/Steps/InitialStep.js b/client/coral-admin/src/containers/Install/components/Steps/InitialStep.js index e450882b1..9f9770fe9 100644 --- a/client/coral-admin/src/containers/Install/components/Steps/InitialStep.js +++ b/client/coral-admin/src/containers/Install/components/Steps/InitialStep.js @@ -8,6 +8,8 @@ const InitialStep = props => {

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.

diff --git a/client/coral-admin/src/containers/Install/components/Steps/style.css b/client/coral-admin/src/containers/Install/components/Steps/style.css index 555ebcc4d..161c72685 100644 --- a/client/coral-admin/src/containers/Install/components/Steps/style.css +++ b/client/coral-admin/src/containers/Install/components/Steps/style.css @@ -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; diff --git a/client/coral-admin/src/reducers/install.js b/client/coral-admin/src/reducers/install.js index 8396beead..be421fe27 100644 --- a/client/coral-admin/src/reducers/install.js +++ b/client/coral-admin/src/reducers/install.js @@ -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; } diff --git a/client/coral-ui/components/WizardNav.js b/client/coral-ui/components/WizardNav.js index be3ce07e5..84f7d30ac 100644 --- a/client/coral-ui/components/WizardNav.js +++ b/client/coral-ui/components/WizardNav.js @@ -25,7 +25,6 @@ const WizardNav = props => { }; WizardNav.propTypes = { - goToStep: PropTypes.func.isRequired, currentStep: PropTypes.number.isRequired };