Skip to content

Commit

Permalink
Merge pull request #4 from disha1202/#2me4rbb-updated
Browse files Browse the repository at this point in the history
Fixed: code to login only when getting stores(#2me4rbb)
  • Loading branch information
adityasharma7 authored Jul 25, 2022
2 parents 015ddc8 + 4449d79 commit 05d619f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"Order Details": "Order Details",
"Order Updated successfully.": "Order Updated successfully.",
"Save changes to order": "Save changes to order",
"Stores missing. You can not login.": "Stores missing. You can not login.",
"No shipping estimates": "No shipping estimates",
"None": "None"
}
9 changes: 6 additions & 3 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ const generateAccessToken = async (config: any): Promise <any> => {
});
}

const getStores = async (payload: any): Promise <any> => {
return api({
const getStores = async (config: any): Promise <any> => {
let baseURL = store.getters['user/getInstanceUrl'];
baseURL = baseURL && baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`;
return client({
url: "storeLookup",
method: 'post',
data: payload
baseURL: baseURL,
...config
})
}

Expand Down
32 changes: 23 additions & 9 deletions src/store/modules/shop/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import ShopState from './ShopState'
import * as types from './mutation-types'
import { getStores } from "@/services"
import { getShopifyConfigId, getStores } from '@/services'
import { hasError } from '@/utils'

const actions: ActionTree<ShopState, RootState> = {
Expand All @@ -12,22 +12,36 @@ const actions: ActionTree<ShopState, RootState> = {
setShop({ commit }, payload) {
commit(types.SHOP_UPDATED, { shop: payload })
},
async getStores({commit}) {
async getStores({commit}, payload){
let resp;
const payload = {
//Increased the viewSize as we have not implemented infinite scroll, will use the default when UI is updated.
"viewSize": 50
}

try {
resp = await getStores(payload);
if(resp.status === 200 && !hasError(resp) && resp.data.response?.docs){
if(resp.status === 200 && !hasError(resp) && resp.data.response?.docs?.length > 0){
commit(types.SHOP_STORES_UPDATED, resp.data.response.docs);
return resp.data.response.docs;
} else {
return [];
}

} catch(err){
console.error(err);
return [];
}
},
async getShopifyConfigId({commit}, payload){
let resp;
try {
resp = await getShopifyConfigId(payload);
if(resp.status === 200 && !hasError(resp) && resp.data?.docs){
const shopifyConfigId = resp.data.docs[0].shopifyConfigId
commit(types.SHOP_CONFIG_ID_UPDATED, shopifyConfigId);
return shopifyConfigId;
} else {
console.error(resp);
return "";
}
} catch(err) {
console.error(err);
return "";
}
}
}
Expand Down
54 changes: 35 additions & 19 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getShopifyConfigId } from '@/services'
import { UserService } from '@/services/UserService'
import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
Expand All @@ -14,32 +13,49 @@ const actions: ActionTree<UserState, RootState> = {
const resp = await UserService.login(username, password)
if (resp.status === 200 && resp.data) {
if (resp.data.token) {
const shop = this.state.shop.shop;
const shopifyConfigIdResp = await getShopifyConfigId({
const stores = await store.dispatch('shop/getStores', {
data: {
'inputFields': {
'apiUrl': `https://${shop}/`
},
"entityName": "ShopifyConfig",
"noConditionFind": "Y",
"fieldList": ['shopifyConfigId']
//Increased the viewSize as we have not implemented infinite scroll, will use the default when UI is updated.
"viewSize": 50
},
headers: {
Authorization: 'Bearer ' + resp.data.token,
'Content-Type': 'application/json'
}
})
if(shopifyConfigIdResp.status === 200 && !hasError(shopifyConfigIdResp) && shopifyConfigIdResp.data?.docs){
store.commit('shop/shop/CONFIG_ID_UPDATED', shopifyConfigIdResp.data.docs[0].shopifyConfigId)
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
await dispatch('getProfile')
return resp.data;
if(stores.length){
const shop = this.state.shop.shop;
const shopifyConfigId = await store.dispatch('shop/getShopifyConfigId', {
data: {
'inputFields': {
'apiUrl': `https://${shop}/`
},
"entityName": "ShopifyConfig",
"noConditionFind": "Y",
"fieldList": ['shopifyConfigId']
},
headers: {
Authorization: 'Bearer ' + resp.data.token,
'Content-Type': 'application/json'
}
})

if(shopifyConfigId){
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
await dispatch('getProfile')
return resp.data;
} else {
const shopifyConfigIdError = "Shopify Configuration missing. You can not login."
showToast(translate(shopifyConfigIdError));
console.error("error", shopifyConfigIdError);
return Promise.reject(new Error(shopifyConfigIdError));
}
} else {
const shopifyConfigIdError = "Shopify Configuration missing. You can not login."
showToast(translate(shopifyConfigIdError));
console.error("error", shopifyConfigIdError);
return Promise.reject(new Error(shopifyConfigIdError));
}
const storesError = "Stores missing. You can not login."
showToast(translate(storesError));
console.error("error", storesError);
return Promise.reject(new Error(storesError));
}
} else if (hasError(resp)) {
showToast(translate('Sorry, your username or password is incorrect. Please try again.'));
console.error("error", resp.data._ERROR_MESSAGE_);
Expand Down
1 change: 0 additions & 1 deletion src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export default defineComponent({
if (data.token) {
this.username = ''
this.password = ''
await this.store.dispatch('shop/getStores');
this.store.dispatch('order/getDraftOrder', this.$route.redirectedFrom?.query.id);
this.$router.push('/order-detail');
}
Expand Down
7 changes: 4 additions & 3 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ export default defineComponent({
},
markPreorderBackorderItem (item: any, event: any) {
const product = this.getPreorderItemAvailability(item.sku)
if(product){
item.properties.push({ name: 'Note', value: event.detail.value }, { name: 'PROMISE_DATE', value: DateTime.fromISO(product.estimatedDeliveryDate).toFormat("MM/dd/yyyy") })
this.store.dispatch('order/updateLineItems', this.order);
item.properties.push({ name: 'Note', value: event.detail.value });
if(product.estimatedDeliveryDate){
item.properties.push({ name: 'PROMISE_DATE', value: DateTime.fromISO(product.estimatedDeliveryDate).toFormat("MM/dd/yyyy") })
}
this.store.dispatch('order/updateLineItems', this.order);
},
updateDraftOrder () {
this.store.dispatch('order/updateDraftOrder', this.order);
Expand Down

0 comments on commit 05d619f

Please sign in to comment.