mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
Failure check
This commit is contained in:
@@ -24,28 +24,37 @@ const validation = (formData, dispatch, next) => {
|
|||||||
const empty = Object.keys(formData).filter(name => {
|
const empty = Object.keys(formData).filter(name => {
|
||||||
const cond = !formData[name].length;
|
const cond = !formData[name].length;
|
||||||
|
|
||||||
// Adding Error
|
if (cond) {
|
||||||
dispatch(addError(name, 'Please, fill this field '));
|
|
||||||
|
// Adding Error
|
||||||
|
dispatch(addError(name, 'Please, fill this field '));
|
||||||
|
} else {
|
||||||
|
dispatch(addError(name, ''));
|
||||||
|
}
|
||||||
|
|
||||||
return cond;
|
return cond;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (empty.length) {
|
if (empty.length) {
|
||||||
return dispatch(hasError('Please fill the form'));
|
return dispatch(hasError());
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegExp Validation
|
// RegExp Validation
|
||||||
const validation = Object.keys(formData).filter(name => {
|
const validation = Object.keys(formData).filter(name => {
|
||||||
const cond = !validate[name](formData[name]);
|
const cond = !validate[name](formData[name]);
|
||||||
if (cond) {
|
if (cond) {
|
||||||
|
|
||||||
// Adding Error
|
// Adding Error
|
||||||
dispatch(addError(name, errorMsj[name]));
|
dispatch(addError(name, errorMsj[name]));
|
||||||
|
} else {
|
||||||
|
dispatch(addError(name, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
return cond;
|
return cond;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (validation.length) {
|
if (validation.length) {
|
||||||
return dispatch(hasError('Please check the form'));
|
return dispatch(hasError());
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(clearErrors());
|
dispatch(clearErrors());
|
||||||
@@ -53,33 +62,29 @@ const validation = (formData, dispatch, next) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const submitSettings = () => (dispatch, getState) => {
|
export const submitSettings = () => (dispatch, getState) => {
|
||||||
const formData = getState().install.toJS().data.settings;
|
const settingsFormData = getState().install.toJS().data.settings;
|
||||||
validation(formData, dispatch, function() {
|
validation(settingsFormData, dispatch, function() {
|
||||||
dispatch(nextStep());
|
dispatch(nextStep());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const install = () => dispatch => {
|
export const submitUser = () => (dispatch, getState) => {
|
||||||
dispatch(installRequest());
|
const userFormData = getState().install.toJS().data.user;
|
||||||
coralApi('/setup')
|
validation(userFormData, dispatch, function() {
|
||||||
.then(result => {
|
const data = getState().install.toJS().data;
|
||||||
console.log(result);
|
dispatch(installRequest());
|
||||||
dispatch(installSuccess());
|
coralApi('/setup', {method: 'POST', body: data})
|
||||||
})
|
.then(result => {
|
||||||
.catch(error => {
|
console.log(result);
|
||||||
console.error(error);
|
dispatch(installSuccess());
|
||||||
dispatch(installFailure(`${error.message}`));
|
dispatch(nextStep());
|
||||||
});
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
dispatch(installFailure(`${error.message}`));
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateSettingsFormData = (name, value) => ({
|
export const updateSettingsFormData = (name, value) => ({type: actions.UPDATE_FORMDATA_SETTINGS, name, value});
|
||||||
type: actions.UPDATE_FORMDATA_SETTINGS,
|
export const updateUserFormData = (name, value) => ({type: actions.UPDATE_FORMDATA_USER, name, value});
|
||||||
name,
|
|
||||||
value
|
|
||||||
});
|
|
||||||
|
|
||||||
export const updateUserFormData = (name, value) => ({
|
|
||||||
type: actions.UPDATE_FORMDATA_USER,
|
|
||||||
name,
|
|
||||||
value
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
|
|||||||
import styles from './style.css';
|
import styles from './style.css';
|
||||||
import {Wizard, WizardNav} from 'coral-ui';
|
import {Wizard, WizardNav} from 'coral-ui';
|
||||||
import {Layout} from '../../components/ui/Layout';
|
import {Layout} from '../../components/ui/Layout';
|
||||||
import {nextStep, previousStep, goToStep, updateUserFormData, updateSettingsFormData, submitSettings} from '../../actions/install';
|
import {nextStep, previousStep, goToStep, updateUserFormData, updateSettingsFormData, submitSettings, submitUser} from '../../actions/install';
|
||||||
|
|
||||||
import InitialStep from './components/Steps/InitialStep';
|
import InitialStep from './components/Steps/InitialStep';
|
||||||
import AddOrganizationName from './components/Steps/AddOrganizationName';
|
import AddOrganizationName from './components/Steps/AddOrganizationName';
|
||||||
@@ -45,9 +45,13 @@ const mapDispatchToProps = dispatch => ({
|
|||||||
const {name, value} = e.currentTarget;
|
const {name, value} = e.currentTarget;
|
||||||
dispatch(updateUserFormData(name, value));
|
dispatch(updateUserFormData(name, value));
|
||||||
},
|
},
|
||||||
handleSubmit: e => {
|
handleSettingsSubmit: e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dispatch(submitSettings());
|
dispatch(submitSettings());
|
||||||
|
},
|
||||||
|
handleUserSubmit: e => {
|
||||||
|
e.preventDefault();
|
||||||
|
dispatch(submitUser());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import styles from './style.css';
|
|||||||
import {FormField, Button} from 'coral-ui';
|
import {FormField, Button} from 'coral-ui';
|
||||||
|
|
||||||
const AddOrganizationName = props => {
|
const AddOrganizationName = props => {
|
||||||
const {handleSettingsChange, handleSubmit, install} = props;
|
const {handleSettingsChange, handleSettingsSubmit, install} = props;
|
||||||
return (
|
return (
|
||||||
<div className={styles.step}>
|
<div className={styles.step}>
|
||||||
<p>
|
<p>
|
||||||
@@ -11,7 +11,7 @@ const AddOrganizationName = props => {
|
|||||||
inviting new team members
|
inviting new team members
|
||||||
</p>
|
</p>
|
||||||
<div className={styles.form}>
|
<div className={styles.form}>
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSettingsSubmit}>
|
||||||
<FormField
|
<FormField
|
||||||
className={styles.FormField}
|
className={styles.FormField}
|
||||||
id="organizationName"
|
id="organizationName"
|
||||||
|
|||||||
@@ -1,28 +1,33 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styles from './style.css';
|
import styles from './style.css';
|
||||||
import {FormField, Button} from 'coral-ui';
|
import {FormField, Button, Spinner} from 'coral-ui';
|
||||||
|
|
||||||
const InitialStep = props => {
|
const InitialStep = props => {
|
||||||
const {handleSubmit, handleUserChange} = props;
|
const {handleUserChange, handleUserSubmit, install} = props;
|
||||||
return (
|
return (
|
||||||
<div className={styles.step}>
|
<div className={styles.step}>
|
||||||
<div className={styles.form}>
|
<div className={styles.form}>
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleUserSubmit}>
|
||||||
<FormField
|
<FormField
|
||||||
className={styles.formField}
|
className={styles.formField}
|
||||||
id="email"
|
id="email"
|
||||||
type="email"
|
type="email"
|
||||||
label='Email address' required
|
label='Email address'
|
||||||
onChange={handleUserChange}
|
onChange={handleUserChange}
|
||||||
|
showErrors={install.showErrors}
|
||||||
|
errorMsg={install.errors.email}
|
||||||
|
noValidate
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
className={styles.formField}
|
className={styles.formField}
|
||||||
id="username"
|
id="displayName"
|
||||||
type="text"
|
type="text"
|
||||||
label='Username'
|
label='Username'
|
||||||
onChange={handleUserChange}
|
onChange={handleUserChange}
|
||||||
/>
|
showErrors={install.showErrors}
|
||||||
|
errorMsg={install.errors.displayName}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
className={styles.formField}
|
className={styles.formField}
|
||||||
@@ -30,7 +35,9 @@ const InitialStep = props => {
|
|||||||
type="password"
|
type="password"
|
||||||
label='Password'
|
label='Password'
|
||||||
onChange={handleUserChange}
|
onChange={handleUserChange}
|
||||||
/>
|
showErrors={install.showErrors}
|
||||||
|
errorMsg={install.errors.password}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
className={styles.formField}
|
className={styles.formField}
|
||||||
@@ -38,9 +45,17 @@ const InitialStep = props => {
|
|||||||
type="password"
|
type="password"
|
||||||
label='Confirm Password'
|
label='Confirm Password'
|
||||||
onChange={handleUserChange}
|
onChange={handleUserChange}
|
||||||
/>
|
showErrors={install.showErrors}
|
||||||
|
errorMsg={install.errors.confirmPassword}
|
||||||
|
/>
|
||||||
|
|
||||||
<Button cStyle='black' type="submit" full>Save</Button>
|
{
|
||||||
|
!props.install.isLoading ?
|
||||||
|
<Button cStyle='black' type="submit" full>Save</Button>
|
||||||
|
:
|
||||||
|
<Spinner />
|
||||||
|
}
|
||||||
|
{props.install.installRequest === 'FAILURE' && <div className={styles.error}>Error: {props.install.installRequestError}</div>}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ import React from 'react';
|
|||||||
import styles from './style.css';
|
import styles from './style.css';
|
||||||
import {Button} from 'coral-ui';
|
import {Button} from 'coral-ui';
|
||||||
|
|
||||||
const InitialStep = props => {
|
const InitialStep = () => {
|
||||||
const {nextStep} = props;
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.step}>
|
<div className={styles.step}>
|
||||||
<p>
|
<p>
|
||||||
Thanks for installing Talk! We sent an email to your team member.
|
Thanks for installing Talk! We sent an email to your team member.
|
||||||
While they finish setting up their account, start engaging with your readers now.
|
While they finish setting up their account, start engaging with your readers now.
|
||||||
</p>
|
</p>
|
||||||
<Button onClick={nextStep}>Launch Talk</Button>
|
<Button>Launch Talk</Button>
|
||||||
<Button cStyle='black' onClick={nextStep}>Close this Installer</Button>
|
<Button cStyle='black'>Close this Installer</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,3 +56,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
background: #FFEBEE;
|
||||||
|
color: #B71C1C;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,16 +3,24 @@ import {Map} from 'immutable';
|
|||||||
import * as actions from '../constants/install';
|
import * as actions from '../constants/install';
|
||||||
|
|
||||||
const initialState = Map({
|
const initialState = Map({
|
||||||
|
isLoading: false,
|
||||||
data: Map({
|
data: Map({
|
||||||
settings: Map({
|
settings: Map({
|
||||||
organizationName: ''
|
organizationName: ''
|
||||||
}),
|
}),
|
||||||
user: Map({
|
user: Map({
|
||||||
displayName: ''
|
displayName: '',
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
confirmPassword: ''
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
errors: Map({
|
errors: Map({
|
||||||
organizationName: ''
|
organizationName: '',
|
||||||
|
displayName: '',
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
confirmPassword: ''
|
||||||
}),
|
}),
|
||||||
showErrors: false,
|
showErrors: false,
|
||||||
hasError: false,
|
hasError: false,
|
||||||
@@ -25,7 +33,9 @@ const initialState = Map({
|
|||||||
{
|
{
|
||||||
text: '2. Create your account',
|
text: '2. Create your account',
|
||||||
step: 2
|
step: 2
|
||||||
}]
|
}],
|
||||||
|
installRequest: null,
|
||||||
|
installRequestError: null
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function install (state = initialState, action) {
|
export default function install (state = initialState, action) {
|
||||||
@@ -57,6 +67,20 @@ export default function install (state = initialState, action) {
|
|||||||
case actions.CLEAR_ERRORS:
|
case actions.CLEAR_ERRORS:
|
||||||
return state
|
return state
|
||||||
.set('errors', Map());
|
.set('errors', Map());
|
||||||
|
case actions.INSTALL_REQUEST:
|
||||||
|
return state
|
||||||
|
.set('isLoading', true);
|
||||||
|
case actions.INSTALL_SUCCESS:
|
||||||
|
return state
|
||||||
|
.set('isLoading', false)
|
||||||
|
.set('installRequest', 'SUCCESS');
|
||||||
|
case actions.INSTALL_FAILURE:
|
||||||
|
return state
|
||||||
|
.merge({
|
||||||
|
isLoading: false,
|
||||||
|
installRequest: 'FAILURE',
|
||||||
|
installRequestError: action.error
|
||||||
|
});
|
||||||
default :
|
default :
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ router.use('/actions', authorization.needed(), require('./actions'));
|
|||||||
router.use('/auth', require('./auth'));
|
router.use('/auth', require('./auth'));
|
||||||
router.use('/users', require('./users'));
|
router.use('/users', require('./users'));
|
||||||
router.use('/account', require('./account'));
|
router.use('/account', require('./account'));
|
||||||
|
router.use('/setup', require('./setup'));
|
||||||
|
|
||||||
// Bind the kue handler to the /kue path.
|
// Bind the kue handler to the /kue path.
|
||||||
router.use('/kue', authorization.needed('ADMIN'), require('../../services/kue').kue.app);
|
router.use('/kue', authorization.needed('ADMIN'), require('../../services/kue').kue.app);
|
||||||
|
|||||||
Reference in New Issue
Block a user