-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathuser-greetings.tsx
More file actions
77 lines (67 loc) · 2.26 KB
/
Copy pathuser-greetings.tsx
File metadata and controls
77 lines (67 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/
// plane types
import { useMemo } from "react";
import { useTranslation } from "@plane/i18n";
// hooks
import type { IUser } from "@plane/types";
import { useCurrentTime } from "@/hooks/use-current-time";
// types
export interface IUserGreetingsView {
user: IUser;
}
export function UserGreetingsView(props: IUserGreetingsView) {
const { user } = props;
// current time hook
const { currentTime } = useCurrentTime();
// store hooks
const { t } = useTranslation();
const userTimezone = useMemo(() => {
if (!user?.user_timezone) return undefined;
try {
new Intl.DateTimeFormat(undefined, { timeZone: user.user_timezone });
return user.user_timezone;
} catch (e) {
console.warn(`[UserGreetingsView] Invalid user_timezone "${user.user_timezone}", falling back to browser timezone.`, e);
return undefined;
}
}, [user?.user_timezone]);
const hour = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
hourCycle: "h23",
hour: "numeric",
}).format(currentTime);
const date = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
month: "short",
day: "numeric",
}).format(currentTime);
const weekDay = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
weekday: "long",
}).format(currentTime);
const timeString = new Intl.DateTimeFormat("en-US", {
timeZone: userTimezone,
hourCycle: "h23",
hour: "2-digit",
minute: "2-digit",
}).format(currentTime);
const hourNum = parseInt(hour, 10);
const greeting = hourNum < 5 ? "night" : hourNum < 12 ? "morning" : hourNum < 18 ? "afternoon" : "evening";
return (
<div className="my-6 flex flex-col items-center">
<h2 className="text-center text-20 font-semibold">
{t(`greetings.${greeting}`, { first_name: user?.first_name ?? "", last_name: user?.last_name ?? "" })}
</h2>
<h5 className="flex items-center gap-2 font-medium text-placeholder">
<div>{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙"}</div>
<div>
{weekDay}, {date} {timeString}
</div>
</h5>
</div>
);
}