Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
Browse files Browse the repository at this point in the history
…lities/#20
  • Loading branch information
amansinghbais committed Nov 21, 2023
2 parents ce5af3d + 57c9ac5 commit aa9bf61
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 288 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ VUE_APP_CACHE_MAX_AGE=3600
VUE_APP_VIEW_SIZE=10
VUE_APP_BASE_URL=
VUE_APP_PERMISSION_ID=
VUE_APP_ALIAS={}
VUE_APP_LOCALES={"en-US": "English"}
VUE_APP_DEFAULT_LOG_LEVEL="error"
VUE_APP_LOGIN_URL="http://launchpad.hotwax.io/login"
4 changes: 2 additions & 2 deletions .firebaserc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"hotwax-digital-commerce": {
"hosting": {
"dev": [
"dev-facilities"
"hotwax-facilities-dev"
],
"uat": [
"uat-facilities"
"hotwax-facilities-uat"
]
}
},
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
'on':
push:
branches:
- main
jobs:
call-workflow-in-another-repo:
uses: hotwax/dxp-components/.github/workflows/common-firebase-hosting-merge.yml@main
with:
config-path: .github/labeler.yml
secrets:
envPAT: ${{ secrets.envPAT }}
HOTWAX_PUBLIC_SECRET: ${{ secrets.HOTWAX_PUBLIC_SECRET }}
7 changes: 1 addition & 6 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"A store represents a company or a unique catalog of products. If your OMS is connected to multiple eCommerce stores selling different collections of products, you may have multiple Product Stores set up in HotWax Commerce.": "A store represents a company or a unique catalog of products. If your OMS is connected to multiple eCommerce stores selling different collections of products, you may have multiple Product Stores set up in HotWax Commerce.",
"Add": "Add",
"Add locations to facility": "Add locations to facility",
"Add staff member to facility": "Add staff member to facility",
Expand Down Expand Up @@ -39,8 +38,8 @@
"Facilities": "Facilities",
"Facility": "Facility",
"Facility address updated successfully.": "Facility address updated successfully.",
"Facility geoPoint updated successfully.": "Facility geoPoint updated successfully.",
"Facility details": "Facility details",
"Facility geoPoint updated successfully.": "Facility geoPoint updated successfully.",
"Facility ID": "Facility ID",
"Facility location created successfully": "Facility location created successfully",
"Facility location updated successfully": "Facility location updated successfully",
Expand Down Expand Up @@ -124,10 +123,8 @@
"Select": "Select",
"Search facilities": "Search facilities",
"Search time zones": "Search time zones",
"Select store": "Select store",
"Select time": "Select time",
"Select time zone": "Select time zone",
"Select facility": "Select facility",
"Select product stores": "Select product stores",
"Select your preferred language.": "Select your preferred language.",
"Sell Online": "Sell Online",
Expand All @@ -141,11 +138,9 @@
"Something went wrong": "Something went wrong",
"Something went wrong while login. Please contact administrator.": "Something went wrong while login. Please contact administrator.",
"Sorry, your username or password is incorrect. Please try again.": "Sorry, your username or password is incorrect. Please try again.",
"Specify which facility you want to operate from. Order, inventory and other configuration data will be specific to the facility you select.": "Specify which facility you want to operate from. Order, inventory and other configuration data will be specific to the facility you select.",
"Staff": "Staff",
"State": "State",
"store name": "store name",
"Store": "Store",
"Sunday": "Sunday",
"The timezone you select is used to ensure automations you schedule are always accurate to the time you select.": "The timezone you select is used to ensure automations you schedule are always accurate to the time you select.",
"These values are used to help customers lookup how close they are to your stores when they are finding nearby stores.": "These values are used to help customers lookup how close they are to your stores when they are finding nearby stores.",
Expand Down
81 changes: 5 additions & 76 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,6 @@ const setUserTimeZone = async (payload: any): Promise <any> => {
});
}

const getEComStores = async (token: any, facilityId: any): Promise<any> => {
try {
const params = {
"inputFields": {
"storeName_op": "not-empty",
facilityId
},
"fieldList": ["productStoreId", "storeName"],
"entityName": "ProductStoreFacilityDetail",
"distinct": "Y",
"noConditionFind": "Y",
"filterByDate": 'Y',
}
const baseURL = store.getters['user/getBaseUrl'];
const resp = await client({
url: "performFind",
method: "get",
baseURL,
params,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
}
});
if (hasError(resp)) {
return Promise.reject(resp.data);
} else {
return Promise.resolve(resp.data.docs);
}
} catch(error: any) {
return Promise.reject(error)
}
}

