From f3091f971462724feb599f73e785cbaaabd28518 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 11 Jan 2024 12:55:34 +0530 Subject: [PATCH 1/2] Removed: product module and related service as unused --- src/services/ProductService.ts | 15 ------ src/store/RootState.ts | 1 - src/store/index.ts | 4 +- src/store/modules/product/ProductState.ts | 6 --- src/store/modules/product/actions.ts | 51 --------------------- src/store/modules/product/getters.ts | 16 ------- src/store/modules/product/index.ts | 21 --------- src/store/modules/product/mutation-types.ts | 2 - src/store/modules/product/mutations.ts | 11 ----- 9 files changed, 1 insertion(+), 126 deletions(-) delete mode 100644 src/services/ProductService.ts delete mode 100644 src/store/modules/product/ProductState.ts delete mode 100644 src/store/modules/product/actions.ts delete mode 100644 src/store/modules/product/getters.ts delete mode 100644 src/store/modules/product/index.ts delete mode 100644 src/store/modules/product/mutation-types.ts delete mode 100644 src/store/modules/product/mutations.ts 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 From fd71bdc6b53b59bc0de6ea63b3be2458aca41ba4 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 11 Jan 2024 16:44:04 +0530 Subject: [PATCH 2/2] Improved: code formatting --- src/App.vue | 12 +++--- src/api/index.ts | 26 ++++++------ src/components/AddActionModal.vue | 6 +-- src/components/Image.vue | 10 ++--- src/components/Logo.vue | 2 +- src/components/RouteMenu.vue | 38 ++++++++--------- src/components/RuleConfiguration.vue | 14 +++--- src/components/RulePopover.vue | 8 ++-- src/event-bus/index.ts | 2 +- src/i18n.ts | 10 ++--- src/main.ts | 54 ++++++++++++------------ src/offline-helper/index.ts | 10 ++--- src/router/index.ts | 44 +++++++++---------- src/services/UserService.ts | 12 +++--- src/store/actions.ts | 4 +- src/store/getters.ts | 4 +- src/store/index.ts | 24 ++++------- src/store/modules/user/actions.ts | 32 +++++++------- src/store/modules/user/getters.ts | 6 +-- src/store/modules/user/index.ts | 18 ++++---- src/store/modules/user/mutation-types.ts | 12 +++--- src/store/modules/user/mutations.ts | 8 ++-- src/store/mutations.ts | 4 +- src/utils/index.ts | 24 +++++------ src/views/BrokeringQuery.vue | 28 ++++++------ src/views/BrokeringRoute.vue | 18 ++++---- src/views/Login.vue | 12 +++--- src/views/Settings.vue | 32 +++++++------- src/views/TimezoneModal.vue | 12 +++--- 29 files changed, 239 insertions(+), 247 deletions(-) diff --git a/src/App.vue b/src/App.vue index 4a4eb17..10578da 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,8 +5,8 @@ \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts index e51e71d..ded8246 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,16 +1,16 @@ -import axios from 'axios'; -import { setupCache } from 'axios-cache-adapter' -import OfflineHelper from '@/offline-helper' +import axios from "axios"; +import { setupCache } from "axios-cache-adapter" +import OfflineHelper from "@/offline-helper" import emitter from "@/event-bus" -import store from '@/store'; -import { StatusCodes } from 'http-status-codes'; -import router from '@/router' +import store from "@/store"; +import { StatusCodes } from "http-status-codes"; +import router from "@/router" axios.interceptors.request.use((config: any) => { - const token = store.getters['user/getUserToken']; + const token = store.getters["user/getUserToken"]; if (token) { - config.headers.Authorization = 'Bearer ' + token; - config.headers['Content-Type'] = 'application/json'; + config.headers.Authorization = "Bearer " + token; + config.headers["Content-Type"] = "application/json"; } return config; }); @@ -30,7 +30,7 @@ axios.interceptors.response.use(function (response) { const { status } = error.response; if (status === StatusCodes.UNAUTHORIZED) { store.dispatch("user/logout"); - router.push('/login') + router.push("/login") } } // Any status codes that falls outside the range of 2xx cause this function to trigger @@ -48,8 +48,8 @@ const axiosCache = setupCache({ * Generic method to call APIs * * @param {string} url - API Url - * @param {string=} method - 'GET', 'PUT', 'POST', 'DELETE , and 'PATCH' - * @param {any} [data] - Optional: `data` is the data to be sent as the request body. Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH' + * @param {string=} method - "GET", "PUT", "POST", "DELETE , and "PATCH" + * @param {any} [data] - Optional: `data` is the data to be sent as the request body. Only applicable for request methods "PUT", "POST", "DELETE , and "PATCH" * When no `transformRequest` is set, must be of one of the following types: * - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams * - Browser only: FormData, File, Blob @@ -68,7 +68,7 @@ const api = async (customConfig: any) => { params: customConfig.params } - const baseURL = store.getters['user/getInstanceUrl']; + const baseURL = store.getters["user/getInstanceUrl"]; if (baseURL) config.baseURL = `https://${baseURL}.hotwax.io/api/`; if(customConfig.cache) config.adapter = axiosCache.adapter; const networkStatus = await OfflineHelper.getNetworkStatus(); diff --git a/src/components/AddActionModal.vue b/src/components/AddActionModal.vue index af4cc0e..f61796e 100644 --- a/src/components/AddActionModal.vue +++ b/src/components/AddActionModal.vue @@ -44,9 +44,9 @@ import { IonTitle, IonToolbar, modalController, -} from '@ionic/vue'; -import { defineComponent } from 'vue'; -import { closeOutline } from 'ionicons/icons'; +} from "@ionic/vue"; +import { defineComponent } from "vue"; +import { closeOutline } from "ionicons/icons"; import { useStore } from "@/store"; export default defineComponent({ diff --git a/src/components/Image.vue b/src/components/Image.vue index 9d7c998..5c52bab 100644 --- a/src/components/Image.vue +++ b/src/components/Image.vue @@ -9,7 +9,7 @@ import { IonSkeletonText } from '@ionic/vue' export default defineComponent({ name: "Image", - props: ['src'], + props: ["src"], components: { IonSkeletonText }, @@ -26,8 +26,8 @@ export default defineComponent({ }, data() { return { - resourceUrl: '', - imageUrl: '' + resourceUrl: "", + imageUrl: "" } }, methods: { @@ -45,10 +45,10 @@ export default defineComponent({ }, setImageUrl() { if (this.src) { - if (this.src.indexOf('assets/') != -1) { + if (this.src.indexOf("assets/") != -1) { // Assign directly in case of assets this.imageUrl = this.src; - } else if (this.src.startsWith('http')) { + } else if (this.src.startsWith("http")) { // If starts with http, it is web url check for existence and assign this.checkIfImageExists(this.src).then(() => { this.imageUrl = this.src; diff --git a/src/components/Logo.vue b/src/components/Logo.vue index 2a2b29b..a6a2834 100644 --- a/src/components/Logo.vue +++ b/src/components/Logo.vue @@ -6,7 +6,7 @@ diff --git a/src/components/RuleConfiguration.vue b/src/components/RuleConfiguration.vue index 9cf93f1..9b75c55 100644 --- a/src/components/RuleConfiguration.vue +++ b/src/components/RuleConfiguration.vue @@ -70,16 +70,16 @@