Skip to content

Commit

Permalink
Implemented: locale update through user profile (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
k2maan committed Oct 9, 2023
1 parent dcba8a4 commit e5092d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default defineComponent({
const userStore = useUserStore()
// to access baseUrl as we store only OMS in DXP
const appState = appContext.config.globalProperties.$store
await userStore.getPreference(token, appState.getters['user/getBaseUrl'])
userStore.setLocale(appState.getters['user/getUserProfile'].userLocale)

// check if firebase configurations are there
if (notificationContext.appFirebaseConfig) {
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export let dxpComponents = {

shopifyImgContext.defaultImgUrl = options.defaultImgUrl

userContext.getUserPreference = options.getUserPreference
userContext.setUserPreference = options.setUserPreference
userContext.setUserLocale = options.setUserLocale

productIdentificationContext.getProductIdentificationPref = options.getProductIdentificationPref
productIdentificationContext.setProductIdentificationPref = options.setProductIdentificationPref
Expand Down
20 changes: 5 additions & 15 deletions src/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ export const useUserStore = defineStore('user', {
state: () => {
return {
localeOptions: process.env.VUE_APP_LOCALES ? JSON.parse(process.env.VUE_APP_LOCALES) : { "en": "English" },
preference: {
locale: 'en'
} as any
locale: 'en'
}
},
getters: {
getLocale: (state) => state.preference.locale,
getLocale: (state) => state.locale,
getLocaleOptions: (state) => state.localeOptions
},
actions: {
Expand All @@ -23,18 +21,10 @@ export const useUserStore = defineStore('user', {
this.setPreference({ locale: payload })
},
async setPreference(payload: any) {
this.preference = { ...this.preference, ...payload }
await userContext.setUserPreference({
'userPrefTypeId': 'LOCALE_PREFERENCE',
'userPrefValue': JSON.stringify(this.preference)
this.locale = payload
await userContext.setUserLocale({
"newLocale": payload
})
},
async getPreference(token: any, baseURL: string) {
try {
this.preference = await userContext.getUserPreference(token, baseURL, 'LOCALE_PREFERENCE')
} catch (error) {
console.error(error)
}
}
},
persist: true
Expand Down

0 comments on commit e5092d2

Please sign in to comment.