Skip to content

Commit bab77e6

Browse files
MinitJainclaude
andcommitted
fix: remove night greeting bucket and extract shared useGreeting hook
Per maintainer feedback, "Good night" is a farewell not a greeting. Simplifies to three buckets: morning (5-11), afternoon (12-16), evening (17-4). Extracts duplicated timezone validation, Intl formatting, and daypart logic into a shared useGreeting hook to eliminate future drift between the two identical components. Removes greetings.night key from all 19 locale files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9e47a43 commit bab77e6

22 files changed

Lines changed: 65 additions & 108 deletions

apps/web/core/components/home/user-greetings.tsx

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,20 @@
55
*/
66

77
// plane types
8-
import { useMemo } from "react";
98
import { useTranslation } from "@plane/i18n";
109
import type { IUser } from "@plane/types";
11-
// plane ui
1210
// hooks
13-
import { useCurrentTime } from "@/hooks/use-current-time";
11+
import { useGreeting } from "@/hooks/use-greeting";
1412

1513
export interface IUserGreetingsView {
1614
user: IUser;
1715
}
1816

1917
export function UserGreetingsView(props: IUserGreetingsView) {
2018
const { user } = props;
21-
// current time hook
22-
const { currentTime } = useCurrentTime();
23-
// store hooks
19+
const { greeting, timeString, weekDay, date } = useGreeting(user);
2420
const { t } = useTranslation();
2521

26-
const userTimezone = useMemo(() => {
27-
if (!user?.user_timezone) return undefined;
28-
try {
29-
new Intl.DateTimeFormat(undefined, { timeZone: user.user_timezone });
30-
return user.user_timezone;
31-
} catch (e) {
32-
console.warn(`[UserGreetingsView] Invalid user_timezone "${user.user_timezone}", falling back to browser timezone.`, e);
33-
return undefined;
34-
}
35-
}, [user?.user_timezone]);
36-
37-
const hour = new Intl.DateTimeFormat("en-US", {
38-
timeZone: userTimezone,
39-
hourCycle: "h23",
40-
hour: "numeric",
41-
}).format(currentTime);
42-
43-
const date = new Intl.DateTimeFormat("en-US", {
44-
timeZone: userTimezone,
45-
month: "short",
46-
day: "numeric",
47-
}).format(currentTime);
48-
49-
const weekDay = new Intl.DateTimeFormat("en-US", {
50-
timeZone: userTimezone,
51-
weekday: "long",
52-
}).format(currentTime);
53-
54-
const timeString = new Intl.DateTimeFormat("en-US", {
55-
timeZone: userTimezone,
56-
hourCycle: "h23",
57-
hour: "2-digit",
58-
minute: "2-digit",
59-
}).format(currentTime);
60-
61-
const hourNum = parseInt(hour, 10);
62-
const greeting = hourNum < 5 ? "night" : hourNum < 12 ? "morning" : hourNum < 18 ? "afternoon" : "evening";
63-
6422
return (
6523
<div className="my-6 flex flex-col items-center">
6624
<h2 className="text-center text-20 font-semibold">

apps/web/core/components/user/user-greetings.tsx

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,20 @@
55
*/
66

77
// plane types
8-
import { useMemo } from "react";
98
import { useTranslation } from "@plane/i18n";
10-
// hooks
119
import type { IUser } from "@plane/types";
12-
import { useCurrentTime } from "@/hooks/use-current-time";
13-
// types
10+
// hooks
11+
import { useGreeting } from "@/hooks/use-greeting";
1412

1513
export interface IUserGreetingsView {
1614
user: IUser;
1715
}
1816

1917
export function UserGreetingsView(props: IUserGreetingsView) {
2018
const { user } = props;
21-
// current time hook
22-
const { currentTime } = useCurrentTime();
23-
// store hooks
19+
const { greeting, timeString, weekDay, date } = useGreeting(user);
2420
const { t } = useTranslation();
2521

26-
const userTimezone = useMemo(() => {
27-
if (!user?.user_timezone) return undefined;
28-
try {
29-
new Intl.DateTimeFormat(undefined, { timeZone: user.user_timezone });
30-
return user.user_timezone;
31-
} catch (e) {
32-
console.warn(`[UserGreetingsView] Invalid user_timezone "${user.user_timezone}", falling back to browser timezone.`, e);
33-
return undefined;
34-
}
35-
}, [user?.user_timezone]);
36-
37-
const hour = new Intl.DateTimeFormat("en-US", {
38-
timeZone: userTimezone,
39-
hourCycle: "h23",
40-
hour: "numeric",
41-
}).format(currentTime);
42-
43-
const date = new Intl.DateTimeFormat("en-US", {
44-
timeZone: userTimezone,
45-
month: "short",
46-
day: "numeric",
47-
}).format(currentTime);
48-
49-
const weekDay = new Intl.DateTimeFormat("en-US", {
50-
timeZone: userTimezone,
51-
weekday: "long",
52-
}).format(currentTime);
53-
54-
const timeString = new Intl.DateTimeFormat("en-US", {
55-
timeZone: userTimezone,
56-
hourCycle: "h23",
57-
hour: "2-digit",
58-
minute: "2-digit",
59-
}).format(currentTime);
60-
61-
const hourNum = parseInt(hour, 10);
62-
const greeting = hourNum < 5 ? "night" : hourNum < 12 ? "morning" : hourNum < 18 ? "afternoon" : "evening";
63-
6422
return (
6523
<div className="my-6 flex flex-col items-center">
6624
<h2 className="text-center text-20 font-semibold">
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright (c) 2023-present Plane Software, Inc. and contributors
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
* See the LICENSE file for details.
5+
*/
6+
7+
import { useMemo } from "react";
8+
import type { IUser } from "@plane/types";
9+
import { useCurrentTime } from "@/hooks/use-current-time";
10+
11+
export type TGreeting = "morning" | "afternoon" | "evening";
12+
13+
export const useGreeting = (user: IUser) => {
14+
const { currentTime } = useCurrentTime();
15+
16+
const userTimezone = useMemo(() => {
17+
if (!user?.user_timezone) return undefined;
18+
try {
19+
new Intl.DateTimeFormat(undefined, { timeZone: user.user_timezone });
20+
return user.user_timezone;
21+
} catch (e) {
22+
console.warn(
23+
`[useGreeting] Invalid user_timezone "${user.user_timezone}", falling back to browser timezone.`,
24+
e
25+
);
26+
return undefined;
27+
}
28+
}, [user?.user_timezone]);
29+
30+
const hour = new Intl.DateTimeFormat("en-US", {
31+
timeZone: userTimezone,
32+
hourCycle: "h23",
33+
hour: "numeric",
34+
}).format(currentTime);
35+
36+
const date = new Intl.DateTimeFormat("en-US", {
37+
timeZone: userTimezone,
38+
month: "short",
39+
day: "numeric",
40+
}).format(currentTime);
41+
42+
const weekDay = new Intl.DateTimeFormat("en-US", {
43+
timeZone: userTimezone,
44+
weekday: "long",
45+
}).format(currentTime);
46+
47+
const timeString = new Intl.DateTimeFormat("en-US", {
48+
timeZone: userTimezone,
49+
hourCycle: "h23",
50+
hour: "2-digit",
51+
minute: "2-digit",
52+
}).format(currentTime);
53+
54+
const hourNum = parseInt(hour, 10);
55+
// 5–11: morning, 12–16: afternoon, 17–4: evening
56+
const greeting: TGreeting =
57+
hourNum >= 5 && hourNum < 12 ? "morning" : hourNum >= 12 && hourNum < 17 ? "afternoon" : "evening";
58+
59+
return { greeting, timeString, weekDay, date };
60+
};

packages/i18n/src/locales/cs/translations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ export default {
494494
morning: "Dobré ráno, {first_name} {last_name}",
495495
afternoon: "Dobré odpoledne, {first_name} {last_name}",
496496
evening: "Dobrý večer, {first_name} {last_name}",
497-
night: "Dobrou noc, {first_name} {last_name}",
498497
},
499498
show_all: "Zobrazit vše",
500499
show_less: "Zobrazit méně",

packages/i18n/src/locales/de/translations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ export default {
507507
morning: "Guten Morgen, {first_name} {last_name}",
508508
afternoon: "Guten Nachmittag, {first_name} {last_name}",
509509
evening: "Guten Abend, {first_name} {last_name}",
510-
night: "Gute Nacht, {first_name} {last_name}",
511510
},
512511
show_all: "Alle anzeigen",
513512
show_less: "Weniger anzeigen",

packages/i18n/src/locales/en/translations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ export default {
327327
morning: "Good morning, {first_name} {last_name}",
328328
afternoon: "Good afternoon, {first_name} {last_name}",
329329
evening: "Good evening, {first_name} {last_name}",
330-
night: "Good night, {first_name} {last_name}",
331330
},
332331
show_all: "Show all",
333332
show_less: "Show less",

packages/i18n/src/locales/es/translations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ export default {
507507
morning: "Buenos días, {first_name} {last_name}",
508508
afternoon: "Buenas tardes, {first_name} {last_name}",
509509
evening: "Buenas noches, {first_name} {last_name}",
510-
night: "Buenas noches, {first_name} {last_name}",
511510
},
512511
show_all: "Mostrar todo",
513512
show_less: "Mostrar menos",

packages/i18n/src/locales/fr/translations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,6 @@ export default {
503503
morning: "Bonjour, {first_name} {last_name}",
504504
afternoon: "Bon après-midi, {first_name} {last_name}",
505505
evening: "Bonsoir, {first_name} {last_name}",
506-
night: "Bonne nuit, {first_name} {last_name}",
507506
},
508507
show_all: "Tout afficher",
509508
show_less: "Afficher moins",

packages/i18n/src/locales/id/translations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ export default {
499499
morning: "Selamat pagi, {first_name} {last_name}",
500500
afternoon: "Selamat siang, {first_name} {last_name}",
501501
evening: "Selamat malam, {first_name} {last_name}",
502-
night: "Selamat malam, {first_name} {last_name}",
503502
},
504503
show_all: "Tampilkan semua",
505504
show_less: "Tampilkan lebih sedikit",

packages/i18n/src/locales/it/translations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ export default {
500500
morning: "Buongiorno, {first_name} {last_name}",
501501
afternoon: "Buon pomeriggio, {first_name} {last_name}",
502502
evening: "Buonasera, {first_name} {last_name}",
503-
night: "Buonanotte, {first_name} {last_name}",
504503
},
505504
show_all: "Mostra tutto",
506505
show_less: "Mostra meno",

0 commit comments

Comments
 (0)