user profile edit actions

This commit is contained in:
GotPPay
2018-09-11 09:26:00 +02:00
committed by Bilal Catic
parent b974eab225
commit a79ef1044c
4 changed files with 214 additions and 56 deletions

View File

@@ -9,9 +9,9 @@ import {
REQUEST_SAVE_BILLING_ADDRESS,
profileTexts
} from '../../constants/profileSettingsConstants';
import {fetchProfileInfo} from './profileSettingsActions';
import {updateMessages} from '../notification/notificationActions';
import {setDialogOpenFlag} from '../dialog/dialogActions';
import {recieveProfileInfo} from './profileSettingsActions';
const client = new HtmlClient();
@@ -23,18 +23,26 @@ export const saveProfileAddress = (idUser, profileAddress) => {
return dispatch => {
dispatch(requestSaveAddress());
return client.fetch({
url: `${API_SERVER}/profileSettings/api/saveProfileAddress`,
method: 'post',
data: {profileAddress: JSON.stringify(profileAddress)}
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
method: 'put',
data: {deliveryAddress: JSON.stringify(profileAddress)}
})
.then(response => {
if(response.data && response.data.messages){
dispatch(updateMessages(response.data.messages, profileTexts.messages));
if(response.data.messages[0].code === 'success'){
dispatch(fetchProfileInfo(idUser));
dispatch(setDialogOpenFlag(false));
}
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
dispatch(setDialogOpenFlag(false));
messages.push({
code:'success',
message:'PROFILE_ADDRESS_UPDATED'
});
}else{
messages.push({
code:'error',
message:'INTERNAL_SERVER_ERROR'
});
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);
@@ -50,15 +58,25 @@ export const removeProfileAddress = (idUser, idProfileAddress) => {
return dispatch => {
dispatch(requestRemoveAddress());
return client.fetch({
url: `${API_SERVER}/profileSettings/api/removeProfileAddress`,
method: 'post',
data: {idProfileAddress}
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
method: 'put',
data: {removeDeliveryAddress:idProfileAddress}
})
.then(response => {
if(response.data && response.data.messages){
dispatch(updateMessages(response.data.messages, profileTexts.messages));
dispatch(fetchProfileInfo(idUser));
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
messages.push({
code:'success',
message:'ADDRESS_REMOVED'
});
}else{
messages.push({
code:'error',
message:'INTERNAL_SERVER_ERROR'
});
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);
@@ -70,22 +88,30 @@ const requestSaveBillingAddress = () => ({
type: REQUEST_SAVE_BILLING_ADDRESS
});
export const saveBillingAddress = (idUser, idCompany, billingAddress) => {
export const saveBillingAddress = (idUser, billingAddress) => {
return dispatch => {
dispatch(requestSaveBillingAddress());
return client.fetch({
url: `${API_SERVER}/profileSettings/api/saveBillingAddress`,
method: 'post',
data: {idCompany, billingAddress: JSON.stringify(billingAddress)}
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
method: 'put',
data: {billingAddress: JSON.stringify(billingAddress)}
})
.then(response => {
if(response.data && response.data.messages){
dispatch(updateMessages(response.data.messages, profileTexts.messages));
if(response.data.messages[0].code === 'success'){
dispatch(fetchProfileInfo(idUser));
dispatch(setDialogOpenFlag(false));
}
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
dispatch(setDialogOpenFlag(false));
messages.push({
code:'success',
message:'BILLING_ADDRESS_UPDATED'
});
}else{
messages.push({
code:'error',
message:'INTERNAL_SERVER_ERROR'
});
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);
@@ -101,15 +127,25 @@ export const removeBillingAddress = (idUser, idBillingAddress) => {
return dispatch => {
dispatch(requestRemoveBillingAddress());
return client.fetch({
url: `${API_SERVER}/profileSettings/api/removeBillingAddress`,
method: 'post',
data: {idBillingAddress}
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
method: 'put',
data: {removeBillingAddress:idBillingAddress}
})
.then(response => {
if(response.data && response.data.messages){
dispatch(updateMessages(response.data.messages, profileTexts.messages));
dispatch(fetchProfileInfo(idUser));
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
messages.push({
code:'success',
message:'BILLING_ADDRESS_REMOVED'
});
}else{
messages.push({
code:'error',
message:'INTERNAL_SERVER_ERROR'
});
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);

View File

@@ -38,19 +38,6 @@ export const fetchProfileInfo = (idUser) => {
dispatch(recieveProfileInfo(response.data));
}
});
// return client.fetch({
// url: `${API_SERVER}/wp-json/wiaas/cart/customer-info`,
// method: 'get',
// data: {idUser}
// })
// .then(response => {
// if(response.data){
// dispatch(recieveProfileInfo(response.data));
// }
// })
// .catch(error => {
// client.onError(error, dispatch);
// });
}
};
@@ -72,10 +59,20 @@ export const saveProfileInfo = (idUser, profile) => {
}
})
.then(response => {
if(response.data && response.data.messages){
dispatch(updateMessages(response.data.messages, profileTexts.messages));
dispatch(fetchProfileInfo(idUser));
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
messages.push({
code:'success',
message:'PROFILE_UPDATED'
});
}else{
messages.push({
code:'error',
message:'INTERNAL_SERVER_ERROR'
});
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);
@@ -99,10 +96,20 @@ export const saveCompanyInfo = (idUser, companyInfo) => {
}
})
.then(response => {
if(response.data && response.data.messages){
dispatch(updateMessages(response.data.messages, profileTexts.messages));
dispatch(fetchProfileInfo(idUser));
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
messages.push({
code:'success',
message:'COMPANY_UPDATED'
});
}else{
messages.push({
code:'error',
message:'INTERNAL_SERVER_ERROR'
});
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);

View File

@@ -77,6 +77,7 @@ export const profileTexts = {
ADD_FIRST_NAME: 'The first name field can not be empty',
ADD_LAST_NAME: 'The last name field can not be empty',
ADD_INVOICE_MAIL: 'The invoice mail field can not be empty',
INVALID_INVOICE_MAIL: 'Invalid invoice mail address'
INVALID_INVOICE_MAIL: 'Invalid invoice mail address',
INTERNAL_SERVER_ERROR: 'Error occured. Please try again'
}
};