use customer endpoint for profile actions

This commit is contained in:
Bilal Catic
2018-09-19 16:08:33 +02:00
parent 31115b7c6a
commit 498f5526a9
2 changed files with 41 additions and 89 deletions

View File

@@ -12,6 +12,7 @@ import {
import {updateMessages} from '../notification/notificationActions';
import {setDialogOpenFlag} from '../dialog/dialogActions';
import {recieveProfileInfo} from './profileSettingsActions';
import { fromWiaasProfileInfo } from '../../helpers/ProfileHelper';
const client = new HtmlClient();
@@ -23,26 +24,18 @@ export const saveProfileAddress = (idUser, profileAddress) => {
return dispatch => {
dispatch(requestSaveAddress());
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses`,
method: 'put',
data: {deliveryAddress: JSON.stringify(profileAddress)}
data: {
'profile_address': JSON.stringify(profileAddress)
}
})
.then(response => {
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
dispatch(updateMessages(response.data.messages, profileTexts.messages));
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);
@@ -58,25 +51,17 @@ export const removeProfileAddress = (idUser, idProfileAddress) => {
return dispatch => {
dispatch(requestRemoveAddress());
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
method: 'put',
data: {removeDeliveryAddress:idProfileAddress}
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses`,
method: 'post',
data: {
'address_id':idProfileAddress
}
})
.then(response => {
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(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
dispatch(updateMessages(response.data.messages, profileTexts.messages));
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);
@@ -92,26 +77,18 @@ export const saveBillingAddress = (idUser, billingAddress) => {
return dispatch => {
dispatch(requestSaveBillingAddress());
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses`,
method: 'put',
data: {billingAddress: JSON.stringify(billingAddress)}
data: {
'billing_address': JSON.stringify(billingAddress)
}
})
.then(response => {
let messages = [];
if(response.data){
dispatch(recieveProfileInfo(response.data));
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
dispatch(updateMessages(response.data.messages, profileTexts.messages));
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);
@@ -127,25 +104,18 @@ export const removeBillingAddress = (idUser, idBillingAddress) => {
return dispatch => {
dispatch(requestRemoveBillingAddress());
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
method: 'put',
data: {removeBillingAddress:idBillingAddress}
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses`,
method: 'POST',
data: {
'address_id':idBillingAddress
}
})
.then(response => {
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(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
dispatch(updateMessages(response.data.messages, profileTexts.messages));
dispatch(setDialogOpenFlag(false));
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);

View File

@@ -12,6 +12,8 @@ import {
profileTexts
} from '../../constants/profileSettingsConstants';
import {updateMessages} from '../notification/notificationActions';
import { fromWiaasProfileInfo} from '../../helpers/ProfileHelper';
import {fromWiaasCountryList} from '../../helpers/CountryHelper';
const client = new HtmlClient();
@@ -35,7 +37,7 @@ export const fetchProfileInfo = (idUser) => {
})
.then(response => {
if(response.data){
dispatch(recieveProfileInfo(response.data));
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data)));
}
});
}
@@ -50,8 +52,8 @@ export const saveProfileInfo = (idUser, profile) => {
dispatch(requestSaveProfile());
const parsedFullName = profile.name.trim().split(' ');
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
method: 'put',
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/personal-info`,
method: 'PUT',
data: {
'first_name': parsedFullName[0],
'last_name': parsedFullName[1],
@@ -59,20 +61,10 @@ export const saveProfileInfo = (idUser, profile) => {
}
})
.then(response => {
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(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
dispatch(updateMessages(response.data.messages, profileTexts.messages));
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);
@@ -88,28 +80,18 @@ export const saveCompanyInfo = (idUser, companyInfo) => {
return dispatch => {
dispatch(requestSaveCompany());
return client.fetch({
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/company-info`,
method: 'put',
data: {
vatCode: companyInfo.vatCode,
companyName: companyInfo.companyName
'vat_code': companyInfo.vatCode,
'company_name': companyInfo.companyName
}
})
.then(response => {
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(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
dispatch(updateMessages(response.data.messages, profileTexts.messages));
}
dispatch(updateMessages(messages, profileTexts.messages));
})
.catch(error => {
client.onError(error, dispatch);
@@ -137,7 +119,7 @@ export const fetchCountries = () => {
})
.then(response => {
if(response.data){
dispatch(recieveCountries(response.data));
dispatch(recieveCountries(response.data.map(country => fromWiaasCountryList(country))));
}
})
.catch(error => {