From dc8d870a440921931aaaadeadd75868c28d1a189 Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Tue, 4 Jun 2024 14:00:11 +0300 Subject: [PATCH] show correct swap request dates --- .../src/pages/schedule/Schedule.tsx | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/grafana-plugin/src/pages/schedule/Schedule.tsx b/grafana-plugin/src/pages/schedule/Schedule.tsx index 703627adc7..6af87a4d6e 100644 --- a/grafana-plugin/src/pages/schedule/Schedule.tsx +++ b/grafana-plugin/src/pages/schedule/Schedule.tsx @@ -38,7 +38,16 @@ import { UserTimezoneSelect } from 'containers/UserTimezoneSelect/UserTimezoneSe import { UsersTimezones } from 'containers/UsersTimezones/UsersTimezones'; import { WithPermissionControlTooltip } from 'containers/WithPermissionControl/WithPermissionControlTooltip'; import { getLayersFromStore, getTotalDaysToDisplay } from 'models/schedule/schedule.helpers'; -import { Event, Layer, Schedule, ScheduleType, ScheduleView, Shift, ShiftSwap } from 'models/schedule/schedule.types'; +import { + Event, + Layer, + Schedule, + ScheduleEvent, + ScheduleType, + ScheduleView, + Shift, + ShiftSwap, +} from 'models/schedule/schedule.types'; import { UserHelper } from 'models/user/user.helpers'; import { PageProps, WithStoreProps } from 'state/types'; import { withMobXProviderContext } from 'state/withStore'; @@ -598,23 +607,35 @@ class _SchedulePage extends React.Component { + handleShowShiftSwapForm = (id: ShiftSwap['id'] | 'new', swap?: { swap_start: string; swap_end: string }) => { + const { filters } = this.state; const { store, + store: { + userStore: { currentUserPk }, + timezoneStore: { currentDateInSelectedTimezone }, + }, match: { params: { id: scheduleId }, }, } = this.props; - const { - userStore: { currentUserPk }, - timezoneStore: { currentDateInSelectedTimezone }, - } = store; - - const layers = getLayersFromStore(store, scheduleId, store.timezoneStore.calendarStartDate); + if (swap) { + if (!filters.users.includes(currentUserPk)) { + this.setState({ filters: { ...filters, users: [...this.state.filters.users, currentUserPk] } }); + this.highlightMyShiftsWasToggled = true; + } - const { filters } = this.state; + return this.setState({ + shiftSwapIdToShowForm: id, + shiftSwapParamsToShowForm: { + swap_start: swap.swap_start, + swap_end: swap.swap_end, + }, + }); + } + const layers = getLayersFromStore(store, scheduleId, store.timezoneStore.calendarStartDate); const closestEvent = findClosestUserEvent(dayjs(), currentUserPk, layers); const swapStart = closestEvent ? dayjs(closestEvent.start)