fix: fix wrong dates on OOO edit dialog (#17736)

* fix: fix wrong dates on OOO edit dialog

* do not use utc() on the browser side
This commit is contained in:
Eunjae Lee
2024-11-19 19:54:12 -03:00
committed by GitHub
parent 757e3a2faf
commit 997d6a75e8
3 changed files with 12 additions and 11 deletions
@@ -104,8 +104,8 @@ export const CreateOrEditOutOfOfficeEntryModal = ({
? currentlyEditingOutOfOfficeEntry
: {
dateRange: {
startDate: dayjs().utc().startOf("d").toDate(),
endDate: dayjs().utc().add(1, "d").endOf("d").toDate(),
startDate: dayjs().startOf("d").toDate(),
endDate: dayjs().startOf("d").add(2, "d").toDate(),
},
offset: dayjs().utcOffset(),
toTeamUserId: null,
@@ -126,13 +126,14 @@ export const OutOfOfficeEntriesList = () => {
data-testid={`ooo-edit-${item.toUser?.username || "n-a"}`}
StartIcon="pencil"
onClick={() => {
const offset = dayjs().utcOffset();
const outOfOfficeEntryData: BookingRedirectForm = {
uuid: item.uuid,
dateRange: {
startDate: item.start,
endDate: dayjs(item.end).subtract(1, "d").toDate(),
startDate: dayjs(item.start).subtract(offset, "minute").toDate(),
endDate: dayjs(item.end).subtract(offset, "minute").startOf("d").toDate(),
},
offset: dayjs().utcOffset(),
offset,
toTeamUserId: item.toUserId,
reasonId: item.reason?.id ?? 1,
notes: item.notes ?? undefined,
@@ -155,8 +155,8 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
if (existingOutOfOfficeEntry) {
throw new TRPCError({ code: "BAD_REQUEST", message: "booking_redirect_infinite_not_allowed" });
}
const startDateUtc = dayjs.utc(startDate).add(input.offset, "minute");
const endDateUtc = dayjs.utc(endDate).add(input.offset, "minute");
const startTimeUtc = dayjs.utc(startDate).add(input.offset, "minute").startOf("day").toISOString();
const endTimeUtc = dayjs.utc(endDate).add(input.offset, "minute").endOf("day").toISOString();
// Get the existing redirected user from existing out of office entry to send that user appropriate email.
const previousOutOfOfficeEntry = await prisma.outOfOfficeEntry.findUnique({
@@ -181,8 +181,8 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
},
create: {
uuid: uuidv4(),
start: startDateUtc.startOf("day").toISOString(),
end: endDateUtc.endOf("day").toISOString(),
start: startTimeUtc,
end: endTimeUtc,
notes: input.notes,
userId: ctx.user.id,
reasonId: input.reasonId,
@@ -191,8 +191,8 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
updatedAt: new Date(),
},
update: {
start: startDateUtc.startOf("day").toISOString(),
end: endDateUtc.endOf("day").toISOString(),
start: startTimeUtc,
end: endTimeUtc,
notes: input.notes,
userId: ctx.user.id,
reasonId: input.reasonId,