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: support for oms package and updated the code as per the response(#2rby5m5) #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
82 changes: 68 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@capacitor/android": "^2.4.7",
"@capacitor/core": "^2.4.7",
"@hotwax/oms-api": "0.0.1",
"@ionic/vue": "^5.4.0",
"@ionic/vue-router": "^5.4.0",
"@types/file-saver": "^2.0.4",
Expand Down
14 changes: 13 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import { IonApp, IonRouterOutlet } from '@ionic/vue';
import { defineComponent } from 'vue';
import { loadingController, alertController } from '@ionic/vue';
import { useStore } from "./store";
import emitter from "@/event-bus"
import { mapGetters, useStore } from 'vuex';
import { updateInstanceUrl, updateToken } from '@hotwax/oms-api';

export default defineComponent({
name: 'App',
components: {
Expand Down Expand Up @@ -49,16 +51,26 @@ export default defineComponent({
});
emitter.on('presentLoader', this.presentLoader);
emitter.on('dismissLoader', this.dismissLoader);
updateToken(this.userToken)
updateInstanceUrl(this.instanceUrl)
},
unmounted() {
emitter.off('presentLoader', this.presentLoader);
emitter.off('dismissLoader', this.dismissLoader);
updateToken('')
updateInstanceUrl('')
},
setup(){
const store = useStore();
return {
store,
}
},
computed: {
...mapGetters({
userToken: 'user/getUserToken',
instanceUrl: 'user/getInstanceUrl'
})
}
});
</script>
6 changes: 4 additions & 2 deletions src/components/ProductListItem.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<ion-item button @click="viewProduct()" detail="true" lines="none">
<ion-thumbnail slot="start">
<img :src="product.mainImageUrl" />
<img :src="product.images?.mainImageUrl" />
</ion-thumbnail>
<ion-label>
<p>{{ product.productName }}</p>
<h3>{{ product.sku }}</h3>
<p>{{$filters.getFeature(product.featureHierarchy, '1/COLOR/')}} | {{$filters.getFeature(product.featureHierarchy, '1/SIZE/')}}</p>
<p>{{ getFeature(product.features, 'Color')}} | {{ getFeature(product.features, 'Size') }}</p>
</ion-label>
</ion-item>
</template>
Expand All @@ -20,6 +20,7 @@ import {
} from '@ionic/vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex';
import { getFeature } from '@/utils';

export default defineComponent({
name: "ProductListItem",
Expand All @@ -41,6 +42,7 @@ export default defineComponent({
const store = useStore();

return {
getFeature,
router,
store
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import './theme/variables.css';
import i18n from './i18n'
import store from './store'
import { DateTime } from 'luxon';
import { init } from '@hotwax/oms-api';

const app = createApp(App)
.use(IonicVue, {
Expand Down Expand Up @@ -62,6 +63,7 @@ app.config.globalProperties.$filters = {
}
}

init(store.getters['user/getUserToken'], store.getters['user/getInstanceUrl'], 3000)

router.isReady().then(() => {
app.mount('#app');
Expand Down
15 changes: 8 additions & 7 deletions src/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ProductService } from "@/services/ProductService";
import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import ProductState from './ProductState'
import * as types from './mutation-types'
import { hasError, showToast } from '@/utils'
import { showToast } from '@/utils'
import { translate } from '@/i18n'
import emitter from '@/event-bus'
import { fetchProducts, isError } from "@hotwax/oms-api";


const actions: ActionTree<ProductState, RootState> = {
Expand All @@ -19,17 +19,18 @@ const actions: ActionTree<ProductState, RootState> = {
let resp;

try {
resp = await ProductService.fetchProducts({
resp = await fetchProducts({
// used sku as we are currently only using sku to search for the product
"filters": ['sku: ' + payload.queryString],
"queryString": payload.queryString,
"queryFields": "sku",
"viewSize": payload.viewSize,
"viewIndex": payload.viewIndex
})

// resp.data.response.numFound tells the number of items in the response
if (resp.status === 200 && resp.data.response.numFound > 0 && !hasError(resp)) {
let products = resp.data.response.docs;
const totalProductsCount = resp.data.response.numFound;
if (!isError(resp) && resp.total > 0) {
let products = resp.products;
const totalProductsCount = resp.total;

if (payload.viewIndex && payload.viewIndex > 0) products = state.products.list.concat(products)
commit(types.PRODUCT_SEARCH_UPDATED, { products: products, totalProductsCount: totalProductsCount })
Expand Down
8 changes: 6 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { hasError, showToast } from '@/utils'
import { translate } from '@/i18n'
import emitter from '@/event-bus'
import { DateTime } from 'luxon';
import { updateInstanceUrl, updateToken } from '@hotwax/oms-api'

const actions: ActionTree<UserState, RootState> = {

Expand All @@ -32,6 +33,7 @@ const actions: ActionTree<UserState, RootState> = {

if (checkPermissionResponse.status === 200 && !hasError(checkPermissionResponse) && checkPermissionResponse.data && checkPermissionResponse.data.hasPermission) {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
updateToken(resp.data.token)
dispatch('getProfile')
if (resp.data._EVENT_MESSAGE_ && resp.data._EVENT_MESSAGE_.startsWith("Alert:")) {
// TODO Internationalise text
Expand Down Expand Up @@ -73,7 +75,8 @@ const actions: ActionTree<UserState, RootState> = {
async logout ({ commit }) {
// TODO add any other tasks if need
commit(types.USER_END_SESSION)

updateToken('')
updateInstanceUrl('')
},

/**
Expand Down Expand Up @@ -109,8 +112,9 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Set User Instance Url
*/
setUserInstanceUrl ({ state, commit }, payload){
setUserInstanceUrl ({ commit }, payload){
commit(types.USER_INSTANCE_URL_UPDATED, payload)
updateInstanceUrl(payload)
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ const showToast = async (message: string) => {
return toast.present();
}

const getFeature = (features: any, key: string) => {
let featureValue = ''
if (features) {
featureValue = features.find((feature: any) => feature.desc === key)?.value
}
// returning 0th index as the featureValue is an array
return featureValue ? featureValue[0] : '';
}

// Utility for parsing CSV file
// Package Used : PapaParse (Link to Documentation : https://www.papaparse.com/docs#config)

Expand Down Expand Up @@ -117,4 +126,4 @@ const jsonToCsv = (file: any, options: JsonToCsvOption = {}) => {
return blob;
}

export { showToast, hasError , parseCsv , jsonToCsv, JsonToCsvOption }
export { showToast, hasError, getFeature, parseCsv , jsonToCsv, JsonToCsvOption }