Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: Add option to select shopify config from settings page(#2q9mut9) #217

Merged
merged 8 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/BatchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default defineComponent({
computed: {
...mapGetters({
getJob: 'job/getJob',
shopifyConfigId: 'user/getShopifyConfigId',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentEComStore: 'user/getCurrentEComStore',
userProfile: "user/getUserProfile"
}),
Expand Down
2 changes: 1 addition & 1 deletion src/components/JobConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default defineComponent({
...mapGetters({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
shopifyConfigId: 'user/getShopifyConfigId',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentEComStore: 'user/getCurrentEComStore',
currentJob: 'job/getCurrentJob',
}),
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"Service has been scheduled": "Service has been scheduled",
"Service updated successfully": "Service updated successfully",
"Settings": "Settings",
"Shopify Config": "Shopify Config",
"Skip": "Skip",
"Skip job": "Skip job",
"Skip once": "Skip once",
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ const actions: ActionTree<JobState, RootState> = {
'runAsUser': 'system', //default system, but empty in run now. TODO Need to remove this as we are using SERVICE_RUN_AS_SYSTEM, currently kept it for backward compatibility
'recurrenceTimeZone': this.state.user.current.userTimeZone
},
'shopifyConfigId': this.state.user.shopifyConfigId,
'shopifyConfigId': this.state.user.currentShopifyConfigId,
'statusId': "SERVICE_PENDING",
'systemJobEnumId': job.systemJobEnumId
} as any
Expand Down Expand Up @@ -531,7 +531,7 @@ const actions: ActionTree<JobState, RootState> = {
'parentJobId': job.parentJobId,
'recurrenceTimeZone': this.state.user.current.userTimeZone
},
'shopifyConfigId': job.status === "SERIVCE_PENDING" ? job.shopifyConfigId : this.state.user.shopifyConfigId,
'shopifyConfigId': job.status === "SERIVCE_PENDING" ? job.shopifyConfigId : this.state.user.currentShopifyConfigId,
'statusId': "SERVICE_PENDING",
'systemJobEnumId': job.systemJobEnumId
} as any
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default interface UserState {
current: object | null;
currentEComStore: object;
instanceUrl: string;
shopifyConfigId: string;
shopifyConfigs: any,
currentShopifyConfigId: string,
}
22 changes: 17 additions & 5 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,37 @@ const actions: ActionTree<UserState, RootState> = {
},
"entityName": "ShopifyConfig",
"noConditionFind": "Y",
"fieldList": ["shopifyConfigId"]
"fieldList": ["shopifyConfigId", "shopifyConfigName"]
}
try {
resp = await UserService.getShopifyConfig(payload);
if (resp.status === 200 && !hasError(resp) && resp.data?.docs) {
commit(types.USER_SHOPIFY_CONFIG_UPDATED, resp.data.docs?.length > 0 ? resp.data.docs[0].shopifyConfigId : "");
const shopifyConfigs = resp.data.docs;
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, shopifyConfigs);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, shopifyConfigs.length > 0 ? shopifyConfigs[0].shopifyConfigId : "");
} else {
console.error(resp);
commit(types.USER_SHOPIFY_CONFIG_UPDATED, "");
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, "");
}
} catch (err) {
console.error(err);
commit(types.USER_SHOPIFY_CONFIG_UPDATED, "");
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, "");
}
} else {
commit(types.USER_SHOPIFY_CONFIG_UPDATED, "");
commit(types.USER_SHOPIFY_CONFIG_LIST_UPDATED, []);
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, "");
}
},

/**
* update current shopify config id
*/
async setCurrentShopifyConfigId({ commit }, id) {
commit(types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED, id);
},

