From aaa18515cc19d17a36d69f8c13905df12aa245e9 Mon Sep 17 00:00:00 2001 From: k2maan Date: Thu, 28 Sep 2023 12:43:28 +0530 Subject: [PATCH 1/7] Implemented: logic to update notification icon after viewing and added preference card on the settings page (#301) --- src/App.vue | 8 +- .../NotificationPreferenceModal.vue | 6 +- src/locales/en.json | 5 + src/locales/es.json | 5 + src/locales/ja.json | 5 + src/store/modules/user/UserState.ts | 1 + src/store/modules/user/actions.ts | 6 ++ src/store/modules/user/getters.ts | 3 + src/store/modules/user/index.ts | 3 +- src/store/modules/user/mutation-types.ts | 3 +- src/store/modules/user/mutations.ts | 3 + src/views/Orders.vue | 6 +- src/views/Settings.vue | 100 +++++++++++++++++- 13 files changed, 142 insertions(+), 12 deletions(-) diff --git a/src/App.vue b/src/App.vue index 3ae6932e4..d510f7992 100644 --- a/src/App.vue +++ b/src/App.vue @@ -55,7 +55,9 @@ export default defineComponent({ ...mapGetters({ locale: 'user/getLocale', userToken: 'user/getUserToken', - instanceUrl: 'user/getInstanceUrl' + instanceUrl: 'user/getInstanceUrl', + notifications: 'user/getNotifications', + notificationsCheckStatus: 'user/getNotificationsCheckStatus' }) }, created() { @@ -85,6 +87,10 @@ export default defineComponent({ emitter.on('presentLoader', this.presentLoader); emitter.on('dismissLoader', this.dismissLoader); this.$i18n.locale = this.locale; + // null check to only update the status once when the app mounts for the fist tine + if (this.notificationsCheckStatus === null) { + this.store.dispatch('user/setNotificationsCheckStatus', !this.notifications.length) + } }, unmounted() { emitter.off('presentLoader', this.presentLoader); diff --git a/src/components/NotificationPreferenceModal.vue b/src/components/NotificationPreferenceModal.vue index 5ee91f96f..f4b6fb42f 100644 --- a/src/components/NotificationPreferenceModal.vue +++ b/src/components/NotificationPreferenceModal.vue @@ -53,10 +53,7 @@ import { translate } from "@/i18n"; import { showToast } from "@/utils"; import emitter from "@/event-bus" import { generateTopicName } from "@/utils/firebase"; -import { - subscribeTopic, - unsubscribeTopic -} from '@/adapter'; +import { subscribeTopic, unsubscribeTopic } from '@/adapter' export default defineComponent({ name: "NotificationPreferenceModal", @@ -132,7 +129,6 @@ export default defineComponent({ this.notificationPrefState[enumId] = value }, async updateNotificationPref() { - // TODO disbale button if initial and final are same // added loader as the API call is in pending state for too long, blocking the flow emitter.emit("presentLoader"); try { diff --git a/src/locales/en.json b/src/locales/en.json index f22b82b84..6c46c7d54 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -4,6 +4,7 @@ "An email notification will be sent to that their order is ready for pickup. This order will also be moved to the packed orders tab.": "An email notification will be sent to { customerName } that their order is ready for pickup.{ space } This order will also be moved to the packed orders tab.", "An email notification will be sent to that their order is ready for pickup.": "An email notification will be sent to { customerName } that their order is ready for pickup.", "Are you sure you want to change the time zone to?": "Are you sure you want to change the time zone to?", + "Are you sure you want to update the notification preference?": "Are you sure you want to update the notification preference?", "Are you sure you want to update the notification preferences?": "Are you sure you want to update the notification preferences?", "Arrived": "Arrived", "Authenticating": "Authenticating", @@ -35,6 +36,7 @@ "Facility": "Facility", "Failed to load packing slip": "Failed to load packing slip", "Failed to update configuration": "Failed to update configuration", + "Failed to update notification preference. Please try again.": "Failed to update notification preference. Please try again.", "First name": "First name", "Generate packing slips": "Generate packing slips", "Go to OMS": "Go to OMS", @@ -70,6 +72,7 @@ "Notifications": "Notifications", "Notification Preference": "Notification Preference", "Notification preferences not found.": "Notification preferences not found.", + "Notification preference updated.": "Notification preference updated.", "Notification preferences updated.": "Notification preferences updated.", "Notification preferences not updated. Please try again.": "Notification preferences not updated. Please try again.", "Open": "Open", @@ -111,6 +114,7 @@ "Search time zones": "Search time zones", "Select facility": "Select facility", "Select time zone": "Select time zone", + "Select the notifications you want to receive.": "Select the notifications you want to receive.", "Select your preferred language.": "Select your preferred language.", "Settings": "Settings", "Select a picker": "Select a picker", @@ -152,6 +156,7 @@ "Warehouse": "Warehouse", "Worn Display": "Worn Display", "This order will be removed from your dashboard. This action cannot be undone.": "This order will be removed from your dashboard.{ space } This action cannot be undone.", + "Update notification preference": "Update notification preference", "Update notification preferences": "Update notification preferences", "View shipping orders along with pickup orders.": "View shipping orders along with pickup orders.", "You do not have permission to access this page": "You do not have permission to access this page", diff --git a/src/locales/es.json b/src/locales/es.json index c9cd6cc59..23d4ee243 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -4,6 +4,7 @@ "An email notification will be sent to that their order is ready for pickup. This order will also be moved to the packed orders tab.": "Se enviará una notificación por correo electrónico a {customerName} de que su pedido está listo para recoger.{ space } Este pedido también se moverá a la pestaña de pedidos empacados.", "An email notification will be sent to that their order is ready for pickup.": "Se enviará una notificación por correo electrónico a {customerName} de que su pedido está listo para recoger.", "Are you sure you want to change the time zone to?": "¿Estás seguro de que quieres cambiar la zona horaria a?", + "Are you sure you want to update the notification preference?": "Are you sure you want to update the notification preference?", "Are you sure you want to update the notification preferences?": "Are you sure you want to update the notification preferences?", "Arrived": "Llegó", "Authenticating": "Authenticating", @@ -35,6 +36,7 @@ "Facility": "Instalación", "Failed to load packing slip": "Error al cargar el documento de embalaje", "Failed to update configuration": "No se pudo actualizar la configuración", + "Failed to update notification preference. Please try again.": "Failed to update notification preference. Please try again.", "First name": "Nombre", "Generate packing slips": "Generar documentos de embalaje", "Go to OMS": "Ir a OMS", @@ -69,6 +71,7 @@ "Notifications": "Notifications", "Notification Preference": "Notification Preference", "Notification preferences not found.": "Notification preferences not found.", + "Notification preference updated.": "Notification preference updated.", "Notification preferences updated.": "Notification preferences updated.", "Notification preferences not updated. Please try again.": "Notification preferences not updated. Please try again.", "Open": "Abierto", @@ -110,6 +113,7 @@ "Search time zones": "Buscar zonas horarias", "Select facility": "Seleccionar instalación", "Select time zone": "Seleccionar zona horaria", + "Select the notifications you want to receive.": "Select the notifications you want to receive.", "Select your preferred language.": "Selecciona tu idioma preferido.", "Settings": "Configuraciones", "Select a picker": "Seleccionar un recolector", @@ -151,6 +155,7 @@ "Warehouse": "Almacén", "Worn Display": "Pantalla desgastada", "This order will be removed from your dashboard. This action cannot be undone.": "Este pedido será eliminado de tu panel de control.{ space } Esta acción no se puede deshacer.", + "Update notification preference": "Update notification preference", "Update notification preferences": "Update notification preferences", "View shipping orders along with pickup orders.": "Ver órdenes de envío junto con órdenes de recogida.", "You do not have permission to access this page": "No tienes permiso para acceder a esta página", diff --git a/src/locales/ja.json b/src/locales/ja.json index 8e81f072b..be4e7813c 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -4,6 +4,7 @@ "An email notification will be sent to that their order is ready for pickup. This order will also be moved to the packed orders tab.": "{ customerName }様宛に注文の受け取り準備が完了したことをお知らするメールが送信されます。{ space } この注文は「梱包済み注文」タブに移動されます.", "An email notification will be sent to that their order is ready for pickup.": "{ customerName }様宛に注文の受け取り準備が完了したことをお知らするメールが送信されます。", "Are you sure you want to change the time zone to?": "タイムゾーンを変更してもよろしいですか?", + "Are you sure you want to update the notification preference?": "Are you sure you want to update the notification preference?", "Are you sure you want to update the notification preferences?": "Are you sure you want to update the notification preferences?", "Arrived": "到着", "Authenticating": "Authenticating", @@ -35,6 +36,7 @@ "Facility": "拠点", "Failed to load packing slip": "納品書の読み込みに失敗しました", "Failed to update configuration": "設定の更新に失敗しました", + "Failed to update notification preference. Please try again.": "Failed to update notification preference. Please try again.", "First name": "名", "Generate packing slips": "内容明細票の作成", "Go to OMS": "OMSへ", @@ -69,6 +71,7 @@ "Notifications": "Notifications", "Notification Preference": "Notification Preference", "Notification preferences not found.": "Notification preferences not found.", + "Notification preference updated.": "Notification preference updated.", "Notification preferences updated.": "Notification preferences updated.", "Notification preferences not updated. Please try again.": "Notification preferences not updated. Please try again.", "Open": "オープン", @@ -110,6 +113,7 @@ "Search time zones": "タイムゾーンの検索", "Select facility": "拠点の検索", "Select time zone": "タイムゾーンを選択", + "Select the notifications you want to receive.": "Select the notifications you want to receive.", "Select your preferred language.": "お好みの言語の選択", "Settings": "設定", "Select a picker": "受取人の選択", @@ -151,6 +155,7 @@ "Warehouse": "倉庫", "Worn Display": "すり切れたディスプレイ", "This order will be removed from your dashboard. This action cannot be undone.": "この注文はダッシュボードから削除されます。{ space } この操作は元に戻せません。", + "Update notification preference": "Update notification preference", "Update notification preferences": "Update notification preferences", "View shipping orders along with pickup orders.": "店舗受取の注文と一緒に配送注文を表示します", "You do not have permission to access this page": "このページにアクセスする権限がありません", diff --git a/src/store/modules/user/UserState.ts b/src/store/modules/user/UserState.ts index 072f2ae6c..ac3b820d9 100644 --- a/src/store/modules/user/UserState.ts +++ b/src/store/modules/user/UserState.ts @@ -10,4 +10,5 @@ export default interface UserState { notifications: any; notificationPrefs: any; firebaseDeviceId: string; + notificationsCheckStatus: boolean | null } \ No newline at end of file diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 54a72c892..fcfe5504c 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -171,6 +171,7 @@ const actions: ActionTree = { addNotification({ state, commit }, payload) { const notifications = JSON.parse(JSON.stringify(state.notifications)) notifications.push({ ...payload.notification, time: DateTime.now().toMillis() }) + commit(types.USER_NOTIFICATIONS_CHECK_STATUS_UPDATED, false) if (payload.isForeground) { showToast(translate("New notification received.")); } @@ -218,6 +219,11 @@ const actions: ActionTree = { commit(types.USER_NOTIFICATIONS_UPDATED, []) commit(types.USER_NOTIFICATIONS_PREFERENCES_UPDATED, []) commit(types.USER_FIREBASE_DEVICEID_UPDATED, '') + commit(types.USER_NOTIFICATIONS_CHECK_STATUS_UPDATED, null) + }, + + setNotificationsCheckStatus({ commit }, payload) { + commit(types.USER_NOTIFICATIONS_CHECK_STATUS_UPDATED, payload) } } export default actions; \ No newline at end of file diff --git a/src/store/modules/user/getters.ts b/src/store/modules/user/getters.ts index 5f3d7f840..b4e5e7699 100644 --- a/src/store/modules/user/getters.ts +++ b/src/store/modules/user/getters.ts @@ -56,6 +56,9 @@ const getters: GetterTree = { }, getFirebaseDeviceId(state) { return state.firebaseDeviceId + }, + getNotificationsCheckStatus(state) { + return state.notificationsCheckStatus } } export default getters; \ No newline at end of file diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts index 30d3abdd3..d963849b3 100644 --- a/src/store/modules/user/index.ts +++ b/src/store/modules/user/index.ts @@ -22,7 +22,8 @@ const userModule: Module = { permissions: [], notifications: [], notificationPrefs: [], - firebaseDeviceId: '' + firebaseDeviceId: '', + notificationsCheckStatus: null }, getters, actions, diff --git a/src/store/modules/user/mutation-types.ts b/src/store/modules/user/mutation-types.ts index 9e4208bb4..25da52591 100644 --- a/src/store/modules/user/mutation-types.ts +++ b/src/store/modules/user/mutation-types.ts @@ -10,4 +10,5 @@ export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UP export const USER_PERMISSIONS_UPDATED = SN_USER + '/PERMISSIONS_UPDATED' export const USER_NOTIFICATIONS_UPDATED = SN_USER + '/NOTIFICATIONS_UPDATED' export const USER_NOTIFICATIONS_PREFERENCES_UPDATED = SN_USER + '/NOTIFICATIONS_PREFERENCES_UPDATED' -export const USER_FIREBASE_DEVICEID_UPDATED = SN_USER + '/FIREBASE_DEVICEID_UPDATED' \ No newline at end of file +export const USER_FIREBASE_DEVICEID_UPDATED = SN_USER + '/FIREBASE_DEVICEID_UPDATED' +export const USER_NOTIFICATIONS_CHECK_STATUS_UPDATED = SN_USER + '/NOTIFICATIONS_CHECK_STATUS_UPDATED' \ No newline at end of file diff --git a/src/store/modules/user/mutations.ts b/src/store/modules/user/mutations.ts index 8346bf33b..91532eaee 100644 --- a/src/store/modules/user/mutations.ts +++ b/src/store/modules/user/mutations.ts @@ -41,6 +41,9 @@ const mutations: MutationTree = { }, [types.USER_FIREBASE_DEVICEID_UPDATED] (state, payload) { state.firebaseDeviceId = payload + }, + [types.USER_NOTIFICATIONS_CHECK_STATUS_UPDATED] (state, payload) { + state.notificationsCheckStatus = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/Orders.vue b/src/views/Orders.vue index f326d0ef9..dc613f608 100644 --- a/src/views/Orders.vue +++ b/src/views/Orders.vue @@ -5,7 +5,7 @@ {{ currentFacility?.facilityName }} - + @@ -251,6 +251,7 @@ export default defineComponent({ isCompletedOrdersScrollable: 'order/isCompletedOrdersScrollable', showPackingSlip: 'user/showPackingSlip', notifications: 'user/getNotifications', + notificationsCheckStatus: 'user/getNotificationsCheckStatus' }) }, data() { @@ -446,6 +447,9 @@ export default defineComponent({ this.$router.push({ path: '/ship-to-store-orders' }) }, viewNotifications() { + if (!this.notificationsCheckStatus) { + this.store.dispatch('user/setNotificationsCheckStatus', true) + } this.$router.push({ path: '/notifications' }) } }, diff --git a/src/views/Settings.vue b/src/views/Settings.vue index cc08a219a..9e54cd75b 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -194,15 +194,60 @@ + + + + + {{ $t("Notification Preference") }} + + + + {{ $t('Select the notifications you want to receive.') }} + + + + {{ pref.description }} + + + +