Javascript 在初始redux表单加载时显示服务器消息

Javascript 在初始redux表单加载时显示服务器消息,javascript,redux-form,Javascript,Redux Form,我需要有一个redux表单烤面包机消息显示在我的提交按钮第一次点击时,表单首次加载。第二次单击submit按钮时,将显示toaster消息。我知道我需要解决一个组件生命周期问题,但我似乎无法确定它 这是我的register.js文件: import React,{Component}来自'React'; 从'react redux'导入{connect}; 从“redux form”导入{Field,reduxForm}; 从“反应路由器”导入{Link}; 从“../../actions/au

我需要有一个redux表单烤面包机消息显示在我的提交按钮第一次点击时,表单首次加载。第二次单击submit按钮时,将显示toaster消息。我知道我需要解决一个组件生命周期问题,但我似乎无法确定它

这是我的register.js文件:

import React,{Component}来自'React';
从'react redux'导入{connect};
从“redux form”导入{Field,reduxForm};
从“反应路由器”导入{Link};
从“../../actions/auth”导入{registerUser};
导入通知,{notify}来自“react notify toast”;
从“../common/Input”导入输入;
const form=reduxForm({
表格:'登记',
字段:['firstName','lastName','email','password'],
验证
});
常量选择器=formValueSelector(“寄存器”);
函数验证(formProps){
常量错误={};
如果(!formProps.firstName){
errors.firstName='请输入名字';
}
如果(!formProps.lastName){
errors.lastName='请输入姓氏';
}
如果(!formProps.email){
errors.email='请输入电子邮件';
}否则,如果(!/^[A-Z0-9.%+-]+@[A-Z0-9.-]+\[A-Z]{2,4}$/i.test(formProps.email)){
errors.email='无效的电子邮件地址格式';
}
如果(!formProps.password){
errors.password='请输入密码';
}
返回错误;
}
类寄存器扩展组件{
handleFormSubmit(formProps){
this.props.registerUser(formProps);
}
renderServerAlert(){
如果(此.props.errorMessage){
返回(
{notify.show(this.props.errorMessage'error',5000)}
)
}
}
render(){
const{email,handleSubmit,submiting}=this.props;
返回(
登记
{this.renderServerAlert()}}className=“btn btn主块全宽m-b”>寄存器

已经有帐户了吗

登录

我公司业务应用程序启动程序©;2017

我的公司总是免费的。 版权所有MyCompany©;2016-2017 ); } } 函数MapStateTops(状态){ 返回{ errorMessage:state.auth.error, 消息:state.auth.message, 已验证:state.auth.authenticated }; } 导出默认连接(mapstatetops,{registerUser})(form(Register));
以下是我的auth.js操作文件:

从“axios”导入axios;
从“react router”导入{browserHistory};
从“反应cookie”导入cookie;
从“/index”导入{API_URL、客户端_ROOT_URL、errorHandler};
从“/types”导入{AUTH_USER,AUTH_ERROR,UNAUTH_USER,忘记密码请求,重置密码请求,受保护测试};
//================================
//身份验证操作
//================================
//待办事项:将过期添加到cookie
导出函数loginUser({电子邮件,密码}){
返回功能(调度){
post(${API\u URL}/auth/login`,{email,password})
。然后(响应=>{
save('token',response.data.token,{path:'/'});
save('user',response.data.user,{path:'/'});
分派({type:AUTH_USER});
window.location.href=CLIENT_ROOT_URL+'/dashboard';
})
.catch((错误)=>{
errorHandler(调度、错误.响应、验证错误)
});
}
}
导出函数注册表服务器({email,firstName,lastName,password}){
返回功能(调度){
post(${API_URL}/auth/register`,{email,firstName,lastName,password})
。然后(响应=>{
save('token',response.data.token,{path:'/'});
save('user',response.data.user,{path:'/'});
分派({type:AUTH_USER});
window.location.href=CLIENT_ROOT_URL+'/dashboard';
})
.catch((错误)=>{
errorHandler(调度、错误.响应、验证错误)
});
}
}
导出函数logoutUser(错误){
返回功能(调度){
分派({type:UNAUTH_USER});
remove('token',{path:'/'});
remove('user',{path:'/'});
window.location.href=CLIENT_ROOT_URL+'/login';
}
}
导出函数getForgotPasswordToken({email}){
返回功能(调度){
post(${API\u URL}/auth/forget password`,{email})
。然后(响应=>{
派遣({
类型:忘记密码请求,
有效载荷:response.data.message
});
})
.catch((错误)=>{
errorHandler(调度、错误.响应、验证错误)
});
}
}
导出函数resetPassword(令牌,{password}){
返回功能(调度){
post(`${API_URL}/auth/reset password/${token}`,{password})
。然后(响应=>{
派遣({
类型:重置密码请求,
有效载荷:response.data.message
});
//成功重置密码时重定向到登录页面
browserHistory.push('/login');
})
.catch((错误)=>{
errorHandler(调度、错误.响应、验证错误)
});
}
}
导出函数protectedTest(){
返回功能(调度){
get(`${API\u URL}/protected`{
标题:{“授权”:cookie.load('token')}
})
。然后(响应=>{
派遣({
类型:受保护的\u试验,
有效载荷:response.data.content
});
})
.catch((错误)=>{
errorHandler(调度、错误.响应、验证错误)
});
}
}
…最后是服务器端控制器:

“严格使用”;
const jwt=require('jsonwebtoken'),
crypto=require('crypto'),
User=require('../models/User'),
mailgun=require('../config/mailgun'),
mailchimp=require('../config/mailchimp'),
config=require('../config/main');
//产生