diff --git a/src/modules/timesheet-approval/models/pay-period-event.models.ts b/src/modules/timesheet-approval/models/pay-period-event.models.ts index 80e03cd..17f61ab 100644 --- a/src/modules/timesheet-approval/models/pay-period-event.models.ts +++ b/src/modules/timesheet-approval/models/pay-period-event.models.ts @@ -2,4 +2,5 @@ export interface PayPeriodEvent { employee_email: string; event_type: 'shift' | 'expense' | 'preset'; action: 'create' | 'update' | 'delete'; + date: string; } \ No newline at end of file diff --git a/src/stores/timesheet-store.ts b/src/stores/timesheet-store.ts index f6f1841..d9914d9 100644 --- a/src/stores/timesheet-store.ts +++ b/src/stores/timesheet-store.ts @@ -1,3 +1,5 @@ +import { Notify, date } from 'quasar'; +import { useI18n } from 'vue-i18n'; import { computed, ref } from 'vue'; import { defineStore } from 'pinia'; import { unwrapAndClone } from 'src/utils/unwrap-and-clone'; @@ -9,8 +11,6 @@ import type { Timesheet } from 'src/modules/timesheets/models/timesheet.models'; import type { PayPeriodEvent } from 'src/modules/timesheet-approval/models/pay-period-event.models'; import type { TimesheetApprovalCSVReportFilters } from 'src/modules/timesheet-approval/models/timesheet-approval-csv-report.models'; import { type FederalHoliday, TARGO_HOLIDAY_NAMES_FR } from 'src/modules/timesheets/models/federal-holidays.models'; -import { Notify } from 'quasar'; -import { useI18n } from 'vue-i18n'; export const useTimesheetStore = defineStore('timesheet', () => { @@ -139,13 +139,6 @@ export const useTimesheetStore = defineStore('timesheet', () => { try { const timesheet_ids = timesheets.value.map(timesheet => timesheet.timesheet_id); - // Backend returns the amount of shifts and expenses successfully updated, could be useful for error handling??? - // const shift_expense_count = timesheets.value.reduce((timesheets_sum, timesheet) => { - // return timesheets_sum + timesheet.days.reduce((day_sum, day) => { - // return day_sum + day.shifts.length + day.expenses.length - // }, 0); - // }, 0); - const response = await timesheetApprovalService.updateTimesheetsApprovalStatus(email, timesheet_ids, approval_status); return response.success; } catch (error) { @@ -185,19 +178,24 @@ export const useTimesheetStore = defineStore('timesheet', () => { if (pay_period_observer.value === undefined) { pay_period_observer.value = timesheetApprovalService.subscribeToPayPeriodObservable(); pay_period_observer.value.onmessage = async (event: MessageEvent) => { - // find employee that modified their timesheets const pay_period_event: PayPeriodEvent = JSON.parse(event.data); + + // abort notification if event date is not within pay period being currently viewed + const eventDate = date.extractDate(pay_period_event.date, 'YYYY-MM-DD'); + const startDate = date.extractDate(pay_period.value!.period_start, 'YYYY-MM-DD'); + const endDate = date.extractDate(pay_period.value!.period_end, 'YYYY-MM-DD'); + + if (!date.isBetweenDates(eventDate, startDate, endDate, { inclusiveFrom: true, inclusiveTo: true, onlyDate: true })) + return; + const overview = pay_period_overviews.value.find(overview => overview.email === pay_period_event.employee_email); const employee_name = overview?.employee_first_name + ' ' + overview?.employee_last_name; - // update overviews await getTimesheetOverviews(); - // if user is looking at details of employee that generated event, update if (selected_employee_name.value === employee_name) await getTimesheetsByOptionalEmployeeEmail(pay_period_event.employee_email); - // create visual feedback of notification and update Notify.create({ message: `${employee_name} ${t('timesheet_approvals.event.' + pay_period_event.action)} ${t('timesheet_approvals.event.' + pay_period_event.event_type)}`, color: 'warning',