From a187e7765ccd79bbb6d3e5e448fddee52ef9210f Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:08:01 +0530 Subject: [PATCH] fix: user dashboard greeting timezone (#2267) * chore: user greeting timezone * fix: group by labels not working on workspace level --- .../core/filters/issues-view-filter.tsx | 6 +- .../core/views/board-view/board-header.tsx | 20 +++++- .../core/views/list-view/single-list.tsx | 40 +++++++++--- .../my-issues/my-issues-view-options.tsx | 2 +- .../profile/profile-issues-view-options.tsx | 2 +- web/pages/[workspaceSlug]/index.tsx | 62 +++++++++++++------ 6 files changed, 97 insertions(+), 35 deletions(-) diff --git a/web/components/core/filters/issues-view-filter.tsx b/web/components/core/filters/issues-view-filter.tsx index f5b0f477a..2ad165dd8 100644 --- a/web/components/core/filters/issues-view-filter.tsx +++ b/web/components/core/filters/issues-view-filter.tsx @@ -93,7 +93,9 @@ export const IssuesFilterView: React.FC = () => { {replaceUnderscoreIfSnakeCase(option.type)} Layout + + {replaceUnderscoreIfSnakeCase(option.type)} Layout + } position="bottom" > @@ -318,7 +320,7 @@ export const IssuesFilterView: React.FC = () => { displayFilters.layout !== "spreadsheet" && displayFilters.layout !== "gantt_chart" && (
-

Show empty states

+

Show empty groups

= ({ : null ); + const { data: workspaceLabels } = useSWR( + workspaceSlug && displayFilters?.group_by === "labels" + ? WORKSPACE_LABELS(workspaceSlug.toString()) + : null, + workspaceSlug && displayFilters?.group_by === "labels" + ? () => issuesService.getWorkspaceLabels(workspaceSlug.toString()) + : null + ); + const { data: members } = useSWR( workspaceSlug && projectId && @@ -82,7 +91,10 @@ export const BoardHeader: React.FC = ({ title = addSpaceIfCamelCase(currentState?.name ?? ""); break; case "labels": - title = issueLabels?.find((label) => label.id === groupTitle)?.name ?? "None"; + title = + [...(issueLabels ?? []), ...(workspaceLabels ?? [])]?.find( + (label) => label.id === groupTitle + )?.name ?? "None"; break; case "project": title = projects?.find((p) => p.id === groupTitle)?.name ?? "None"; @@ -137,7 +149,9 @@ export const BoardHeader: React.FC = ({ break; case "labels": const labelColor = - issueLabels?.find((label) => label.id === groupTitle)?.color ?? "#000000"; + [...(issueLabels ?? []), ...(workspaceLabels ?? [])]?.find( + (label) => label.id === groupTitle + )?.color ?? "#000000"; icon = ( = (props) => { const { displayFilters, groupedIssues } = viewProps; - const { data: issueLabels } = useSWR( - workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null, - workspaceSlug && projectId - ? () => issuesService.getIssueLabels(workspaceSlug as string, projectId as string) + const { data: issueLabels } = useSWR( + workspaceSlug && projectId && displayFilters?.group_by === "labels" + ? PROJECT_ISSUE_LABELS(projectId.toString()) + : null, + workspaceSlug && projectId && displayFilters?.group_by === "labels" + ? () => issuesService.getIssueLabels(workspaceSlug.toString(), projectId.toString()) + : null + ); + + const { data: workspaceLabels } = useSWR( + workspaceSlug && displayFilters?.group_by === "labels" + ? WORKSPACE_LABELS(workspaceSlug.toString()) + : null, + workspaceSlug && displayFilters?.group_by === "labels" + ? () => issuesService.getWorkspaceLabels(workspaceSlug.toString()) : null ); const { data: members } = useSWR( - workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null, - workspaceSlug && projectId + workspaceSlug && + projectId && + (displayFilters?.group_by === "created_by" || displayFilters?.group_by === "assignees") + ? PROJECT_MEMBERS(projectId as string) + : null, + workspaceSlug && + projectId && + (displayFilters?.group_by === "created_by" || displayFilters?.group_by === "assignees") ? () => projectService.projectMembers(workspaceSlug as string, projectId as string) : null ); @@ -110,7 +127,10 @@ export const SingleList: React.FC = (props) => { title = addSpaceIfCamelCase(currentState?.name ?? ""); break; case "labels": - title = issueLabels?.find((label) => label.id === groupTitle)?.name ?? "None"; + title = + [...(issueLabels ?? []), ...(workspaceLabels ?? [])]?.find( + (label) => label.id === groupTitle + )?.name ?? "None"; break; case "project": title = projects?.find((p) => p.id === groupTitle)?.name ?? "None"; @@ -164,7 +184,9 @@ export const SingleList: React.FC = (props) => { break; case "labels": const labelColor = - issueLabels?.find((label) => label.id === groupTitle)?.color ?? "#000000"; + [...(issueLabels ?? []), ...(workspaceLabels ?? [])]?.find( + (label) => label.id === groupTitle + )?.color ?? "#000000"; icon = ( { displayFilters?.layout !== "spreadsheet" && ( <>
-

Show empty states

+

Show empty groups

{ displayFilters?.layout !== "spreadsheet" && ( <>
-

Show empty states

+

Show empty groups

{ + const currentTime = new Date(); + + const hour = new Intl.DateTimeFormat("en-US", { + hour12: false, + hour: "numeric", + }).format(currentTime); + + const date = new Intl.DateTimeFormat("en-US", { + month: "short", + day: "numeric", + }).format(currentTime); + + const weekDay = new Intl.DateTimeFormat("en-US", { + weekday: "long", + }).format(currentTime); + + const timeString = new Intl.DateTimeFormat("en-US", { + timeZone: user?.user_timezone, + hour12: false, // Use 24-hour format + hour: "2-digit", + minute: "2-digit", + }).format(currentTime); + + const greeting = + parseInt(hour, 10) < 12 ? "morning" : parseInt(hour, 10) < 18 ? "afternoon" : "evening"; + + return ( +
+

+ Good {greeting}, {user?.first_name} {user?.last_name} +

+
+
{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙️"}
+
+ {weekDay}, {date} {timeString} +
+
+
+ ); +}; const WorkspacePage: NextPage = () => { const [month, setMonth] = useState(new Date().getMonth() + 1); @@ -58,10 +96,6 @@ const WorkspacePage: NextPage = () => { workspaceSlug ? () => userService.userWorkspaceDashboard(workspaceSlug as string, month) : null ); - const today = new Date(); - const greeting = - today.getHours() < 12 ? "morning" : today.getHours() < 18 ? "afternoon" : "evening"; - useEffect(() => { if (!workspaceSlug) return; @@ -128,17 +162,7 @@ const WorkspacePage: NextPage = () => {
)}
-
-

- Good {greeting}, {user?.first_name} {user?.last_name} -

-
-
{greeting === "morning" ? "🌤️" : greeting === "afternoon" ? "🌥️" : "🌙️"}
-
- {DAYS[today.getDay()]}, {renderShortDate(today)} {render12HourFormatTime(today)} -
-
-
+ {projects ? ( projects.length > 0 ? (