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: product identifier component from dxp-components (dxp-178) #193

Merged
merged 6 commits into from
Feb 8, 2024
10 changes: 9 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import emitter from "@/event-bus"
import { mapGetters, useStore } from 'vuex';
import { initialise, resetConfig } from '@/adapter'
import { useRouter } from 'vue-router';
import { useProductIdentificationStore } from '@hotwax/dxp-components';

export default defineComponent({
name: 'App',
Expand All @@ -28,7 +29,8 @@ export default defineComponent({
computed: {
...mapGetters({
userToken: 'user/getUserToken',
instanceUrl: 'user/getInstanceUrl'
instanceUrl: 'user/getInstanceUrl',
currentEComStore: 'user/getCurrentEComStore'
})
},
methods: {
Expand Down Expand Up @@ -84,6 +86,12 @@ export default defineComponent({
});
emitter.on('presentLoader', this.presentLoader);
emitter.on('dismissLoader', this.dismissLoader);

if(this.userToken) {
// Get product identification from api using dxp-component
await useProductIdentificationStore().getIdentificationPref(this.currentEComStore?.productStoreId)
.catch((error) => console.error(error));
}
},
unmounted() {
emitter.off('presentLoader', this.presentLoader);
Expand Down
4 changes: 3 additions & 1 deletion src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { api, client, getConfig, initialise, logout, resetConfig, updateInstanceUrl, updateToken } from '@hotwax/oms-api'
import { api, client, getConfig, getProductIdentificationPref, initialise, logout, resetConfig, setProductIdentificationPref, updateInstanceUrl, updateToken } from '@hotwax/oms-api'

export {
api,
client,
getConfig,
getProductIdentificationPref,
initialise,
logout,
resetConfig,
setProductIdentificationPref,
updateInstanceUrl,
updateToken
}
13 changes: 9 additions & 4 deletions src/components/Picklist-detail-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</ion-thumbnail>
<ion-label>
<p class="caption">{{ getProduct(picklistItem.productId).parentProductName}}</p>
<h2>{{ getProduct(picklistItem.productId).productName}}</h2>
<h2>{{ picklistItem.productId }}</h2>
<h2>{{ getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(picklistItem.productId)) ? getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(picklistItem.productId)) : getProduct(picklistItem.productId).productName }}</h2>
<h2>{{ getProductIdentificationValue(productIdentificationPref.secondaryId, getProduct(picklistItem.productId)) }}</h2>
<p>{{ $t("Color") }} : {{ $filters.getFeatures(getProduct(picklistItem.productId).featureHierarchy, '1/COLOR/') }}</p>
<p>{{ $t("Size") }} : {{ $filters.getFeatures(getProduct(picklistItem.productId).featureHierarchy, '1/SIZE/') }}</p>
</ion-label>
Expand All @@ -16,9 +16,9 @@

<script lang="ts">
import { IonCheckbox, IonItem, IonLabel, IonThumbnail } from '@ionic/vue';
import { defineComponent } from 'vue';
import { computed, defineComponent } from 'vue';
import { mapGetters, useStore } from 'vuex';
import { ShopifyImg } from '@hotwax/dxp-components';
import { getProductIdentificationValue, ShopifyImg, useProductIdentificationStore } from '@hotwax/dxp-components';

export default defineComponent({
name: 'PicklistDetailItem',
Expand All @@ -37,7 +37,12 @@ export default defineComponent({
},
setup() {
const store = useStore();
const productIdentificationStore = useProductIdentificationStore();
let productIdentificationPref = computed(() => productIdentificationStore.getProductIdentificationPref)

return {
getProductIdentificationValue,
productIdentificationPref,
store
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import i18n from './i18n'
import store from './store'
import { dxpComponents } from '@hotwax/dxp-components'
import { login, logout, loader } from './user-utils';
import { getConfig, initialise } from '@/adapter'
import { getConfig, getProductIdentificationPref, initialise, setProductIdentificationPref } from '@/adapter'

const app = createApp(App)
.use(IonicVue, {
Expand All @@ -46,7 +46,9 @@ const app = createApp(App)
loader,
appLoginUrl: process.env.VUE_APP_LOGIN_URL as string,
getConfig,
initialise
getProductIdentificationPref,
initialise,
setProductIdentificationPref
});

// Filters are removed in Vue 3 and global filter introduced https://v3.vuejs.org/guide/migration/filters.html#global-filters
Expand Down
44 changes: 43 additions & 1 deletion src/services/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { api, client } from '@/adapter'
import store from '@/store';
import { hasError } from '@/utils';

const login = async (username: string, password: string): Promise <any> => {
return api({
Expand All @@ -23,6 +24,46 @@ const checkPermission = async (payload: any): Promise <any> => {
});
}

const getCurrentEComStore = async (token: any, facilityId: any): Promise<any> => {

// If the facilityId is not provided, it may be case of user not associated with any facility or the logout
if (!facilityId) {
return Promise.resolve({});
}

const baseURL = store.getters['user/getBaseUrl'];
try {
const data = {
"inputFields": {
"facilityId": facilityId,
},
"fieldList": ["defaultCurrencyUomId", "productStoreId"],
"entityName": "ProductStoreFacilityDetail",
"noConditionFind": "Y",
"filterByDate": 'Y',
"viewSize": 1
}
const resp = await client({
url: "performFind",
method: "post",
data,
baseURL,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
}
});
if (hasError(resp)) {
throw resp.data;
}

return Promise.resolve(resp.data.docs?.length ? resp.data.docs[0] : {});
} catch(error: any) {
console.error(error)
return Promise.resolve({})
}
}

const getProfile = async (): Promise <any> => {
return api({
url: "user-profile",
Expand All @@ -49,5 +90,6 @@ export const UserService = {
getAvailableTimeZones,
getProfile,
setUserTimeZone,
checkPermission
checkPermission,
getCurrentEComStore
}
1 change: 1 addition & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export default interface UserState {
currentFacility: object;
instanceUrl: string;
picklistItemSortBy: string;
currentEComStore: any;
}
30 changes: 24 additions & 6 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hasError, showToast } from '@/utils'
import { translate } from '@/i18n'
import { Settings } from 'luxon';
import { logout, updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import { useAuthStore } from '@hotwax/dxp-components'
import { useAuthStore, useProductIdentificationStore } from '@hotwax/dxp-components'
import emitter from '@/event-bus'
import router from '@/router';

Expand Down Expand Up @@ -36,7 +36,7 @@ const actions: ActionTree<UserState, RootState> = {
if (checkPermissionResponse.status === 200 && !hasError(checkPermissionResponse) && checkPermissionResponse.data && checkPermissionResponse.data.hasPermission) {
commit(types.USER_TOKEN_CHANGED, { newToken: token })
updateToken(token)
await dispatch('getProfile')
await dispatch('getProfile', token)
} else {
const permissionError = 'You do not have permission to access the app.';
showToast(translate(permissionError));
Expand All @@ -46,7 +46,7 @@ const actions: ActionTree<UserState, RootState> = {
} else {
commit(types.USER_TOKEN_CHANGED, { newToken: token })
updateToken(token)
await dispatch('getProfile')
await dispatch('getProfile', token)
}

// accessing picklist ID from router as route cannot be accessed here
Expand Down Expand Up @@ -115,14 +115,25 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Get User profile
*/
async getProfile ( { commit }) {
async getProfile ( { commit }, token) {
const resp = await UserService.getProfile()
if (resp.status === 200) {
if (resp.data.userTimeZone) {
Settings.defaultZone = resp.data.userTimeZone;
}
commit(types.USER_INFO_UPDATED, resp.data);
commit(types.USER_CURRENT_FACILITY_UPDATED, resp.data.facilities.length > 0 ? resp.data.facilities[0] : {});

const currentFacility = resp.data.facilities.length > 0 ? resp.data.facilities[0] : {};

commit(types.USER_CURRENT_FACILITY_UPDATED, currentFacility);

// get and set current ecom store in state
const currentEComStore = await UserService.getCurrentEComStore(token, currentFacility?.facilityId);
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore);

// Get product identification from api using dxp-component
await useProductIdentificationStore().getIdentificationPref(currentEComStore?.productStoreId)
.catch((error) => console.error(error));
}
},

Expand All @@ -141,8 +152,15 @@ const actions: ActionTree<UserState, RootState> = {
},

// update current facility information
async setFacility ({ commit }, payload) {
async setFacility ({ commit, state }, payload) {
commit(types.USER_CURRENT_FACILITY_UPDATED, payload.facility);

// get and set current ecom store in state
const currentEComStore = await UserService.getCurrentEComStore(state.token, payload.facility.facilityId);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore);

await useProductIdentificationStore().getIdentificationPref(currentEComStore?.productStoreId)
.catch((error) => console.error(error));
},

/**
Expand Down
10 changes: 9 additions & 1 deletion src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const getters: GetterTree <UserState, RootState> = {
getUserProfile (state) {
return state.current
},
getCurrentEComStore(state) {
return state.currentEComStore;
},
getCurrentFacility (state) {
return state.currentFacility;
},
Expand All @@ -24,6 +27,11 @@ const getters: GetterTree <UserState, RootState> = {
},
getPicklistItemSortBy (state) {
return state.picklistItemSortBy;
}
},
getBaseUrl(state) {
let baseURL = process.env.VUE_APP_BASE_URL;
if (!baseURL) baseURL = state.instanceUrl;
return baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`;
},
}
export default getters;
1 change: 1 addition & 0 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const userModule: Module<UserState, RootState> = {
state: {
token: '',
current: null,
currentEComStore: {},
currentFacility: {},
instanceUrl: '',
picklistItemSortBy: 'productName'
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED'
export const USER_CURRENT_FACILITY_UPDATED = SN_USER + '/CURRENT_FACILITY_UPDATED'
export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_SORTBY_UPDATED = SN_USER + '/SORTBY_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const mutations: MutationTree <UserState> = {
},
[types.USER_SORTBY_UPDATED] (state, payload) {
state.picklistItemSortBy = payload
},
[types.USER_CURRENT_ECOM_STORE_UPDATED] (state, payload) {
state.currentEComStore = payload
}
}
export default mutations;
2 changes: 2 additions & 0 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<p class="overline">{{ "Built: " + getDateTime(appInfo.builtTime) }}</p>
</div>
<section>
<ProductIdentifier />

<ion-card>
<ion-card-header>
<ion-card-title>
Expand Down
Loading