const getPreferredStore = async (token: any): Promise<any> => {
const baseURL = store.getters['user/getBaseUrl'];
try {
const resp = await client({
url: "service/getUserPreference",
//TODO Due to security reasons service model of OMS 1.0 does not support sending parameters in get request that's why we use post here
method: "post",
baseURL,
headers: {
Authorization: 'Bearer ' + token,
'Content-Type': 'application/json'
},
data: {
'userPrefTypeId': 'SELECTED_BRAND'
},
});
if (hasError(resp)) {
return Promise.reject(resp.data);
} else {
return Promise.resolve(resp.data.userPrefValue);
}
} catch (error: any) {
return Promise.reject(error)
}
}

const getUserPermissions = async (payload: any, token: any): Promise<any> => {
const baseURL = store.getters['user/getBaseUrl'];
let serverPermissions = [] as any;
Expand Down Expand Up @@ -196,21 +136,10 @@ const getUserProfile = async (token: any): Promise<any> => {
}
}

const setUserPreference = async (payload: any): Promise<any> => {
return api({
url: "service/setUserPreference",
method: "post",
data: payload
});
}

export const UserService = {
login,
getAvailableTimeZones,
getEComStores,
getUserProfile,
getPreferredStore,
setUserPreference,
setUserTimeZone,
getUserPermissions
login,
getAvailableTimeZones,
getUserProfile,
setUserTimeZone,
getUserPermissions
}
13 changes: 0 additions & 13 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@ export default interface UserState {
token: string;
current: object | null;
permissions: any;
currentFacility: object;
instanceUrl: string;
currentEComStore: object;
preference: {
printShippingLabel: boolean,
printPackingSlip: boolean
};
fieldMappings: object | null;
currentMapping: {
id: string;
mappingType: string;
name: string;
value: object;
};
pwaState: any;
}
75 changes: 1 addition & 74 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { UserService } from '@/services/UserService'
import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import store from '@/store';
import UserState from './UserState'
import * as types from './mutation-types'
import { showToast } from '@/utils'
import { Settings } from 'luxon'
import { hasError, logout, updateInstanceUrl, updateToken, resetConfig, getUserFacilities } from '@/adapter'
import { hasError, logout, updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import logger from '@/logger'
import { getServerPermissionsFromRules, prepareAppPermissions, resetPermissions, setPermissions } from '@/authorization'
import { translate, useAuthStore, useUserStore } from '@hotwax/dxp-components'
Expand Down Expand Up @@ -49,44 +48,6 @@ const actions: ActionTree<UserState, RootState> = {
}

const userProfile = await UserService.getUserProfile(token);

//fetching user facilities
const baseURL = store.getters['user/getBaseUrl'];

try {
const facilities = await getUserFacilities(token, baseURL, userProfile?.partyId, "");

// if (!facilities.length) throw 'Unable to login. User is not assocaited with any facility'

userProfile.facilities = facilities;
userProfile.facilities.reduce((uniqueFacilities: any, facility: any, index: number) => {
if (uniqueFacilities.includes(facility.facilityId)) userProfile.facilities.splice(index, 1);
else uniqueFacilities.push(facility.facilityId);
return uniqueFacilities
}, []);
const currentFacility = userProfile.facilities[0];
userProfile.stores = await UserService.getEComStores(token, currentFacility.facilityId);

// In Job Manager application, we have jobs which may not be associated with any product store
userProfile.stores.push({
productStoreId: "",
storeName: "None"
})
let preferredStore = userProfile.stores[0]

const preferredStoreId = await UserService.getPreferredStore(token);
if (preferredStoreId) {
const store = userProfile.stores.find((store: any) => store.productStoreId === preferredStoreId);
store && (preferredStore = store)
}
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, preferredStore);
commit(types.USER_CURRENT_FACILITY_UPDATED, currentFacility);
} catch(err) {
logger.error(err)
}
// Getting unique facilities

// TODO Use a separate API for getting facilities, this should handle user like admin accessing the app

/* ---- Guard clauses ends here --- */

