Skip to content

Commit

Permalink
Merge pull request #125 from xGouley/after-claiming
Browse files Browse the repository at this point in the history
GMC already linked at page loading
  • Loading branch information
Quetzacoalt91 authored Jun 14, 2021
2 parents 5c584cf + f249638 commit 3a95c67
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
<!-- <b-button
v-else
variant="primary"
@click="saveChangeExistingMca()"
@click="saveChangeExistingGmc()"
>
{{ $t('cta.saveChange') }}
</b-button> -->
Expand Down Expand Up @@ -258,7 +258,7 @@
<script>
/**
* TODO: Handle events (close, continue, etc...)
* Handle Existing MCA, check requirements that are already checked
* Handle Existing GMC, check requirements that are already checked
* by filling the data.selectedRequirements[]
*/
Expand Down Expand Up @@ -328,9 +328,9 @@ export default {
cancel() {
this.$refs.MerchantCenterAccountPopinNewMca.hide();
},
saveChangeExistingMca() {
saveChangeExistingGmc() {
/**
* TODO: Save change when existing MCA
* TODO: Save change when existing GMC
*/
},
},
Expand Down
5 changes: 3 additions & 2 deletions _dev/src/store/modules/accounts/actions-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ enum ActionsTypes {
TOGGLE_GOOGLE_ACCOUNT_IS_REGISTERED = 'TOGGLE_GOOGLE_ACCOUNT_IS_REGISTERED',
REQUEST_ROUTE_TO_GOOGLE_AUTH = 'REQUEST_ROUTE_TO_GOOGLE_AUTH',
REQUEST_GOOGLE_ACCOUNT_DETAILS = 'REQUEST_GOOGLE_ACCOUNT_DETAILS',
REQUEST_GOOGLE_ACCOUNT_GMC_LIST = 'REQUEST_GOOGLE_ACCOUNT_GMC_LIST',
REQUEST_GMC_DETAILS = 'REQUEST_GMC_DETAILS',
REQUEST_GMC_LIST = 'REQUEST_GMC_LIST',
DISSOCIATE_GOOGLE_ACCOUNT = 'DISSOCIATE_GOOGLE_ACCOUNT',
DISSOCIATE_MERCHANT_CENTER_ACCOUNT = 'DISSOCIATE_MERCHANT_CENTER_ACCOUNT',
DISSOCIATE_GMC = 'DISSOCIATE_GMC',
TRIGGER_WEBSITE_VERIFICATION_AND_CLAIMING_PROCESS = 'TRIGGER_WEBSITE_VERIFICATION_AND_CLAIMING_PROCESS',
/** Merchant Center Account - Website verification */
TRIGGER_WEBSITE_VERIFICATION_PROCESS = 'TRIGGER_WEBSITE_VERIFICATION_PROCESS',
Expand Down
39 changes: 28 additions & 11 deletions _dev/src/store/modules/accounts/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* International Registered Trademark & Property of PrestaShop SA
*/

import {content_v2_1 as contentApi} from '@googleapis/content/v2.1';
import {WebsiteClaimErrorReason} from '@/store/modules/accounts/state';
import MutationsTypes from './mutations-types';
import ActionsTypes from './actions-types';
Expand Down Expand Up @@ -77,7 +76,8 @@ export default {
if (!response.ok) {
throw new HttpClientError(response.statusText, response.status);
}
commit(MutationsTypes.SAVE_MCA_ACCOUNT, selectedAccount);

commit(MutationsTypes.SAVE_GMC, selectedAccount);
},

async [ActionsTypes.TRIGGER_WEBSITE_VERIFICATION_AND_CLAIMING_PROCESS](
Expand Down Expand Up @@ -190,6 +190,13 @@ export default {
const json = await response.json();
commit(MutationsTypes.SAVE_GOOGLE_ACCOUNT_TOKEN, json);
commit(MutationsTypes.SET_GOOGLE_ACCOUNT, json);
if (json.account_id && json.merchant_id) {
commit(MutationsTypes.SAVE_GMC, {
id: json.account_id,
});
// If GMC is already linked, must start by requesting GMC list, then look after the link GMC
dispatch(ActionsTypes.REQUEST_GMC_LIST);
}
return json;
} catch (error) {
if (error instanceof HttpClientError && (error.code === 404 || error.code === 412)) {
Expand All @@ -203,8 +210,8 @@ export default {
return null;
},

async [ActionsTypes.REQUEST_GOOGLE_ACCOUNT_GMC_LIST]({
commit, state, rootState,
async [ActionsTypes.REQUEST_GMC_LIST]({
commit, state, rootState, dispatch,
}) {
try {
const response = await fetch(`${rootState.app.psGoogleShoppingApiUrl}/merchant-accounts`, {
Expand All @@ -217,31 +224,40 @@ export default {
throw new HttpClientError(response.statusText, response.status);
}
const json = await response.json();
commit(MutationsTypes.SAVE_GOOGLE_ACCOUNT_MCA_LIST, json);
commit(MutationsTypes.SAVE_GMC_LIST, json);

// Now we have the GMC merchant's list, if he already linked one, then must fill it now
if (state.googleMerchantAccount.id) {
const linkedGmc = json.find((gmc) => gmc.id === state.googleMerchantAccount.id);
if (linkedGmc) {
commit(MutationsTypes.SAVE_GMC, linkedGmc);
dispatch(ActionsTypes.TRIGGER_WEBSITE_VERIFICATION_AND_CLAIMING_PROCESS);
}
}
} catch (error) {
console.error(error);
}
},

[ActionsTypes.DISSOCIATE_GOOGLE_ACCOUNT]({commit, dispatch}) {
dispatch(ActionsTypes.DISSOCIATE_MERCHANT_CENTER_ACCOUNT);
dispatch(ActionsTypes.DISSOCIATE_GMC);
// ToDo: Add API calls if needed
commit(MutationsTypes.REMOVE_GOOGLE_ACCOUNT);
commit(MutationsTypes.SET_GOOGLE_ACCOUNT, null);
dispatch(ActionsTypes.REQUEST_ROUTE_TO_GOOGLE_AUTH);
dispatch(ActionsTypes.TOGGLE_GOOGLE_ACCOUNT_IS_REGISTERED, false);
},

[ActionsTypes.DISSOCIATE_MERCHANT_CENTER_ACCOUNT]({commit, dispatch, state}) {
[ActionsTypes.DISSOCIATE_GMC]({commit, dispatch, state}) {
// ToDo: Add API calls if needed
commit(MutationsTypes.REMOVE_MCA_ACCOUNT);
commit(MutationsTypes.REMOVE_GMC);
},

[ActionsTypes.REQUEST_TO_OVERRIDE_CLAIM]({commit}) {
// ToDo: Add API call for get new status
const resp = '';

// After response for API, change statement for claiming to trigger watcher on MCA card
// After response for API, change statement for claiming to trigger watcher on GMC card
commit(MutationsTypes.SAVE_WEBSITE_CLAIMING_STATUS, false);
setTimeout(() => {
commit(MutationsTypes.SAVE_STATUS_OVERRIDE_CLAIMING, resp);
Expand All @@ -267,12 +283,13 @@ export default {
if (!isVerified) {
throw new Error('Website was not verified by Google');
}
// 5- Remove token from shop
await dispatch(ActionsTypes.SAVE_WEBSITE_VERIFICATION_META, false);
return {isVerified, isClaimed};
} catch (error) {
console.error(error);
return {isVerified: false, isClaimed: false};
} finally {
// Remove token anyway
await dispatch(ActionsTypes.SAVE_WEBSITE_VERIFICATION_META, false);
}
},

Expand Down
10 changes: 5 additions & 5 deletions _dev/src/store/modules/accounts/mutations-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ enum MutationsTypes {
SET_GOOGLE_ACCOUNT = 'SET_GOOGLE_ACCOUNT',
REMOVE_GOOGLE_ACCOUNT = 'REMOVE_GOOGLE_ACCOUNT',
SAVE_GOOGLE_ACCOUNT_CONNECTED_ONCE = 'SAVE_GOOGLE_ACCOUNT_CONNECTED_ONCE',
SAVE_GOOGLE_ACCOUNT_MCA_LIST = 'SAVE_GOOGLE_ACCOUNT_MCA_LIST',
SAVE_MCA_ACCOUNT = 'SAVE_MCA_ACCOUNT',
REMOVE_MCA_ACCOUNT = 'REMOVE_MCA_ACCOUNT',
SAVE_MCA_WEBSITE_VERIFICATION_PROGRESS_STATUS = 'SAVE_MCA_WEBSITE_VERIFICATION_PROGRESS_STATUS',
SAVE_MCA_WEBSITE_VERIFICATION_STATUS = 'SAVE_MCA_WEBSITE_VERIFICATION_STATUS',
SAVE_GMC_LIST = 'SAVE_GMC_LIST',
SAVE_GMC = 'SAVE_GMC',
REMOVE_GMC = 'REMOVE_GMC',
SAVE_GMC_WEBSITE_VERIFICATION_PROGRESS_STATUS = 'SAVE_GMC_WEBSITE_VERIFICATION_PROGRESS_STATUS',
SAVE_GMC_WEBSITE_VERIFICATION_STATUS = 'SAVE_GMC_WEBSITE_VERIFICATION_STATUS',
SET_GOOGLE_AUTHENTICATION_URL = 'SET_GOOGLE_AUTHENTICATION_URL',
SET_GOOGLE_AUTHENTICATION_RESPONSE = 'SET_GOOGLE_AUTHENTICATION_RESPONSE',
SAVE_WEBSITE_CLAIMING_STATUS = 'SAVE_WEBSITE_CLAIMING_STATUS',
Expand Down
6 changes: 3 additions & 3 deletions _dev/src/store/modules/accounts/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default {
[MutationsTypes.SAVE_GOOGLE_ACCOUNT_CONNECTED_ONCE](state: LocalState, response) {
state.googleAccount.connectedOnce = response;
},
[MutationsTypes.SAVE_GOOGLE_ACCOUNT_MCA_LIST](
[MutationsTypes.SAVE_GMC_LIST](
state: LocalState,
mcaSelectionOptions: contentApi.Schema$Account[],
) {
Expand All @@ -69,13 +69,13 @@ export default {
/** End of Google Account mutations */

/** Merchant Center Account mutations */
[MutationsTypes.SAVE_MCA_ACCOUNT](state: LocalState, selectedAccount: contentApi.Schema$Account) {
[MutationsTypes.SAVE_GMC](state: LocalState, selectedAccount: contentApi.Schema$Account) {
state.googleMerchantAccount = {
...state.googleMerchantAccount,
...selectedAccount,
};
},
[MutationsTypes.REMOVE_MCA_ACCOUNT](state: LocalState) {
[MutationsTypes.REMOVE_GMC](state: LocalState) {
state.googleMerchantAccount = {
...state.googleMerchantAccount,
id: null,
Expand Down

0 comments on commit 3a95c67

Please sign in to comment.