From 597de432ec75b72e0c8c4e873cf72170d8c4ebcc Mon Sep 17 00:00:00 2001 From: Bashu Tiwari Date: Wed, 15 Dec 2021 15:07:27 +0530 Subject: [PATCH] Implemented instance url flow --- src/api/index.ts | 4 +++- src/i18n/locales/en.json | 1 + src/store/modules/user/UserState.ts | 1 + src/store/modules/user/actions.ts | 7 +++++++ src/store/modules/user/getters.ts | 3 +++ src/store/modules/user/index.ts | 3 ++- src/store/modules/user/mutation-types.ts | 3 ++- src/store/modules/user/mutations.ts | 3 +++ src/views/login.vue | 21 ++++++++++++++++++--- 9 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 382220652..4144170ec 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -69,7 +69,9 @@ const api = async (customConfig: any) => { data: customConfig.data, params: customConfig.params } - const baseURL = process.env.VUE_APP_BASE_URL; + + let baseURL = store.getters['user/getInstanceUrl']; + baseURL = baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`; if (baseURL) config.baseURL = baseURL; if(customConfig.cache) config.adapter = axiosCache.adapter; diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 05aa0f227..b16b60528 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -25,6 +25,7 @@ "Enter an order ID, product name, style name, SKU, customer name, UPCA or external ID":"Enter an order ID, product name, style name, SKU, customer name, UPCA or external ID", "How are orders released?":"How are orders released?", "in stock": "in stock", + "Instance Url": "Instance Url", "Item cancelled successfully": "Item cancelled successfully", "items preordered": "items preordered", "Item promise date updated successfully": "Item promise date updated successfully", diff --git a/src/store/modules/user/UserState.ts b/src/store/modules/user/UserState.ts index 4b998b62f..ad1cdb039 100644 --- a/src/store/modules/user/UserState.ts +++ b/src/store/modules/user/UserState.ts @@ -2,4 +2,5 @@ export default interface UserState { token: string; current: object | null; selectedBrand: string; + instanceUrl: string; } \ No newline at end of file diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 0480e35e5..40e7a6b27 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -84,6 +84,13 @@ const actions: ActionTree = { // Reset all the current queries this.dispatch("product/resetProductList") this.dispatch("order/resetOrderQuery") + }, + + /** + * Set User Instance Url + */ + setUserInstanceUrl ({ state, commit }, payload){ + commit(types.USER_INSTANCE_URL_UPDATED, payload) } } export default actions; \ No newline at end of file diff --git a/src/store/modules/user/getters.ts b/src/store/modules/user/getters.ts index 43e825abf..17cd0b9e7 100644 --- a/src/store/modules/user/getters.ts +++ b/src/store/modules/user/getters.ts @@ -17,6 +17,9 @@ const getters: GetterTree = { }, getSelectedBrand (state) { return state.selectedBrand + }, + getInstanceUrl (state) { + return state.instanceUrl; } } export default getters; \ No newline at end of file diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts index 89c53249e..7ab86abf0 100644 --- a/src/store/modules/user/index.ts +++ b/src/store/modules/user/index.ts @@ -10,7 +10,8 @@ const userModule: Module = { state: { token: '', current: null, - selectedBrand: '' + selectedBrand: '', + instanceUrl: '', }, getters, actions, diff --git a/src/store/modules/user/mutation-types.ts b/src/store/modules/user/mutation-types.ts index be03f2481..cfb452c70 100644 --- a/src/store/modules/user/mutation-types.ts +++ b/src/store/modules/user/mutation-types.ts @@ -2,4 +2,5 @@ export const SN_USER = 'user' export const USER_TOKEN_CHANGED = SN_USER + '/TOKEN_CHANGED' export const USER_END_SESSION = SN_USER + '/END_SESSION' export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED' -export const USER_BRAND_UPDATED = SN_USER + '/BRAND_UPDATED' \ No newline at end of file +export const USER_BRAND_UPDATED = SN_USER + '/BRAND_UPDATED' +export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED' \ No newline at end of file diff --git a/src/store/modules/user/mutations.ts b/src/store/modules/user/mutations.ts index d5012df44..f17aea6df 100644 --- a/src/store/modules/user/mutations.ts +++ b/src/store/modules/user/mutations.ts @@ -16,5 +16,8 @@ const mutations: MutationTree = { [types.USER_BRAND_UPDATED] (state, payload) { state.selectedBrand = payload }, + [types.USER_INSTANCE_URL_UPDATED] (state, payload) { + state.instanceUrl = payload; + } } export default mutations; \ No newline at end of file diff --git a/src/views/login.vue b/src/views/login.vue index d208ed3cd..59fea649a 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -5,13 +5,17 @@