Skip to content

Commit babd514

Browse files
authored
fix: date overrides for availability settings atom (calcom#22701)
* only make api call once access token is verified * add date fns tz * use date-fns to format ranges for platform * update yarn.lock * fix merge conflicts * fix updating overrides for atoms * add changesets
1 parent 2e5cc11 commit babd514

5 files changed

Lines changed: 37 additions & 14 deletions

File tree

.changeset/twenty-comics-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@calcom/atoms": patch
3+
---
4+
5+
This change fixes date overrides breaking for availability settings atom

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"@next/third-parties": "^14.2.5",
121121
"@vercel/functions": "^1.4.0",
122122
"city-timezones": "^1.2.1",
123+
"date-fns-tz": "^3.2.0",
123124
"eslint": "^8.34.0",
124125
"p-limit": "^6.2.0",
125126
"turbo": "^1.10.1"

packages/features/schedules/components/DateOverrideList.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { noop } from "@tanstack/react-table";
2+
import { formatInTimeZone } from "date-fns-tz";
23

4+
import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform";
35
import dayjs from "@calcom/dayjs";
46
import { useLocale } from "@calcom/lib/hooks/useLocale";
57
import type { RouterOutputs } from "@calcom/trpc/react";
@@ -38,6 +40,7 @@ const DateOverrideList = ({
3840
handleAvailabilityUpdate?: VoidFunction;
3941
}) => {
4042
const { t, i18n } = useLocale();
43+
const isPlatform = useIsPlatform();
4144

4245
const unsortedFieldArrayMap = fields.reduce(
4346
(map: { [id: string]: number }, { id }, index) => ({ ...map, [id]: index }),
@@ -49,6 +52,10 @@ const DateOverrideList = ({
4952
}
5053

5154
const timeSpan = ({ start, end }: TimeRange) => {
55+
if (isPlatform) {
56+
return `${formatInTimeZone(start, "UTC", "h a")} - ${formatInTimeZone(end, "UTC", "h a")}`;
57+
}
58+
5259
return `${new Intl.DateTimeFormat(i18n.language, { hour: "numeric", minute: "numeric", hour12 }).format(
5360
new Date(start.toISOString().slice(0, -1))
5461
)} - ${new Intl.DateTimeFormat(i18n.language, { hour: "numeric", minute: "numeric", hour12 }).format(
@@ -62,12 +69,14 @@ const DateOverrideList = ({
6269
<li key={item.id} className="border-subtle flex justify-between border-b px-5 py-4 last:border-b-0">
6370
<div>
6471
<h3 className="text-emphasis text-sm">
65-
{new Intl.DateTimeFormat(i18n.language, {
66-
weekday: "long",
67-
month: "long",
68-
day: "numeric",
69-
timeZone: "UTC",
70-
}).format(item.ranges[0].start)}
72+
{!isPlatform &&
73+
new Intl.DateTimeFormat(i18n.language, {
74+
weekday: "long",
75+
month: "long",
76+
day: "numeric",
77+
timeZone: "UTC",
78+
}).format(item.ranges[0].start)}
79+
{isPlatform && formatInTimeZone(new Date(item.ranges[0].start), "UTC", "EEE MMM dd")}
7180
</h3>
7281
{item.ranges[0].start.valueOf() - item.ranges[0].end.valueOf() === 0 ? (
7382
<p className="text-subtle text-xs">{t("unavailable")}</p>
@@ -94,7 +103,10 @@ const DateOverrideList = ({
94103
userTimeFormat={userTimeFormat}
95104
excludedDates={excludedDates}
96105
workingHours={workingHours}
97-
value={item.ranges}
106+
value={item.ranges.map((range) => ({
107+
start: new Date(range.start),
108+
end: new Date(range.end),
109+
}))}
98110
weekStart={weekStart}
99111
onChange={(ranges) => {
100112
// update has very weird side-effects with sorting.
@@ -119,12 +131,14 @@ const DateOverrideList = ({
119131
className="text-default h-5"
120132
data-testid="delete-button"
121133
title={t("date_overrides_delete_on_date", {
122-
date: new Intl.DateTimeFormat(i18n.language, {
123-
weekday: "long",
124-
month: "long",
125-
day: "numeric",
126-
timeZone: "UTC",
127-
}).format(item.ranges[0].start),
134+
date: isPlatform
135+
? formatInTimeZone(new Date(item.ranges[0].start), "UTC", "h a")
136+
: new Intl.DateTimeFormat(i18n.language, {
137+
weekday: "long",
138+
month: "long",
139+
day: "numeric",
140+
timeZone: "UTC",
141+
}).format(item.ranges[0].start),
128142
})}
129143
color="destructive"
130144
variant="icon"

packages/platform/atoms/hooks/schedules/useAtomSchedule.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { SUCCESS_STATUS } from "@calcom/platform-constants";
55
import type { ApiResponse } from "@calcom/platform-types";
66

77
import http from "../../lib/http";
8+
import { useAtomsContext } from "../useAtomsContext";
89

910
export const QUERY_KEY = "use-atom-schedule";
1011

1112
export const useAtomSchedule = (scheduleId?: string, isManagedEventType?: boolean) => {
1213
const pathname = "atoms/schedules";
14+
const { isInit, accessToken } = useAtomsContext();
1315

1416
const { isLoading, error, data } = useQuery({
1517
queryKey: [QUERY_KEY, scheduleId, isManagedEventType],
@@ -25,6 +27,7 @@ export const useAtomSchedule = (scheduleId?: string, isManagedEventType?: boolea
2527
throw new Error(res.data.error?.message);
2628
});
2729
},
30+
enabled: isInit && !!accessToken,
2831
});
2932

3033
return { isLoading, error, data };

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48173,4 +48173,4 @@ __metadata:
4817348173
resolution: "zwitch@npm:2.0.4"
4817448174
checksum: f22ec5fc2d5f02c423c93d35cdfa83573a3a3bd98c66b927c368ea4d0e7252a500df2a90a6b45522be536a96a73404393c958e945fdba95e6832c200791702b6
4817548175
languageName: node
48176-
linkType: hard
48176+
linkType: hard

0 commit comments

Comments
 (0)