use customer endpoint for profile actions
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
import {updateMessages} from '../notification/notificationActions';
|
import {updateMessages} from '../notification/notificationActions';
|
||||||
import {setDialogOpenFlag} from '../dialog/dialogActions';
|
import {setDialogOpenFlag} from '../dialog/dialogActions';
|
||||||
import {recieveProfileInfo} from './profileSettingsActions';
|
import {recieveProfileInfo} from './profileSettingsActions';
|
||||||
|
import { fromWiaasProfileInfo } from '../../helpers/ProfileHelper';
|
||||||
|
|
||||||
const client = new HtmlClient();
|
const client = new HtmlClient();
|
||||||
|
|
||||||
@@ -23,26 +24,18 @@ export const saveProfileAddress = (idUser, profileAddress) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestSaveAddress());
|
dispatch(requestSaveAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: {deliveryAddress: JSON.stringify(profileAddress)}
|
data: {
|
||||||
|
'profile_address': JSON.stringify(profileAddress)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let messages = [];
|
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveProfileInfo(response.data));
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
dispatch(setDialogOpenFlag(false));
|
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 => {
|
.catch(error => {
|
||||||
client.onError(error, dispatch);
|
client.onError(error, dispatch);
|
||||||
@@ -58,25 +51,17 @@ export const removeProfileAddress = (idUser, idProfileAddress) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestRemoveAddress());
|
dispatch(requestRemoveAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses`,
|
||||||
method: 'put',
|
method: 'post',
|
||||||
data: {removeDeliveryAddress:idProfileAddress}
|
data: {
|
||||||
|
'address_id':idProfileAddress
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let messages = [];
|
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveProfileInfo(response.data));
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
messages.push({
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
code:'success',
|
|
||||||
message:'ADDRESS_REMOVED'
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
messages.push({
|
|
||||||
code:'error',
|
|
||||||
message:'INTERNAL_SERVER_ERROR'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
dispatch(updateMessages(messages, profileTexts.messages));
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
client.onError(error, dispatch);
|
client.onError(error, dispatch);
|
||||||
@@ -92,26 +77,18 @@ export const saveBillingAddress = (idUser, billingAddress) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestSaveBillingAddress());
|
dispatch(requestSaveBillingAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: {billingAddress: JSON.stringify(billingAddress)}
|
data: {
|
||||||
|
'billing_address': JSON.stringify(billingAddress)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let messages = [];
|
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveProfileInfo(response.data));
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
dispatch(setDialogOpenFlag(false));
|
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 => {
|
.catch(error => {
|
||||||
client.onError(error, dispatch);
|
client.onError(error, dispatch);
|
||||||
@@ -127,25 +104,18 @@ export const removeBillingAddress = (idUser, idBillingAddress) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestRemoveBillingAddress());
|
dispatch(requestRemoveBillingAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses`,
|
||||||
method: 'put',
|
method: 'POST',
|
||||||
data: {removeBillingAddress:idBillingAddress}
|
data: {
|
||||||
|
'address_id':idBillingAddress
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let messages = [];
|
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveProfileInfo(response.data));
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
messages.push({
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
code:'success',
|
dispatch(setDialogOpenFlag(false));
|
||||||
message:'BILLING_ADDRESS_REMOVED'
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
messages.push({
|
|
||||||
code:'error',
|
|
||||||
message:'INTERNAL_SERVER_ERROR'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
dispatch(updateMessages(messages, profileTexts.messages));
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
client.onError(error, dispatch);
|
client.onError(error, dispatch);
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import {
|
|||||||
profileTexts
|
profileTexts
|
||||||
} from '../../constants/profileSettingsConstants';
|
} from '../../constants/profileSettingsConstants';
|
||||||
import {updateMessages} from '../notification/notificationActions';
|
import {updateMessages} from '../notification/notificationActions';
|
||||||
|
import { fromWiaasProfileInfo} from '../../helpers/ProfileHelper';
|
||||||
|
import {fromWiaasCountryList} from '../../helpers/CountryHelper';
|
||||||
|
|
||||||
const client = new HtmlClient();
|
const client = new HtmlClient();
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ export const fetchProfileInfo = (idUser) => {
|
|||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveProfileInfo(response.data));
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -50,8 +52,8 @@ export const saveProfileInfo = (idUser, profile) => {
|
|||||||
dispatch(requestSaveProfile());
|
dispatch(requestSaveProfile());
|
||||||
const parsedFullName = profile.name.trim().split(' ');
|
const parsedFullName = profile.name.trim().split(' ');
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/personal-info`,
|
||||||
method: 'put',
|
method: 'PUT',
|
||||||
data: {
|
data: {
|
||||||
'first_name': parsedFullName[0],
|
'first_name': parsedFullName[0],
|
||||||
'last_name': parsedFullName[1],
|
'last_name': parsedFullName[1],
|
||||||
@@ -59,20 +61,10 @@ export const saveProfileInfo = (idUser, profile) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let messages = [];
|
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveProfileInfo(response.data));
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
messages.push({
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
code:'success',
|
|
||||||
message:'PROFILE_UPDATED'
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
messages.push({
|
|
||||||
code:'error',
|
|
||||||
message:'INTERNAL_SERVER_ERROR'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
dispatch(updateMessages(messages, profileTexts.messages));
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
client.onError(error, dispatch);
|
client.onError(error, dispatch);
|
||||||
@@ -88,28 +80,18 @@ export const saveCompanyInfo = (idUser, companyInfo) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestSaveCompany());
|
dispatch(requestSaveCompany());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/company-info`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: {
|
data: {
|
||||||
vatCode: companyInfo.vatCode,
|
'vat_code': companyInfo.vatCode,
|
||||||
companyName: companyInfo.companyName
|
'company_name': companyInfo.companyName
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let messages = [];
|
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveProfileInfo(response.data));
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
messages.push({
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
code:'success',
|
|
||||||
message:'COMPANY_UPDATED'
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
messages.push({
|
|
||||||
code:'error',
|
|
||||||
message:'INTERNAL_SERVER_ERROR'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
dispatch(updateMessages(messages, profileTexts.messages));
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
client.onError(error, dispatch);
|
client.onError(error, dispatch);
|
||||||
@@ -137,7 +119,7 @@ export const fetchCountries = () => {
|
|||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data){
|
if(response.data){
|
||||||
dispatch(recieveCountries(response.data));
|
dispatch(recieveCountries(response.data.map(country => fromWiaasCountryList(country))));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
Reference in New Issue
Block a user