Skip to content

Commit 35259b7

Browse files
joeauyeungkodiakhq[bot]zomars
authored
Display correct time format on availability page (#3441)
* Pass time format * Write 24hr time format * Remove console.log * Change regex * Add console.log * Remove console.log * Remove console.log * Update TimeOptions.tsx * Write time format to localstorage on user create / edit * Grab and set from local storage * On user create grab timeformat from browser * Update timeFormat in DB * Fix typo Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com>
1 parent 538c5df commit 35259b7

File tree

7 files changed

+43
-8
lines changed

7 files changed

+43
-8
lines changed

apps/web/components/booking/TimeOptions.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { FC, useEffect, useState } from "react";
22

3+
import { useLocale } from "@calcom/lib/hooks/useLocale";
34
import Switch from "@calcom/ui/Switch";
45

5-
import { useLocale } from "@lib/hooks/useLocale";
6-
76
import TimezoneSelect, { ITimezoneOption } from "@components/ui/form/TimezoneSelect";
87

98
import { is24h, timeZone } from "../../lib/clock";
109

1110
type Props = {
1211
onSelectTimeZone: (selectedTimeZone: string) => void;
1312
onToggle24hClock: (is24hClock: boolean) => void;
13+
timeFormat: string;
1414
};
1515

16-
const TimeOptions: FC<Props> = ({ onToggle24hClock, onSelectTimeZone }) => {
16+
const TimeOptions: FC<Props> = ({ onToggle24hClock, onSelectTimeZone, timeFormat }) => {
1717
const [selectedTimeZone, setSelectedTimeZone] = useState("");
18-
const [is24hClock, setIs24hClock] = useState(false);
18+
const [is24hClock, setIs24hClock] = useState(timeFormat === "HH:mm" && true);
1919
const { t } = useLocale();
2020

2121
useEffect(() => {

apps/web/components/booking/pages/AvailabilityPage.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,18 @@ function TimezoneDropdown({
241241
onChangeTimeFormat,
242242
onChangeTimeZone,
243243
timeZone,
244+
timeFormat,
244245
}: {
245246
onChangeTimeFormat: (newTimeFormat: string) => void;
246247
onChangeTimeZone: (newTimeZone: string) => void;
247248
timeZone?: string;
249+
timeFormat: string;
248250
}) {
249251
const [isTimeOptionsOpen, setIsTimeOptionsOpen] = useState(false);
250252

251253
useEffect(() => {
252254
handleToggle24hClock(localStorage.getItem("timeOption.is24hClock") === "true");
255+
253256
// eslint-disable-next-line react-hooks/exhaustive-deps
254257
}, []);
255258

@@ -277,7 +280,11 @@ function TimezoneDropdown({
277280
</p>
278281
</Collapsible.Trigger>
279282
<Collapsible.Content>
280-
<TimeOptions onSelectTimeZone={handleSelectTimeZone} onToggle24hClock={handleToggle24hClock} />
283+
<TimeOptions
284+
onSelectTimeZone={handleSelectTimeZone}
285+
onToggle24hClock={handleToggle24hClock}
286+
timeFormat={timeFormat}
287+
/>
281288
</Collapsible.Content>
282289
</Collapsible.Root>
283290
);
@@ -363,6 +370,7 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
363370
const timezoneDropdown = useMemo(
364371
() => (
365372
<TimezoneDropdown
373+
timeFormat={timeFormat}
366374
onChangeTimeFormat={setTimeFormat}
367375
timeZone={timeZone}
368376
onChangeTimeZone={setTimeZone}

apps/web/lib/timeFormat.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@
44
* based on the user's preferred language
55
* defaults to 'en-US' (12h) if no navigator language is found
66
*/
7+
import { localStorage } from "@calcom/lib/webstorage";
8+
79
export const isBrowserLocale24h = () => {
10+
const localStorageTimeFormat = localStorage.getItem("timeOption.is24hClock");
11+
// If time format is already stored in the browser then retrieve and return early
12+
if (localStorageTimeFormat === "true") {
13+
return true;
14+
} else if (localStorageTimeFormat === "false") {
15+
return false;
16+
}
17+
818
let locale = "en-US";
9-
if (typeof window !== "undefined" && navigator) locale = navigator?.language;
10-
return !new Intl.DateTimeFormat(locale, { hour: "numeric" }).format(0).match(/AM/);
19+
if (typeof window !== "undefined" && navigator) locale = window.navigator?.language;
20+
21+
if (!new Intl.DateTimeFormat(locale, { hour: "numeric" }).format(0).match(/M/)) {
22+
localStorage.setItem("timeOption.is24hClock", "false");
23+
return false;
24+
} else {
25+
localStorage.setItem("timeOption.is24hClock", "true");
26+
return true;
27+
}
1128
};
29+
1230
export const detectBrowserTimeFormat = isBrowserLocale24h() ? "H:mm" : "h:mma";

apps/web/pages/api/user/[id].ts

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
5252
"name",
5353
"avatar",
5454
"timeZone",
55+
"timeFormat",
5556
"weekStart",
5657
"hideBranding",
5758
"theme",
@@ -68,6 +69,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
6869
bio: true,
6970
avatar: true,
7071
timeZone: true,
72+
timeFormat: true,
7173
weekStart: true,
7274
startTime: true,
7375
endTime: true,

apps/web/pages/getting-started.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { DEFAULT_SCHEDULE } from "@lib/availability";
2727
import { useLocale } from "@lib/hooks/useLocale";
2828
import prisma from "@lib/prisma";
2929
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
30+
import { isBrowserLocale24h } from "@lib/timeFormat";
3031
import { inferSSRProps } from "@lib/types/inferSSRProps";
3132
import { Schedule as ScheduleType } from "@lib/types/schedule";
3233

@@ -214,8 +215,12 @@ export default function Onboarding(props: inferSSRProps<typeof getServerSideProp
214215
);
215216
}
216217
}
218+
// Write default timeformat to localStorage
219+
const browserTimeFormat = isBrowserLocale24h() ? 24 : 12;
220+
217221
await updateUser({
218222
completedOnboarding: true,
223+
timeFormat: browserTimeFormat,
219224
});
220225

221226
setSubmitting(false);

apps/web/pages/settings/profile.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ function SettingsView(props: ComponentProps<typeof Settings> & { localeProp: str
178178
const enteredLanguage = selectedLanguage.value;
179179
const enteredTimeFormat = selectedTimeFormat.value;
180180

181+
// Write time format to localStorage if available
182+
window.localStorage.setItem("timeOption.is24hClock", selectedTimeFormat.value === 12 ? "false" : "true");
183+
181184
// TODO: Add validation
182185

183186
mutation.mutate({

packages/app-store/office365video/api/callback.ts

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ let client_secret = "";
1414

1515
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
1616
const { code } = req.query;
17-
console.log("🚀 ~ file: callback.ts ~ line 14 ~ handler ~ code", req.query);
1817

1918
if (typeof code !== "string") {
2019
res.status(400).json({ message: "No code returned" });

0 commit comments

Comments
 (0)