async getEComStores(_context, payload) {
let resp;

Expand Down
7 changes: 5 additions & 2 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ const getters: GetterTree <UserState, RootState> = {
getInstanceUrl (state) {
return state.instanceUrl;
},
getShopifyConfigId (state) {
return state.shopifyConfigId;
getCurrentShopifyConfigId (state) {
return state.currentShopifyConfigId;
},
getShopifyConfigs (state) {
return state.shopifyConfigs;
},
getCurrentEComStore(state) {
return state.currentEComStore
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const userModule: Module<UserState, RootState> = {
token: '',
current: null,
instanceUrl: '',
shopifyConfigId: "",
shopifyConfigs: [],
currentShopifyConfigId: "",
currentEComStore: {
productStoreId: "",
storeName: "None"
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ 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_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_SHOPIFY_CONFIG_UPDATED = SN_USER + '/SHOPIFY_CONFIG_UPDATED'
export const USER_SHOPIFY_CONFIG_LIST_UPDATED = SN_USER + '/SHOPIFY_CONFIG_LIST_UPDATED'
export const USER_CURRENT_SHOPIFY_CONFIG_UPDATED = SN_USER + '/SHOPIFY_CONFIG_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
10 changes: 7 additions & 3 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ const mutations: MutationTree <UserState> = {
[types.USER_END_SESSION] (state) {
state.token = ''
state.current = null
state.shopifyConfigId = ""
state.currentShopifyConfigId = ""
state.currentEComStore = {
productStoreId: "",
storeName: "None"
}
state.shopifyConfigs = []
},
[types.USER_INFO_UPDATED] (state, payload) {
state.current = payload
},
[types.USER_INSTANCE_URL_UPDATED] (state, payload) {
state.instanceUrl = payload;
},
[types.USER_SHOPIFY_CONFIG_UPDATED] (state, payload) {
state.shopifyConfigId = payload;
[types.USER_CURRENT_SHOPIFY_CONFIG_UPDATED] (state, payload) {
state.currentShopifyConfigId = payload;
},
[types.USER_SHOPIFY_CONFIG_LIST_UPDATED] (state, payload) {
state.shopifyConfigs = payload
},
[types.USER_CURRENT_ECOM_STORE_UPDATED] (state, payload) {
state.currentEComStore = payload;
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/webhook/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { translate } from '@/i18n'

const actions: ActionTree<WebhookState, RootState> = {
async fetchWebhooks({ commit }) {
await WebhookService.fetchShopifyWebhooks({ shopifyConfigId: this.state.user.shopifyConfigId }).then(resp => {
await WebhookService.fetchShopifyWebhooks({ shopifyConfigId: this.state.user.currentShopifyConfigId }).then(resp => {
if (resp.status == 200 && resp.data.webhooks?.length > 0 && !hasError(resp)) {
const webhooks = resp.data.webhooks;
const topics: any = {}
Expand Down Expand Up @@ -39,7 +39,7 @@ const actions: ActionTree<WebhookState, RootState> = {
let resp;

try {
resp = await WebhookService.subscribeWebhook({ shopifyConfigId: this.state.user.shopifyConfigId }, id)
resp = await WebhookService.subscribeWebhook({ shopifyConfigId: this.state.user.currentShopifyConfigId }, id)

if (resp.status == 200 && !hasError(resp)) {
showToast(translate('Webhook subscribed successfully'))
Expand Down
4 changes: 2 additions & 2 deletions src/views/InitialLoad.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default defineComponent({
...mapGetters({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
shopifyConfigId: 'user/getShopifyConfigId',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentEComStore: 'user/getCurrentEComStore',
getCachedWebhook: 'webhook/getCachedWebhook'
}),
Expand Down Expand Up @@ -207,7 +207,7 @@ export default defineComponent({
if (checked) {
await this.store.dispatch('webhook/subscribeWebhook', enumId)
} else {
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.shopifyConfigId })
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfigId })
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/views/Inventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default defineComponent({
...mapGetters({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
shopifyConfigId: 'user/getShopifyConfigId',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr'
}),
Expand Down
4 changes: 2 additions & 2 deletions src/views/Orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default defineComponent({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
orderBatchJobs: "job/getOrderBatchJobs",
shopifyConfigId: 'user/getShopifyConfigId',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr',
getCachedWebhook: 'webhook/getCachedWebhook'
Expand Down Expand Up @@ -275,7 +275,7 @@ export default defineComponent({
if (checked) {
await this.store.dispatch('webhook/subscribeWebhook', enumId)
} else {
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.shopifyConfigId })
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfigId })
}
},
async addBatch() {
Expand Down
2 changes: 1 addition & 1 deletion src/views/PreOrder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default defineComponent({
...mapGetters({
getJobStatus: 'job/getJobStatus',
getJob: 'job/getJob',
shopifyConfigId: 'user/getShopifyConfigId',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr'
}),
Expand Down
4 changes: 2 additions & 2 deletions src/views/Product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default defineComponent({
getJobStatus: 'job/getJobStatus',
getTemporalExpr: 'job/getTemporalExpr',
getJob: 'job/getJob',
shopifyConfigId: 'user/getShopifyConfigId',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId',
getCachedWebhook: 'webhook/getCachedWebhook'
}),
newProductsWebhook(): boolean {
Expand Down Expand Up @@ -142,7 +142,7 @@ export default defineComponent({
if (checked) {
await this.store.dispatch('webhook/subscribeWebhook', enumId)
} else {
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.shopifyConfigId })
await this.store.dispatch('webhook/unsubscribeWebhook', { webhookId: webhook?.id, shopifyConfigId: this.currentShopifyConfigId })
}
},
async viewJobConfiguration(id: string, title: string, status: string) {
Expand Down
15 changes: 14 additions & 1 deletion src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
<ion-select-option v-for="store in (userProfile ? userProfile.stores : [])" :key="store.productStoreId" :value="store.productStoreId" >{{ store.storeName }}</ion-select-option>
</ion-select>
</ion-item>
<!-- Select shopify config -->
<ion-item>
<ion-icon :icon="globeOutline" slot="start" />
<ion-label>{{ $t("Shopify Config") }}</ion-label>
<ion-select interface="popover" :value="currentShopifyConfigId" @ionChange="setShopifyConfig($event)">
<ion-select-option v-for="shopifyConfig in shopifyConfigs" :key="shopifyConfig.shopifyConfigId" :value="shopifyConfig.shopifyConfigId" >{{ shopifyConfig.shopifyConfigName }}</ion-select-option>
</ion-select>
</ion-item>
<!-- OMS information -->
<ion-item>
<ion-icon :icon="codeWorkingOutline" slot="start"/>
Expand Down Expand Up @@ -72,7 +80,9 @@ export default defineComponent({
...mapGetters({
userProfile: 'user/getUserProfile',
currentEComStore: 'user/getCurrentEComStore',
instanceUrl: 'user/getInstanceUrl'
instanceUrl: 'user/getInstanceUrl',
shopifyConfigs: 'user/getShopifyConfigs',
currentShopifyConfigId: 'user/getCurrentShopifyConfigId'
})
},
methods: {
Expand All @@ -83,6 +93,9 @@ export default defineComponent({
})
}
},
setShopifyConfig(event: any){
this.store.dispatch('user/setCurrentShopifyConfigId', event.detail.value);
},
async changeTimeZone() {
const timeZoneModal = await modalController.create({
component: TimeZoneModal,
Expand Down