diff --git a/src/locales/en.json b/src/locales/en.json index c4cfac2..ba50d35 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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" } \ No newline at end of file diff --git a/src/services/index.ts b/src/services/index.ts index 6b5e68a..772ab16 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -9,11 +9,14 @@ const generateAccessToken = async (config: any): Promise => { }); } -const getStores = async (payload: any): Promise => { - return api({ +const getStores = async (config: any): Promise => { + 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 }) } diff --git a/src/store/modules/shop/actions.ts b/src/store/modules/shop/actions.ts index 1b533f7..9e2bff5 100644 --- a/src/store/modules/shop/actions.ts +++ b/src/store/modules/shop/actions.ts @@ -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 = { @@ -12,22 +12,36 @@ const actions: ActionTree = { 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 ""; } } } diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 7daa96c..04f6ba9 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -1,4 +1,3 @@ -import { getShopifyConfigId } from '@/services' import { UserService } from '@/services/UserService' import { ActionTree } from 'vuex' import RootState from '@/store/RootState' @@ -14,32 +13,49 @@ const actions: ActionTree = { 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_); diff --git a/src/views/Login.vue b/src/views/Login.vue index a600f02..bf83e01 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -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'); } diff --git a/src/views/OrderDetail.vue b/src/views/OrderDetail.vue index 1ec9d6d..eadfbb2 100644 --- a/src/views/OrderDetail.vue +++ b/src/views/OrderDetail.vue @@ -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);