update user success
This commit is contained in:
@@ -4,17 +4,17 @@ import {
|
||||
POST_AD_ANSWER_SUCCESS
|
||||
} from "../types";
|
||||
|
||||
export const postAdAnswer = data => ({
|
||||
export const postAdAnswerRequest = data => ({
|
||||
type: POST_AD_ANSWER_REQUEST,
|
||||
data
|
||||
});
|
||||
|
||||
export const postAdAnswerFailure = errors => ({
|
||||
export const postAdAnswerRequestFailure = errors => ({
|
||||
type: POST_AD_ANSWER_FAILURE,
|
||||
errors
|
||||
});
|
||||
|
||||
export const postAdAnswerSuccess = res => ({
|
||||
export const postAdAnswerRequestSuccess = res => ({
|
||||
type: POST_AD_ANSWER_SUCCESS,
|
||||
res
|
||||
});
|
||||
|
||||
@@ -14,6 +14,9 @@ import {
|
||||
SEND_CONFIRMATION_EMAIL_REQUEST,
|
||||
SEND_CONFIRMATION_EMAIL_SUCCESS,
|
||||
SEND_CONFIRMATION_EMAIL_FAILURE,
|
||||
UPDATE_USER_REQUEST,
|
||||
UPDATE_USER_SUCCESS,
|
||||
UPDATE_USER_FAILURE,
|
||||
} from '../types'
|
||||
|
||||
export const fetchCurrentUserRequest = () => ({
|
||||
@@ -86,3 +89,18 @@ export const requestConfirmationAccountFailure = (err) => ({
|
||||
type: ACCOUNT_CONFIRMATION_FAILURE,
|
||||
err
|
||||
});
|
||||
|
||||
|
||||
export const updateUserRequest = (payload) => ({
|
||||
type: UPDATE_USER_REQUEST,
|
||||
payload
|
||||
});
|
||||
|
||||
export const updateUserRequestSuccess = () => ({
|
||||
type: UPDATE_USER_SUCCESS,
|
||||
});
|
||||
|
||||
export const updateUserRequestFailure = (err) => ({
|
||||
type: UPDATE_USER_FAILURE,
|
||||
err
|
||||
});
|
||||
|
||||
@@ -3,7 +3,9 @@ import { withStyles } from '@material-ui/core/styles';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import TextField from '@material-ui/core/TextField';
|
||||
import { connect } from 'react-redux'
|
||||
import { postAdAnswer, updateUser} from '../../actions/answer'
|
||||
import { postAdAnswerRequest } from '../../actions/answer'
|
||||
import { updateUserRequest } from '../../actions/user'
|
||||
|
||||
|
||||
const styles = theme => ({
|
||||
container: {
|
||||
@@ -72,33 +74,44 @@ const styles = theme => ({
|
||||
class Answer extends Component {
|
||||
|
||||
State = {
|
||||
data: {}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
console.log("componentWillReceiveProps")
|
||||
console.log(nextProps)
|
||||
|
||||
this.setState({ data: { firstname: nextProps.user.firstname, lastname: nextProps.user.lastname } })
|
||||
}
|
||||
|
||||
handleChange = (e) => {
|
||||
this.setState({ data: { ...this.state.data, [e.target.name]: e.target.value } })
|
||||
this.setState({ [e.target.name]: e.target.value })
|
||||
}
|
||||
|
||||
onSubmit = data => {
|
||||
onSubmit = (e) => {
|
||||
e.preventDefault()
|
||||
console.log("submit answer")
|
||||
|
||||
this.props.updateUser(this.state.data)
|
||||
//this.props.postAdAnswer(data)
|
||||
const data = new FormData()
|
||||
|
||||
data.append('file', this.state.file)
|
||||
data.append('firstname', this.state.firstname)
|
||||
data.append('lastname', this.state.lastname)
|
||||
|
||||
this.props.updateUserRequest(data)
|
||||
//this.props.postAdAnswerRequest(data)
|
||||
}
|
||||
|
||||
inputFilesystemChange = (e) => {
|
||||
var file = e.target.files[0]
|
||||
const data = new FormData()
|
||||
data.append('file', file)
|
||||
this.setState({ data: data })
|
||||
this.setState({ file: file })
|
||||
//TODO : updateProfile pict
|
||||
}
|
||||
render() {
|
||||
const { classes, user } = this.props
|
||||
return (
|
||||
<Fragment>
|
||||
<form className={classes.container} noValidate
|
||||
autoComplete="off" onSubmit={this.onSubmit}>
|
||||
<form className={classes.container}
|
||||
autoComplete="off">
|
||||
|
||||
<div className={classes.importContainer}>
|
||||
<input
|
||||
@@ -177,10 +190,9 @@ class Answer extends Component {
|
||||
classes={{ root: classes.rootTextfield }}
|
||||
variant="outlined"
|
||||
/>
|
||||
|
||||
</form>
|
||||
<div id="F" className={classes.foot}>
|
||||
<Button type="submit" variant="contained" className={classes.button}>Postuler</Button>
|
||||
<Button variant="contained" className={classes.button} onClick={this.onSubmit}>Postuler</Button>
|
||||
</div>
|
||||
</Fragment>
|
||||
)
|
||||
@@ -197,4 +209,4 @@ function mapStateToProps(state, ownProps) {
|
||||
};
|
||||
}
|
||||
|
||||
export default withStyles(styles)(connect(mapStateToProps, { postAdAnswer, updateUser })(Answer))
|
||||
export default withStyles(styles)(connect(mapStateToProps, { postAdAnswerRequest, updateUserRequest })(Answer))
|
||||
@@ -7,7 +7,7 @@ import Step from '@material-ui/core/Step';
|
||||
import StepLabel from '@material-ui/core/StepLabel';
|
||||
import { fetchAdRequest } from '../actions/ads'
|
||||
import { uploadMedia } from '../actions/media'
|
||||
import { postAdAnswer } from '../actions/answer'
|
||||
import { postAdAnswerRequest } from '../actions/answer'
|
||||
|
||||
import Recorder from '../components/organisms/Recorder'
|
||||
import Answer from '../components/organisms/Answer'
|
||||
|
||||
+7
-5
@@ -3,10 +3,10 @@
|
||||
import { all, call, delay, put, take, takeLatest } from 'redux-saga/effects'
|
||||
import es6promise from 'es6-promise'
|
||||
|
||||
import { requestConfirmationAccountSaga, sendConfirmationEmailSaga, requestLoginSaga, requestUserSaga, requestRegisterSaga, requestLogoutSaga, requestNewsletterSubscribitionSaga } from './sagas/userSaga.js'
|
||||
import { requestUpdateUserSaga, requestConfirmationAccountSaga, sendConfirmationEmailSaga, requestLoginSaga, requestUserSaga, requestRegisterSaga, requestLogoutSaga, requestNewsletterSubscribitionSaga } from './sagas/userSaga.js'
|
||||
import { requestAdsSaga, requestAdSaga, requestEmphasisAdsSaga } from './sagas/offreSaga.js'
|
||||
import { requestCompaniesSaga, requestCompanySaga,requestEmphasisCompaniesSaga } from './sagas/companySaga.js'
|
||||
import { postAdAnswerSaga, uploadMediaSaga } from './sagas/answerSaga.js'
|
||||
import { requestCompaniesSaga, requestCompanySaga, requestEmphasisCompaniesSaga } from './sagas/companySaga.js'
|
||||
import { postAdAnswerRequestSaga, uploadMediaSaga } from './sagas/answerSaga.js'
|
||||
|
||||
import {
|
||||
REQUEST_LOGIN,
|
||||
@@ -23,7 +23,8 @@ import {
|
||||
SEND_CONFIRMATION_EMAIL_REQUEST,
|
||||
ACCOUNT_CONFIRMATION_REQUEST,
|
||||
POST_AD_ANSWER_REQUEST,
|
||||
UPLOAD_MEDIA_REQUEST
|
||||
UPLOAD_MEDIA_REQUEST,
|
||||
UPDATE_USER_REQUEST
|
||||
} from "./types";
|
||||
|
||||
|
||||
@@ -36,6 +37,7 @@ function* rootSaga() {
|
||||
takeLatest(REQUEST_LOGOUT, requestLogoutSaga),
|
||||
takeLatest(REQUEST_REGISTER, requestRegisterSaga),
|
||||
takeLatest(FETCH_CURRENT_USER_REQUEST, requestUserSaga),
|
||||
takeLatest(UPDATE_USER_REQUEST, requestUpdateUserSaga),
|
||||
takeLatest(SUBSCRIBE_NEWSLETTER_REQUEST, requestNewsletterSubscribitionSaga),
|
||||
takeLatest(FETCH_ADS_REQUEST, requestAdsSaga),
|
||||
takeLatest(FETCH_AD_REQUEST, requestAdSaga),
|
||||
@@ -45,7 +47,7 @@ function* rootSaga() {
|
||||
takeLatest(FETCH_COMPANY_REQUEST, requestCompanySaga),
|
||||
takeLatest(SEND_CONFIRMATION_EMAIL_REQUEST, sendConfirmationEmailSaga),
|
||||
takeLatest(ACCOUNT_CONFIRMATION_REQUEST, requestConfirmationAccountSaga),
|
||||
takeLatest(POST_AD_ANSWER_REQUEST, postAdAnswerSaga),
|
||||
takeLatest(POST_AD_ANSWER_REQUEST, postAdAnswerRequestSaga),
|
||||
takeLatest(UPLOAD_MEDIA_REQUEST, uploadMediaSaga),
|
||||
|
||||
])
|
||||
|
||||
@@ -2,8 +2,8 @@ import { call, put } from "redux-saga/effects";
|
||||
import api from "../data/api";
|
||||
|
||||
import {
|
||||
postAdAnswerSuccess,
|
||||
postAdAnswerFailure
|
||||
postAdAnswerRequestSuccess,
|
||||
postAdAnswerRequestFailure
|
||||
} from "../actions/answer";
|
||||
|
||||
import {
|
||||
@@ -11,18 +11,18 @@ import {
|
||||
uploadMediaFailure
|
||||
} from "../actions/media";
|
||||
|
||||
export function* postAdAnswerSaga(action) {
|
||||
export function* postAdAnswerRequestSaga(action) {
|
||||
try {
|
||||
|
||||
const res = yield call(api.answers.postAnswer, action.payload);
|
||||
|
||||
if (!!res.data)
|
||||
yield put(postAdAnswerSuccess(res));
|
||||
yield put(postAdAnswerRequestSuccess(res));
|
||||
else
|
||||
yield put(postAdAnswerFailure(res));
|
||||
yield put(postAdAnswerRequestFailure(res));
|
||||
|
||||
} catch (err) {
|
||||
yield put(postAdAnswerFailure(err.response));
|
||||
yield put(postAdAnswerRequestFailure(err.response));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
registerUserSuccess, registerUserFailure,
|
||||
sendConfirmationEmailRequest, sendConfirmationEmailFailure,
|
||||
requestConfirmationAccountSuccess, requestConfirmationAccountFailure,
|
||||
updateUserRequestSuccess, updateUserRequestFailure
|
||||
} from "../actions/user";
|
||||
import setAuthorizationHeader from "../data/setAuthorizationHeader";
|
||||
|
||||
@@ -18,11 +19,11 @@ import _ from "lodash";
|
||||
export function* requestLoginSaga(action) {
|
||||
try {
|
||||
const res = yield call(api.user.login, action.data);
|
||||
|
||||
|
||||
if (!!res.token) {
|
||||
|
||||
localStorage.setItem('ttJWT', res.token)
|
||||
|
||||
|
||||
setAuthorizationHeader(res.token)
|
||||
|
||||
yield put(userLoggedIn());
|
||||
@@ -37,7 +38,7 @@ export function* requestLoginSaga(action) {
|
||||
console.log(error)
|
||||
localStorage.removeItem("ttJWT");
|
||||
setAuthorizationHeader();
|
||||
yield put(requestLoginFailure({message: "Mauvais identifiants."}));
|
||||
yield put(requestLoginFailure({ message: "Mauvais identifiants." }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,12 +90,12 @@ export function* requestNewsletterSubscribitionSaga(action) {
|
||||
yield put(subscribeToNewsletterSuccess(res));
|
||||
} else
|
||||
console.log(res.data.message);
|
||||
if (_.startsWith(res.data.message, 'Unsuccessful: 400 MJ18')) {
|
||||
throw new Error("Existe déjà.")
|
||||
}
|
||||
if (_.startsWith(res.data.message, 'Unsuccessful: 400 MJ18')) {
|
||||
throw new Error("Existe déjà.")
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err.message)
|
||||
yield put(subscribeToNewsletterFailure({err:err, message:err.message}));
|
||||
yield put(subscribeToNewsletterFailure({ err: err, message: err.message }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,3 +157,24 @@ export function* requestConfirmationAccountSaga(action) {
|
||||
yield put(requestConfirmationAccountFailure(err));
|
||||
}
|
||||
}
|
||||
|
||||
export function* requestUpdateUserSaga(action) {
|
||||
try {
|
||||
console.log('function* requestUpdateUserSaga')
|
||||
console.log(action.payload)
|
||||
const res = yield call(api.user.updateUser, action.payload);
|
||||
console.log(res);
|
||||
if (res.data.status === 'success') {
|
||||
|
||||
yield put(updateUserRequestSuccess(res));
|
||||
|
||||
} else
|
||||
throw new Error(res.message)
|
||||
|
||||
} catch (err) {
|
||||
console.log('function* requestUpdateUserSaga')
|
||||
console.log(err)
|
||||
yield put(updateUserRequestFailure(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@ export const SUBSCRIBE_NEWSLETTER_REQUEST = "SUBSCRIBE_NEWSLETTER_REQUEST"
|
||||
export const SUBSCRIBE_NEWSLETTER_SUCCESS = "SUBSCRIBE_NEWSLETTER_SUCCESS"
|
||||
export const SUBSCRIBE_NEWSLETTER_FAILURE = "SUBSCRIBE_NEWSLETTER_FAILURE"
|
||||
|
||||
|
||||
export const UPDATE_USER_REQUEST = "UPDATE_USER_REQUEST"
|
||||
export const UPDATE_USER_SUCCESS = "UPDATE_USER_SUCCESS"
|
||||
export const UPDATE_USER_FAILURE = "UPDATE_USER_FAILURE"
|
||||
|
||||
//ANSWER
|
||||
export const POST_AD_ANSWER_REQUEST = "POST_AD_ANSWER_REQUEST";
|
||||
export const POST_AD_ANSWER_SUCCESS = "POST_AD_ANSWER_SUCCESS";
|
||||
|
||||
Reference in New Issue
Block a user