Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Card Design in Notice Board #9343

Closed

Conversation

AnveshNalimela
Copy link
Contributor

@AnveshNalimela AnveshNalimela commented Dec 9, 2024

Proposed Changes

Before
image

After:
image

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Enhanced NoticeBoard component for improved notification management and user experience.
    • Introduced new components: UserInfo, Message, and NoticeDialog for better notification display.
    • Added localized messages for improved accessibility.
  • Bug Fixes

    • Updated loading state handling for notifications.
  • Refactor

    • Improved type safety in notification data structures.

@AnveshNalimela AnveshNalimela requested a review from a team as a code owner December 9, 2024 17:57
Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Walkthrough

The pull request focuses on enhancing the NoticeBoard component in the notifications system. The changes include updating the component's data fetching mechanism using React Query, introducing new sub-components for improved rendering, and adding localized messages. The modifications aim to improve the user interface and experience of the notifications page by providing more structured and readable notification displays.

Changes

File Change Summary
src/components/Notifications/NoticeBoard.tsx - Added useQuery for data fetching
- Introduced new components: UserInfo, Message, NoticeDialog
- Added state management for selected notification
- Updated imports and utility functions
public/locale/en.json - Added localization keys for no notifications and view notice
src/components/Notifications/models.tsx - Updated NotificationData interface to improve type safety for caused_by property

Assessment against linked issues