Expand Down Expand Up @@ -160,25 +121,6 @@ const actions: ActionTree<UserState, RootState> = {
emitter.emit('dismissLoader')
return redirectionUrl;
},

/**
* update current facility information
*/
async setFacility ({ commit, state }, payload) {
const userProfile = JSON.parse(JSON.stringify(state.current as any));
userProfile.stores = await UserService.getEComStores(undefined, payload.facility.facilityId);

let preferredStore = userProfile.stores[0];
const preferredStoreId = await UserService.getPreferredStore(undefined);

if (preferredStoreId) {
const store = userProfile.stores.find((store: any) => store.productStoreId === preferredStoreId);
store && (preferredStore = store)
}
commit(types.USER_INFO_UPDATED, userProfile);
commit(types.USER_CURRENT_FACILITY_UPDATED, payload.facility);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, preferredStore);
},

/**
* Update user timeZone
Expand Down Expand Up @@ -207,21 +149,6 @@ const actions: ActionTree<UserState, RootState> = {
updateInstanceUrl(payload)
},

/**
* update current eComStore information
*/
async setEComStore({ commit }, payload) {
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, payload.eComStore);
await UserService.setUserPreference({
'userPrefTypeId': 'SELECTED_BRAND',
'userPrefValue': payload.eComStore.productStoreId
});
},

setUserPreference({ commit }, payload){
commit(types.USER_PREFERENCE_UPDATED, payload)
},

updatePwaState({commit}, payload) {
commit(types.USER_PWA_STATE_UPDATED, payload);
}
Expand Down
9 changes: 0 additions & 9 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const getters: GetterTree <UserState, RootState> = {
getUserProfile (state) {
return state.current
},
getCurrentFacility (state){
return state.currentFacility
},
getInstanceUrl (state) {
const baseUrl = process.env.VUE_APP_BASE_URL;
return baseUrl ? baseUrl : state.instanceUrl;
Expand All @@ -30,12 +27,6 @@ const getters: GetterTree <UserState, RootState> = {
if (!baseURL) baseURL = state.instanceUrl;
return baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`;
},
getCurrentEComStore(state) {
return state.currentEComStore
},
getUserPreference(state) {
return state.preference
},
getPwaState (state) {
return state.pwaState;
}
Expand Down
13 changes: 0 additions & 13 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@ const userModule: Module<UserState, RootState> = {
token: '',
permissions: [],
current: {},
currentFacility: {},
instanceUrl: '',
currentEComStore: {},
preference: {
printShippingLabel: false,
printPackingSlip: false
},
fieldMappings: {},
currentMapping: {
id: '',
mappingType: '',
name: '',
value: {}
},
pwaState: {
updateExists: false,
registration: null,
Expand Down
3 changes: 0 additions & 3 deletions src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ export const SN_USER = 'user'
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_CURRENT_FACILITY_UPDATED = SN_USER + '/CURRENT_FACILITY_UPDATED'
export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
export const USER_PREFERENCE_UPDATED = SN_USER + '/PREFERENCE_UPDATED'
export const USER_PERMISSIONS_UPDATED = SN_USER + '/PERMISSIONS_UPDATED'
export const USER_PWA_STATE_UPDATED = SN_USER + '/PWA_STATE_UPDATED'
11 changes: 0 additions & 11 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,14 @@ const mutations: MutationTree <UserState> = {
[types.USER_END_SESSION] (state) {
state.token = ''
state.current = {},
state.currentFacility = {}
state.currentEComStore = {}
state.permissions = []
},
[types.USER_INFO_UPDATED] (state, payload) {
state.current = { ...state.current, ...payload}
},
[types.USER_CURRENT_FACILITY_UPDATED] (state, payload) {
state.currentFacility = payload;
},
[types.USER_INSTANCE_URL_UPDATED] (state, payload) {
state.instanceUrl = payload;
},
[types.USER_CURRENT_ECOM_STORE_UPDATED](state, payload) {
state.currentEComStore = payload;
},
[types.USER_PREFERENCE_UPDATED] (state, payload) {
state.preference = {...state.preference, ...payload};
},
[types.USER_PERMISSIONS_UPDATED] (state, payload) {
state.permissions = payload
},
Expand Down
Loading

0 comments on commit aa9bf61

Please sign in to comment.