Skip to content

Commit

Permalink
Changed swap shift to take timezone into consideration (#4849)
Browse files Browse the repository at this point in the history
# What this PR does

- Pass the utcOffset to the `datetime` pickers used in Swap Shift form
- Any subsequent change to the global utcOffset displayed on top will
now trigger a change in the datetime pickers as well

## Which issue(s) this PR closes

#4688

Closes #4688
  • Loading branch information
teodosii authored Aug 20, 2024
1 parent 8241042 commit 3d4e876
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion grafana-plugin/src/containers/RotationForm/ShiftSwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const ShiftSwapForm = (props: ShiftSwapFormProps) => {
const {
scheduleStore,
userStore: { currentUserPk },
timezoneStore: { selectedTimezoneOffset },
} = store;

useEffect(() => {
Expand Down Expand Up @@ -87,7 +88,7 @@ export const ShiftSwapForm = (props: ShiftSwapFormProps) => {
...shiftSwap,
});
}
}, [shiftSwap, store.timezoneStore.calendarStartDate, store.timezoneStore.selectedTimezoneOffset]);
}, [shiftSwap, store.timezoneStore.calendarStartDate, selectedTimezoneOffset]);

const handleDescriptionChange = useCallback(
(event) => {
Expand Down Expand Up @@ -171,13 +172,15 @@ export const ShiftSwapForm = (props: ShiftSwapFormProps) => {
<Field label="Swap start">
<DateTimePicker
disabled={!isNew}
utcOffset={selectedTimezoneOffset}
value={dayjs(shiftSwap.swap_start)}
onChange={handleShiftSwapStartChange}
/>
</Field>
<Field label="Swap end">
<DateTimePicker
disabled={!isNew}
utcOffset={selectedTimezoneOffset}
value={dayjs(shiftSwap.swap_end)}
onChange={handleShiftSwapEndChange}
/>
Expand Down
16 changes: 12 additions & 4 deletions grafana-plugin/src/pages/schedule/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ import { isUserActionAllowed, UserActions } from 'utils/authorization/authorizat
import { PLUGIN_ROOT } from 'utils/consts';
import { PropsWithRouter, withRouter } from 'utils/hoc';

import { getCalendarStartDate, getNewCalendarStartDate, getUTCString } from './Schedule.helpers';
import {
getCalendarStartDate,
getNewCalendarStartDate,
getUTCString,
toDateWithTimezoneOffset,
} from './Schedule.helpers';
import { getScheduleStyles } from './Schedule.styles';

interface RouteProps {
Expand Down Expand Up @@ -647,7 +652,7 @@ class _SchedulePage extends React.Component<SchedulePageProps, SchedulePageState
store,
store: {
userStore: { currentUserPk },
timezoneStore: { currentDateInSelectedTimezone },
timezoneStore: { currentDateInSelectedTimezone, selectedTimezoneOffset },
},
router: {
params: { id: scheduleId },
Expand All @@ -671,11 +676,14 @@ class _SchedulePage extends React.Component<SchedulePageProps, SchedulePageState

const layers = getLayersFromStore(store, scheduleId, store.timezoneStore.calendarStartDate);
const closestEvent = findClosestUserEvent(dayjs(), currentUserPk, layers);

const swapStart = closestEvent
? dayjs(closestEvent.start)
? toDateWithTimezoneOffset(dayjs(closestEvent.start), selectedTimezoneOffset)
: currentDateInSelectedTimezone.startOf('day').add(1, 'day');

const swapEnd = closestEvent ? dayjs(closestEvent.end) : swapStart.add(1, 'day');
const swapEnd = closestEvent
? toDateWithTimezoneOffset(dayjs(closestEvent.end), selectedTimezoneOffset)
: swapStart.add(1, 'day');

const params = {
swap_start: getUTCString(swapStart),
Expand Down

0 comments on commit 3d4e876

Please sign in to comment.