Objective Addressed Explanation
Update Notice Card UI [#9339]
Improve Usability
Enhance Visual Appeal

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 Notifications dance and sway,
In a UI that brightens the day!
Components new, data so clear,
Rabbit's magic brings notices near!
A query here, a dialog there,
User experience beyond compare! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Dec 9, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 9827d3f
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6772aba90d5b8a000819c961
😎 Deploy Preview https://deploy-preview-9343--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
src/components/Notifications/NoticeBoard.tsx (1)

26-26: Consider adjusting card margin for consistency

While the card styling looks good, the my-1 margin seems inconsistent with the gap-6 used in the grid. Consider removing the margin since the grid gap already provides sufficient spacing.

-className="overflow-hidden rounded shadow-md my-1"
+className="overflow-hidden rounded shadow-md"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0f58adc and 3d8ec40.

📒 Files selected for processing (1)
  • src/components/Notifications/NoticeBoard.tsx (1 hunks)
🔇 Additional comments (2)
src/components/Notifications/NoticeBoard.tsx (2)

22-22: LGTM! Responsive grid layout with proper spacing

The grid container implementation with responsive columns and consistent gaps provides a clean layout across different screen sizes.


36-44: Consider using a more appropriate icon for user attribution

The Facebook Messenger icon (l-facebook-messenger) seems out of place for representing the user who caused the notification. Consider using a more appropriate icon like l-user or l-user-circle.

 <div className="text-md my-1 text-secondary-700 mx-2 px-3">
-  <CareIcon icon="l-facebook-messenger" className="mr-2" />
+  <CareIcon icon="l-user" className="mr-2" />
   {formatName(item.caused_by)} -{" "}

Let's verify that all text strings are properly internationalized:

src/components/Notifications/NoticeBoard.tsx Outdated Show resolved Hide resolved
@Jacobjeevan
Copy link
Contributor

Closing as duplicate of #9342

Please update the original PR instead 👍

@AnveshNalimela
Copy link
Contributor Author

@Jacobjeevan i closed the original PR becuase many unwanted changes got commited into that . Try to open these and get reviewd

@rithviknishad
Copy link
Member

rithviknishad commented Dec 10, 2024

But both PRs are using the same branch @AnveshNalimela. So it's equivalent to re-opening your old PR right?

@AnveshNalimela
Copy link
Contributor Author

@rithviknishad i just seen the in that PR 5 files got changed which are irrelavent and lot of commits
{9CD137DF-9C35-4023-B972-0FED2ADA0007}

so i closed that and reverted all changes and made the new PR

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 10, 2024
@rithviknishad
Copy link
Member

@Jacobjeevan reopening this as github doesn't allow reopening old PR's if there are force pushes on to the same branch.

@rithviknishad rithviknishad reopened this Dec 10, 2024
@rithviknishad rithviknishad removed question Further information is requested needs-triage labels Dec 10, 2024
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are now capturing user's avatar too, let's show that too.

@rithviknishad rithviknishad removed their request for review December 11, 2024 16:05
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by avatar in my previous change request, I meant this: https://github.com/ohcnetwork/care_fe/blob/develop/src/components/Common/Avatar.tsx

Not an icon.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/components/Notifications/NoticeBoard.tsx (1)

1-25: Consider organizing imports by category

Group imports into these categories for better maintainability:

  1. React and core dependencies
  2. UI components
  3. Utils and helpers
  4. Local components and types
 import { useQuery } from "@tanstack/react-query";
 import { useState } from "react";
 import React from "react";
 import { useTranslation } from "react-i18next";
+
 import CareIcon from "@/CAREUI/icons/CareIcon";
-
 import { Button } from "@/components/ui/button";
 import {
   Dialog,
   DialogContent,
   DialogFooter,
   DialogHeader,
   DialogTrigger,
 } from "@/components/ui/dialog";
+
 import { Avatar } from "@/components/Common/Avatar";
 import Loading from "@/components/Common/Loading";
 import Page from "@/components/Common/Page";
+
 import routes from "@/Utils/request/api";
 import query from "@/Utils/request/query";
 import { formatName, relativeTime } from "@/Utils/utils";
+
 import { NotificationData } from "./models";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e706e02 and d88651d.

📒 Files selected for processing (1)
  • src/components/Notifications/NoticeBoard.tsx (1 hunks)
🔇 Additional comments (5)
src/components/Notifications/NoticeBoard.tsx (5)

29-33: Update query configuration as discussed

Based on previous discussions:

  1. Add a limit parameter since we're only showing one page
  2. Remove unnecessary complexity from the query configuration
 const { data, isLoading } = useQuery({
   queryKey: ["notices"],
   queryFn: query(routes.getNotifications, {
-    queryParams: { event: "MESSAGE", medium_sent: "SYSTEM" },
+    queryParams: { event: "MESSAGE", medium_sent: "SYSTEM", limit: 14 },
   }),
 });

40-60: Improve UserInfo component implementation

The component needs the following improvements:

  1. Define a proper interface for the props instead of using the entire NotificationData
  2. Remove redundant username display
  3. Use proper spacing classes
-const UserInfo: React.FC<NotificationData> = (notice) => (
+interface UserInfoProps {
+  caused_by: NotificationData['caused_by'];
+  created_date: string;
+}
+
+const UserInfo: React.FC<UserInfoProps> = ({ caused_by, created_date }) => (
-  <div className="flex items-center bg-gray-100">
+  <div className="flex items-center bg-gray-100 w-full">
     <Avatar
-      name={formatName(notice.caused_by)}
-      imageUrl={notice.caused_by.read_profile_picture_url}
-      aria-label={`${formatName(notice.caused_by)}'s avatar`}
+      name={formatName(caused_by)}
+      imageUrl={caused_by.read_profile_picture_url}
+      aria-label={`${formatName(caused_by)}'s avatar`}
       className="border-0 border-b border-b-secondary-300 rounded-full h-10 w-10 ml-5"
     />
     <div className="text-md my-1 text-secondary-700  px-3">
       <div className="flex font-bold items-center text-black">
-        {formatName(notice.caused_by)}
-        <span className="font-oblique text-gray-500 font-medium ml-2">
-          {notice.caused_by.username}
-        </span>
+        {formatName(caused_by)}
       </div>
       <div className="text-xs text-secondary-900 font-medium">
-        {relativeTime(notice.created_date)}
+        {relativeTime(created_date)}
       </div>
     </div>
   </div>
 );

61-77: Fix message truncation in formatMessage

The current implementation drops the first line of the message by using lines.slice(1).

 const formatMessage = (message: string): React.ReactNode => {
   const lines = message.split("\n");
-  return lines.slice(1).map((line, index) => (
+  return lines.map((line, index) => (
     <React.Fragment key={index}>
       {line}
       {index < lines.length - 1 && <br />}
     </React.Fragment>
   ));
 };

79-104: Enhance dialog implementation and accessibility

The dialog needs several improvements:

  1. Use shadcn's Dialog components consistently
  2. Add proper ARIA attributes
  3. Improve structure and spacing
 const NoticeDialog: React.FC<{ notice: NotificationData }> = ({ notice }) => {
   return (
-    <div className="m-0 w-full h-full rounded-md w-full">
+    <div className="m-0 w-full h-full rounded-md">
       <DialogHeader>
+        <DialogTitle>Notice Details</DialogTitle>
         <div className="flex justify-between items-center mb-4">
           <CareIcon
             className="h-10 w-12 text-primary-500 bg-primary-200 rounded-md p-2 m-5"
             icon="l-envelope-open"
+            aria-hidden="true"
           />
         </div>
       </DialogHeader>
       <div
         className="flex-1 text-justify mx-6 mb-4"
         id="notification-message"
+        role="article"
+        aria-labelledby="notice-title notice-content"
       >
-        <h1 className="font-semibold text-lg text-black mb-1">
+        <h1 
+          id="notice-title"
+          className="font-semibold text-lg text-black mb-1"
+        >
           {notice.title ? notice.title : notice.message?.split("\n")[0]}
         </h1>
-        <Message className="" message={notice.message} />
+        <Message 
+          id="notice-content"
+          className="mt-2" 
+          message={notice.message} 
+        />
       </div>

109-146: Improve semantic structure and accessibility of notice cards

The notice cards structure needs improvements:

  1. Use semantic HTML elements
  2. Add proper ARIA attributes
  3. Improve responsive layout
-<section className="grid grid-cols-1 gap-6  xl:grid-cols-2 mt-4">
+<section 
+  className="grid grid-cols-1 gap-6 xl:grid-cols-2 mt-4"
+  aria-label="Notice board"
+>
   {data.results.map((item) => (
-    <div
+    <article
       key={`usr_${item.id}`}
+      aria-labelledby={`notice-${item.id}-title`}
       className="my-2 flex-col flex justify-between rounded-lg shadow-md min-h-[30vh]"
     >
       <div
         className="h-auto md:h-3/4 flex-1 text-justify mx-2 py-3 px-5  mb-3"
         id="notification-message"
       >
         <h1 
+          id={`notice-${item.id}-title`}
           className="font-semibold text-lg text-black mb-1 truncate hover:text-clip"
         >
           {item.title ? item.title : item.message?.split("\n")[0]}
         </h1>
-        <Message className="line-clamp-4" message={item.message} />
+        <Message 
+          className="line-clamp-4" 
+          message={item.message}
+          aria-labelledby={`notice-${item.id}-title`}
+        />
       </div>

@nihal467
Copy link
Member

@AnveshNalimela fix the cypress test failure, related to notice board

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/components/Notifications/NoticeBoard.tsx (3)

17-17: Convert relative imports to absolute imports

Following the project's conventions, convert these relative imports to absolute imports.

-import { Avatar } from "@/components/Common/Avatar";
+import { Avatar } from "components/Common/Avatar";
-import { NotificationData } from "@/components/Notifications/models";
+import { NotificationData } from "components/Notifications/models";
-import query from "@/Utils/request/query";
+import query from "Utils/request/query";
-import { formatName, relativeTime } from "@/Utils/utils";
+import { formatName, relativeTime } from "Utils/utils";

Also applies to: 20-20, 23-23, 24-24


28-32: Optimize query configuration

Based on previous discussions:

  1. Add a limit parameter since we're only showing one page
  2. Remove unnecessary complexity from the query configuration
  const { data, isLoading } = useQuery({
    queryKey: ["notices"],
    queryFn: query(routes.getNotifications, {
-     queryParams: { event: "MESSAGE", medium_sent: "SYSTEM" },
+     queryParams: { event: "MESSAGE", medium_sent: "SYSTEM", limit: 14 },
    }),
  });

108-108: Improve notice card structure and text display

The notice card structure and text display can be enhanced:

  1. Add aria-label to the section for better accessibility
  2. Use consistent line clamping for title and message
-<section className="grid grid-cols-1 gap-6  xl:grid-cols-2 mt-4">
+<section className="grid grid-cols-1 gap-6 xl:grid-cols-2 mt-4" aria-label="Notice board">
   <div
     className="h-auto md:h-3/4 flex-1 text-justify mx-2 py-3 px-5 mb-3"
     id="notification-message"
+    role="article"
   >
-    <h1 className="font-semibold text-lg text-black mb-1 truncate hover:text-clip">
+    <h1 className="font-semibold text-lg text-black mb-1 line-clamp-1 hover:line-clamp-none">
       {item.title ? item.title : item.message?.split("\n")[0]}
     </h1>
     <Message className="line-clamp-4" message={item.message} />
   </div>

Also applies to: 114-122

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d88651d and 100dd2a.

📒 Files selected for processing (1)
  • src/components/Notifications/NoticeBoard.tsx (1 hunks)
🔇 Additional comments (2)
src/components/Notifications/NoticeBoard.tsx (2)

60-68: ⚠️ Potential issue

Fix message truncation in formatMessage

The current implementation drops the first line of the message by using lines.slice(1).

 const formatMessage = (message: string): React.ReactNode => {
   const lines = message.split("\n");
-  return lines.slice(1).map((line, index) => (
+  return lines.map((line, index) => (
     <React.Fragment key={index}>
       {line}
       {index < lines.length - 1 && <br />}
     </React.Fragment>
   ));
 };

Likely invalid or redundant comment.


39-59: 🛠️ Refactor suggestion

Improve UserInfo component structure and props

The component needs better typing and reduced redundancy:

  1. Use a dedicated props interface instead of the entire NotificationData
  2. Remove redundant username display
-const UserInfo: React.FC<NotificationData> = (notice) => (
+interface UserInfoProps {
+  caused_by: NotificationData['caused_by'];
+  created_date: string;
+}
+
+const UserInfo: React.FC<UserInfoProps> = ({ caused_by, created_date }) => (
   <div className="flex items-center bg-gray-100">
     <Avatar
-      name={formatName(notice.caused_by)}
-      imageUrl={notice.caused_by.read_profile_picture_url}
+      name={formatName(caused_by)}
+      imageUrl={caused_by.read_profile_picture_url}
       className="border-0 border-b border-b-secondary-300 rounded-full h-10 w-10 ml-5"
     />
     <div className="text-md my-1 text-secondary-700  px-3">
       <div className="flex font-bold items-center text-black">
-        {formatName(notice.caused_by)}
-        <span className="font-oblique text-gray-500 font-medium ml-2">
-          {notice.caused_by.username}
-        </span>
+        {formatName(caused_by)}
       </div>
       <div className="text-xs text-secondary-900 font-medium ">
-        {relativeTime(notice.created_date)}
+        {relativeTime(created_date)}
       </div>
     </div>
   </div>
 );

Likely invalid or redundant comment.

src/components/Notifications/NoticeBoard.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/components/Notifications/NoticeBoard.tsx (3)

1-24: Convert relative imports to absolute imports

Based on the team's preferences from previous reviews, convert relative imports to absolute imports for better maintainability.

-import query from "@/Utils/request/query";
-import { formatName, relativeTime } from "@/Utils/utils";
+import { query } from "@care/utils/request/query";
+import { formatName, relativeTime } from "@care/utils/utils";

28-32: Simplify query configuration

As discussed in previous reviews:

  1. Remove the offset parameter since we're only showing one page
  2. Add a limit parameter to explicitly specify the page size
  const { data, isLoading } = useQuery({
    queryKey: ["notices"],
    queryFn: query(routes.getNotifications, {
-     queryParams: { offset: 0, event: "MESSAGE", medium_sent: "SYSTEM" },
+     queryParams: { event: "MESSAGE", medium_sent: "SYSTEM", limit: 14 },
    }),
  });

108-145: Enhance notice board accessibility and responsiveness

The notice board structure is good but could benefit from improved accessibility and responsive design.

-<section className="grid grid-cols-1 gap-6  xl:grid-cols-2 mt-4">
+<section 
+  className="grid grid-cols-1 gap-6 xl:grid-cols-2 mt-4"
+  aria-label={t("notice_board")}
+>
   {data.results.map((item) => (
     <div
       key={`usr_${item.id}`}
+      role="article"
+      aria-labelledby={`notice-${item.id}-title`}
       className="my-2 flex-col flex justify-between rounded-lg shadow-md min-h-[30vh]"
     >
       <div
         className="h-auto md:h-3/4 flex-1 text-justify mx-2 py-3 px-5 mb-3"
         id="notification-message"
       >
-        <h1 className="font-semibold text-lg text-black mb-1 truncate hover:text-clip">
+        <h1 
+          id={`notice-${item.id}-title`}
+          className="font-semibold text-lg text-black mb-1 truncate hover:text-clip"
+        >
           {item.title ? item.title : item.message?.split("\n")[0]}
         </h1>
         <Message className="line-clamp-4" message={item.message} />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 100dd2a and 7a22ba7.

📒 Files selected for processing (1)
  • src/components/Notifications/NoticeBoard.tsx (1 hunks)
🔇 Additional comments (3)
src/components/Notifications/NoticeBoard.tsx (3)

60-76: ⚠️ Potential issue

Fix message formatting and enhance security

The current implementation has two critical issues:

  1. The formatMessage function drops the first line of the message by using slice(1)
  2. The component needs proper typing and security measures
-const formatMessage = (message: string): React.ReactNode => {
-  const lines = message.split("\n");
-  return lines.slice(1).map((line, index) => (
+const formatMessage = (message: string): React.ReactNode => {
+  const lines = message.split("\n");
+  return lines.map((line, index) => (
     <React.Fragment key={index}>
       {line}
       {index < lines.length - 1 && <br />}
     </React.Fragment>
   ));
 };

-const Message: React.FC<{ message: string; className: string }> = ({
+interface MessageProps {
+  message: string;
+  className?: string;
+  id?: string;
+}
+
+const Message: React.FC<MessageProps> = ({
   message,
   className,
+  id,
 }) => {
   const formattedMessage = formatMessage(message);
-  return <p className={className}>{formattedMessage}</p>;
+  return <p id={id} className={className}>{formattedMessage}</p>;
 };

Likely invalid or redundant comment.


39-59: 🛠️ Refactor suggestion

Enhance UserInfo component type safety and reduce redundancy

The component needs the following improvements:

  1. Define a proper interface for props instead of using the entire NotificationData
  2. Remove redundant username display as it's already part of the formatted name
-const UserInfo: React.FC<NotificationData> = (notice) => (
+interface UserInfoProps {
+  caused_by: NotificationData['caused_by'];
+  created_date: string;
+}
+
+const UserInfo: React.FC<UserInfoProps> = ({ caused_by, created_date }) => (
   <div className="flex items-center bg-gray-100">
     <Avatar
-      name={formatName(notice.caused_by)}
-      imageUrl={notice.caused_by.read_profile_picture_url}
+      name={formatName(caused_by)}
+      imageUrl={caused_by.read_profile_picture_url}
       className="border-0 border-b border-b-secondary-300 rounded-full h-10 w-10 ml-5"
     />
     <div className="text-md my-1 text-secondary-700  px-3">
       <div className="flex font-bold items-center text-black">
-        {formatName(notice.caused_by)}
-        <span className="font-oblique text-gray-500 font-medium ml-2">
-          {notice.caused_by.username}
-        </span>
+        {formatName(caused_by)}
       </div>
       <div className="text-xs text-secondary-900 font-medium">
-        {relativeTime(notice.created_date)}
+        {relativeTime(created_date)}
       </div>
     </div>
   </div>
 );

Likely invalid or redundant comment.


78-103: 🛠️ Refactor suggestion

Enhance dialog accessibility and fix styling

The dialog needs proper ARIA attributes and styling fixes:

  1. Add proper dialog title and ARIA attributes
  2. Remove duplicate width class
  3. Improve semantic structure
 const NoticeDialog: React.FC<{ notice: NotificationData }> = ({ notice }) => {
   return (
-    <div className="m-0 w-full h-full rounded-md w-full">
+    <div className="m-0 w-full h-full rounded-md">
       <DialogHeader>
+        <DialogTitle>Notice Details</DialogTitle>
         <div className="flex justify-between items-center mb-4">
           <CareIcon
             className="h-10 w-12 text-primary-500 bg-primary-200 rounded-md p-2 m-5"
             icon="l-envelope-open"
+            aria-hidden="true"
           />
         </div>
       </DialogHeader>
       <div
         className="flex-1 text-justify mx-6 mb-4"
         id="notification-message"
+        role="article"
+        aria-labelledby="notice-title notice-content"
       >
-        <h1 className="font-semibold text-lg text-black mb-1">
+        <h1 id="notice-title" className="font-semibold text-lg text-black mb-1">
           {notice.title ? notice.title : notice.message?.split("\n")[0]}
         </h1>
-        <Message className="" message={notice.message} />
+        <Message id="notice-content" className="mt-2" message={notice.message} />
       </div>

Likely invalid or redundant comment.

@AnveshNalimela
Copy link
Contributor Author

@nihal467 Now all tests are passing..

@AnveshNalimela
Copy link
Contributor Author

AnveshNalimela commented Dec 28, 2024

@nihal467 . PR ready for testing

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 28, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (4)
src/components/Notifications/NoticeBoard.tsx (4)

28-32: 🛠️ Refactor suggestion

Simplify query configuration and add stale time

The current query configuration can be improved.

 const { data, isLoading } = useQuery({
   queryKey: ["notices"],
   queryFn: query(routes.getNotifications, {
-    queryParams: { offset: 0, event: "MESSAGE", medium_sent: "SYSTEM" },
+    queryParams: { event: "MESSAGE", medium_sent: "SYSTEM", limit: 14 },
   }),
+  staleTime: 5 * 60 * 1000, // 5 minutes
 });

39-59: 🛠️ Refactor suggestion

Improve UserInfo component structure and props

The component needs better typing and structure.

-const UserInfo: React.FC<NotificationData> = (notice) => (
+interface UserInfoProps {
+  caused_by: NotificationData['caused_by'];
+  created_date: string;
+}
+
+const UserInfo: React.FC<UserInfoProps> = ({ caused_by, created_date }) => (
   <div className="flex items-center bg-gray-100">
     <Avatar
-      name={formatName(notice.caused_by)}
+      name={formatName(caused_by)}
       imageUrl={notice.caused_by.read_profile_picture_url}
-      aria-label={`${formatName(notice.caused_by)}'s avatar`}
+      aria-label={`${formatName(caused_by)}'s avatar`}
       className="border-0 border-b border-b-secondary-300 rounded-full h-10 w-10 ml-5"
     />
     <div className="text-md my-1 text-secondary-700  px-3">
       <div className="flex font-bold items-center text-black">
-        {formatName(notice.caused_by)}
-        <span className="font-oblique text-gray-500 font-medium ml-2">
-          {notice.caused_by.username}
-        </span>
+        {formatName(caused_by)}
       </div>
       <div className="text-xs text-secondary-900 font-medium ">
-        {relativeTime(notice.created_date)}
+        {relativeTime(created_date)}
       </div>
     </div>
   </div>
 );

60-76: ⚠️ Potential issue

Fix message formatting logic and enhance Message component

The current implementation has issues with message formatting and component structure.

 const formatMessage = (message: string): React.ReactNode => {
   const lines = message.split("\n");
-  return lines.slice(1).map((line, index) => (
+  return lines.map((line, index) => (
     <React.Fragment key={index}>
       {line}
       {index < lines.length - 1 && <br />}
     </React.Fragment>
   ));
 };

-const Message: React.FC<{ message: string; className: string }> = ({
+interface MessageProps {
+  message: string;
+  className?: string;
+  id?: string;
+}
+
+const Message: React.FC<MessageProps> = ({
   message,
   className,
+  id,
 }) => {
   const formattedMessage = formatMessage(message);
-  return <p className={className}>{formattedMessage}</p>;
+  return <p id={id} className={className}>{formattedMessage}</p>;
 };

78-103: 🛠️ Refactor suggestion

Enhance NoticeDialog accessibility and structure

The dialog needs proper ARIA attributes and better structure.

 const NoticeDialog: React.FC<{ notice: NotificationData }> = ({ notice }) => {
   return (
-    <div className="w-full h-full rounded-md w-full">
+    <div className="m-0 w-full h-full rounded-md">
       <DialogHeader>
+        <DialogTitle>Notice Details</DialogTitle>
         <div className="flex justify-between items-center mb-4">
           <CareIcon
             className="h-10 w-12 text-primary-500 bg-primary-200 rounded-md p-2 m-5"
             icon="l-envelope-open"
+            aria-hidden="true"
           />
         </div>
       </DialogHeader>
       <div
         className="flex-1 text-justify mx-6 mb-4"
         id="notification-message"
+        role="article"
+        aria-labelledby="notice-title notice-content"
       >
-        <h1 className="font-semibold text-lg text-black mb-1">
+        <h1 id="notice-title" className="font-semibold text-lg text-black mb-1">
           {notice.title ? notice.title : notice.message?.split("\n")[0]}
         </h1>
-        <Message className="" message={notice.message} />
+        <Message id="notice-content" className="mt-2" message={notice.message} />
       </div>
🧹 Nitpick comments (3)
src/components/Notifications/NoticeBoard.tsx (3)

1-24: Convert relative imports to absolute imports

Use absolute imports consistently throughout the file for better maintainability.

-import { useTranslation } from "react-i18next";
+import { useTranslation } from "@/i18n";

-import CareIcon from "@/CAREUI/icons/CareIcon";
+import { CareIcon } from "@/components/icons";

-import { formatName, relativeTime } from "@/Utils/utils";
+import { formatName, relativeTime } from "@/lib/utils";

108-108: Improve grid layout and spacing

The current layout can be improved for better responsiveness and consistency.

-<section className="grid grid-cols-1 gap-6  xl:grid-cols-2 mt-4">
+<section className="grid grid-cols-1 gap-6 lg:grid-cols-2 mt-4">
   <div
-    className="my-2 flex-col flex justify-between rounded-lg shadow-md min-h-[30vh]"
+    className="flex flex-col justify-between rounded-lg shadow-md min-h-[30vh]"
   >
     <div
-      className="h-auto md:h-3/4 flex-1 text-justify mx-2 py-3 px-5  mb-3"
+      className="flex-1 text-justify mx-2 py-3 px-5 overflow-hidden mb-3"

Also applies to: 112-112, 115-115


124-125: Simplify button container structure

The button container has unnecessary nesting and styling.

 <UserInfo {...item} />
-<div className="flex flex-col text-left border-2 border-gray-400 rounded-md mr-10">
+<div className="flex items-center mr-4">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a22ba7 and 8179c69.

📒 Files selected for processing (1)
  • src/components/Notifications/NoticeBoard.tsx (1 hunks)
🔇 Additional comments (2)
src/components/Notifications/NoticeBoard.tsx (2)

160-160: LGTM: Loading state handling

The loading state is handled correctly using the Loading component.


137-139: 🛠️ Refactor suggestion

Optimize dialog content rendering

The current implementation might cause unnecessary re-renders.

-<DialogContent className="sm:max-w-md max-h-[80vh] overflow-y-auto p-0">
-  {selectedNotice && <NoticeDialog notice={selectedNotice} />}
+<DialogContent className="sm:max-w-md max-h-[80vh] overflow-y-auto p-0">
+  <NoticeDialog notice={item} />
</DialogContent>

Likely invalid or redundant comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/Notifications/NoticeBoard.tsx (2)

1-24: Consider grouping related imports together.

Group imports in the following order:

  1. React and related libraries
  2. UI components
  3. Local components
  4. Utils and types
 import { useQuery } from "@tanstack/react-query";
 import { useState } from "react";
 import React from "react";
 import { useTranslation } from "react-i18next";
+
 import { Button } from "@/components/ui/button";
 import {
   Dialog,
   DialogContent,
   DialogFooter,
   DialogHeader,
   DialogTrigger,
 } from "@/components/ui/dialog";
 import CareIcon from "@/CAREUI/icons/CareIcon";
 import { Avatar } from "@/components/Common/Avatar";
+
 import Loading from "@/components/Common/Loading";
 import Page from "@/components/Common/Page";
 import { NotificationData } from "@/components/Notifications/models";
+
 import routes from "@/Utils/request/api";
 import query from "@/Utils/request/query";
 import { formatName, relativeTime } from "@/Utils/utils";

108-145: Enhance semantic structure and responsive layout.

Consider these improvements for better accessibility and responsiveness:

-<section className="grid grid-cols-1 gap-6  xl:grid-cols-2 mt-4">
+<section 
+  className="grid grid-cols-1 gap-6 xl:grid-cols-2 mt-4"
+  aria-label="Notice board"
+>
   {data.results.map((item) => (
-    <div
+    <article
       key={`usr_${item.id}`}
+      aria-labelledby={`notice-${item.id}-title`}
       className="my-2 flex-col flex justify-between rounded-lg shadow-md min-h-[30vh]"
     >
       <div
-        className="h-auto md:h-3/4 flex-1 text-justify mx-2 py-3 px-5  mb-3"
+        className="h-auto md:h-3/4 flex-1 text-justify mx-2 py-3 px-5 mb-3 overflow-hidden"
         id="notification-message"
       >
-        <h1 className="font-semibold text-lg text-black mb-1 truncate hover:text-clip">
+        <h1 
+          id={`notice-${item.id}-title`}
+          className="font-semibold text-lg text-black mb-1 truncate hover:text-clip"
+        >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8179c69 and 3573070.

📒 Files selected for processing (1)
  • src/components/Notifications/NoticeBoard.tsx (1 hunks)
🔇 Additional comments (4)
src/components/Notifications/NoticeBoard.tsx (4)

28-32: 🛠️ Refactor suggestion

Optimize query configuration.

Since we're only showing one page of notices:

  1. Remove the unnecessary offset parameter
  2. Add a limit parameter to explicitly define the page size
 const { data, isLoading } = useQuery({
   queryKey: ["notices"],
   queryFn: query(routes.getNotifications, {
-    queryParams: { offset: 0, event: "MESSAGE", medium_sent: "SYSTEM" },
+    queryParams: { event: "MESSAGE", medium_sent: "SYSTEM", limit: 14 },
   }),
 });

Likely invalid or redundant comment.


60-68: ⚠️ Potential issue

Fix content loss in message formatting.

The formatMessage function is dropping the first line of the message by using lines.slice(1).

 const formatMessage = (message: string): React.ReactNode => {
   const lines = message.split("\n");
-  return lines.slice(1).map((line, index) => (
+  return lines.map((line, index) => (
     <React.Fragment key={index}>
       {line}
       {index < lines.length - 1 && <br />}
     </React.Fragment>
   ));
 };

Likely invalid or redundant comment.


39-59: 🛠️ Refactor suggestion

Enhance UserInfo component type safety and reduce redundancy.

The component needs the following improvements:

  1. Define a proper props interface instead of using the entire NotificationData
  2. Remove redundant username display
  3. Add proper types for user data
+interface UserInfoProps {
+  caused_by: {
+    username: string;
+    read_profile_picture_url?: string;
+  };
+  created_date: string;
+}

-const UserInfo: React.FC<NotificationData> = (notice) => (
+const UserInfo: React.FC<UserInfoProps> = ({ caused_by, created_date }) => (
   <div className="flex items-center bg-gray-100">
     <Avatar
-      name={formatName(notice.caused_by)}
-      imageUrl={notice.caused_by.read_profile_picture_url}
+      name={formatName(caused_by)}
+      imageUrl={caused_by.read_profile_picture_url}
       className="border-0 border-b border-b-secondary-300 rounded-full h-10 w-10 ml-5"
     />
     <div className="text-md my-1 text-secondary-700  px-3">
       <div className="flex font-bold items-center text-black">
-        {formatName(notice.caused_by)}
-        <span className="font-oblique text-gray-500 font-medium ml-2">
-          {notice.caused_by.username}
-        </span>
+        {formatName(caused_by)}
       </div>
       <div className="text-xs text-secondary-900 font-medium ">
-        {relativeTime(notice.created_date)}
+        {relativeTime(created_date)}
       </div>
     </div>
   </div>
 );

Likely invalid or redundant comment.


78-103: 🛠️ Refactor suggestion

Enhance dialog accessibility and structure.

The dialog needs proper ARIA attributes and better structure.

 const NoticeDialog: React.FC<{ notice: NotificationData }> = ({ notice }) => {
   return (
     <div className="w-full h-full rounded-md">
       <DialogHeader>
+        <DialogTitle>Notice Details</DialogTitle>
         <div className="flex justify-between items-center mb-4">
           <CareIcon
             className="h-10 w-12 text-primary-500 bg-primary-200 rounded-md p-2 m-5"
             icon="l-envelope-open"
+            aria-hidden="true"
           />
         </div>
       </DialogHeader>
       <div
         className="flex-1 text-justify mx-6 mb-4"
         id="notification-message"
+        role="article"
+        aria-labelledby="notice-title notice-content"
       >
-        <h1 className="font-semibold text-lg text-black mb-1">
+        <h1 id="notice-title" className="font-semibold text-lg text-black mb-1">
           {notice.title ? notice.title : notice.message?.split("\n")[0]}
         </h1>
-        <Message className="" message={notice.message} />
+        <Message id="notice-content" className="mt-2" message={notice.message} />
       </div>

Likely invalid or redundant comment.

src/components/Notifications/NoticeBoard.tsx Show resolved Hide resolved
@Jacobjeevan
Copy link
Contributor

No longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage question Further information is requested test failed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Notice Card UI in the notice_board Page
5 participants