Skip to content

Commit

Permalink
show correct swap request dates
Browse files Browse the repository at this point in the history
  • Loading branch information
teodosii committed Jun 4, 2024
1 parent 2f1ffcf commit dc8d870
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions grafana-plugin/src/pages/schedule/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 45 in grafana-plugin/src/pages/schedule/Schedule.tsx

View workflow job for this annotation

GitHub Actions / Lint, test, and build frontend

'ScheduleEvent' is defined but never used
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';
Expand Down Expand Up @@ -598,23 +607,35 @@ class _SchedulePage extends React.Component<SchedulePageProps, SchedulePageState
history.replace(`${PLUGIN_ROOT}/schedules`);
};

handleShowShiftSwapForm = (id: ShiftSwap['id'] | 'new') => {
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)
Expand Down

0 comments on commit dc8d870

Please sign in to comment.