diff --git a/src/services/ProductService.ts b/src/services/ProductService.ts deleted file mode 100644 index 48848dd..0000000 --- a/src/services/ProductService.ts +++ /dev/null @@ -1,15 +0,0 @@ -import api from '@/api'; - -const fetchProducts = async (query: any): Promise => { - return api({ - // TODO: We can replace this with any API - url: "searchProducts", - method: "post", - data: query, - cache: true - }); -} - -export const ProductService = { - fetchProducts -} \ No newline at end of file diff --git a/src/store/RootState.ts b/src/store/RootState.ts index 0bfb2f2..d3f55f7 100644 --- a/src/store/RootState.ts +++ b/src/store/RootState.ts @@ -1,4 +1,3 @@ export default interface RootState { user: any; - product: any; } \ No newline at end of file diff --git a/src/store/index.ts b/src/store/index.ts index 32c2373..4ffaec5 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -5,7 +5,6 @@ import actions from './actions' import RootState from './RootState' import createPersistedState from "vuex-persistedstate"; import userModule from './modules/user'; -import productModule from "./modules/product"; @@ -32,8 +31,7 @@ const store = createStore({ getters, plugins: [ persistState ], modules: { - 'user': userModule, - 'product': productModule + 'user': userModule }, }) diff --git a/src/store/modules/product/ProductState.ts b/src/store/modules/product/ProductState.ts deleted file mode 100644 index 7719736..0000000 --- a/src/store/modules/product/ProductState.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default interface ProductState { - products: { - list: any; - total: number; - } -} \ No newline at end of file diff --git a/src/store/modules/product/actions.ts b/src/store/modules/product/actions.ts deleted file mode 100644 index 42c3114..0000000 --- a/src/store/modules/product/actions.ts +++ /dev/null @@ -1,51 +0,0 @@ -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 { translate } from '@/i18n' -import emitter from '@/event-bus' - - -const actions: ActionTree = { - - // Find Product - async findProduct ({ commit, state }, payload) { - - // Show loader only when new query and not the infinite scroll - if (payload.viewIndex === 0) emitter.emit("presentLoader"); - - let resp; - - try { - resp = await ProductService.fetchProducts({ - // used sku as we are currently only using sku to search for the product - "filters": ['sku: ' + payload.queryString], - "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 (payload.viewIndex && payload.viewIndex > 0) products = state.products.list.concat(products) - commit(types.PRODUCT_SEARCH_UPDATED, { products: products, totalProductsCount: totalProductsCount }) - } else { - //showing error whenever getting no products in the response or having any other error - showToast(translate("Product not found")); - } - // Remove added loader only when new query and not the infinite scroll - if (payload.viewIndex === 0) emitter.emit("dismissLoader"); - } catch(error){ - console.error(error) - showToast(translate("Something went wrong")); - } - // TODO Handle specific error - return resp; - }, -} - -export default actions; \ No newline at end of file diff --git a/src/store/modules/product/getters.ts b/src/store/modules/product/getters.ts deleted file mode 100644 index 94a9e5b..0000000 --- a/src/store/modules/product/getters.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { GetterTree } from "vuex"; -import ProductState from "./ProductState"; -import RootState from "../../RootState"; - -const getters: GetterTree = { - getSearchProducts(state) { - return state.products.list; - }, - isScrollable(state) { - return ( - state.products.list.length > 0 && - state.products.list.length < state.products.total - ); - }, -}; -export default getters; \ No newline at end of file diff --git a/src/store/modules/product/index.ts b/src/store/modules/product/index.ts deleted file mode 100644 index a328a6c..0000000 --- a/src/store/modules/product/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -import actions from './actions' -import getters from './getters' -import mutations from './mutations' -import { Module } from 'vuex' -import ProductState from './ProductState' -import RootState from '../../RootState' - -const productModule: Module = { - namespaced: true, - state: { - products: { - list: {}, - total: 0 - } - }, - getters, - actions, - mutations, -} - -export default productModule; \ No newline at end of file diff --git a/src/store/modules/product/mutation-types.ts b/src/store/modules/product/mutation-types.ts deleted file mode 100644 index 7f3cc39..0000000 --- a/src/store/modules/product/mutation-types.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const SN_PRODUCT = 'product' -export const PRODUCT_SEARCH_UPDATED = SN_PRODUCT + '/SEARCH_UPDATED' diff --git a/src/store/modules/product/mutations.ts b/src/store/modules/product/mutations.ts deleted file mode 100644 index a5f80ab..0000000 --- a/src/store/modules/product/mutations.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { MutationTree } from 'vuex' -import ProductState from './ProductState' -import * as types from './mutation-types' - -const mutations: MutationTree = { - [types.PRODUCT_SEARCH_UPDATED] (state, payload) { - state.products.list = payload.products; - state.products.total = payload.totalProductsCount; - } -} -export default mutations; \ No newline at end of file