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
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3d8ec40
updated the design fixes #9339
AnveshNalimela Dec 9, 2024
46e2883
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 11, 2024
237a4a5
Replaced with user-icon
AnveshNalimela Dec 11, 2024
60e640d
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 11, 2024
fe11134
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 12, 2024
a47b465
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 12, 2024
2b16c64
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 13, 2024
b412ee4
Added User Avatar
AnveshNalimela Dec 13, 2024
3eec6d3
Realinged message with user avatar
AnveshNalimela Dec 13, 2024
e96dbb1
Merge branch 'develop' into issue/#9339/notice-card
AnveshNalimela Dec 15, 2024
3673ee8
Made the suggestions from coderabbit
AnveshNalimela Dec 15, 2024
aa756f8
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 16, 2024
bdabbb8
Removed Console stmts
AnveshNalimela Dec 16, 2024
769176c
Added Relative time and first_name and last_name
AnveshNalimela Dec 16, 2024
85f3280
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 18, 2024
24b7a63
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 21, 2024
f4e2dbd
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 22, 2024
ff8a8cc
Redesigned as per provided ui
AnveshNalimela Dec 22, 2024
be8ece6
added translations
AnveshNalimela Dec 22, 2024
0db12db
Made the changes suggested by coderabbit
AnveshNalimela Dec 22, 2024
6335d64
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 22, 2024
5593f00
Changed to shadcdn dialog,button
AnveshNalimela Dec 23, 2024
5375973
Merge branch 'issue/#9339/notice-card' of github.com:AnveshNalimela/c…
AnveshNalimela Dec 23, 2024
116d44b
Use useQuery instead of usetanstackQuerinstead
AnveshNalimela Dec 23, 2024
89253ef
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 23, 2024
a0b3cc3
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 23, 2024
738b65c
Removed getNotifcations.tsx and used query instead of request
AnveshNalimela Dec 23, 2024
58818fe
Remove console logs,used NotifcationData,passed user argument to Avatar
AnveshNalimela Dec 23, 2024
2b91c26
Merge branch 'develop' into issue/#9339/notice-card
AnveshNalimela Dec 23, 2024
34911f1
Made the requested changes
AnveshNalimela Dec 23, 2024
dd9885b
Removed offset parameter
AnveshNalimela Dec 24, 2024
ed07aae
Changed the gray-gradient according to design
AnveshNalimela Dec 24, 2024
40cceab
Merge branch 'develop' into issue/#9339/notice-card
AnveshNalimela Dec 24, 2024
d4f8a60
Changed the padding and margin according to design
AnveshNalimela Dec 24, 2024
db1e5ee
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 24, 2024
e706e02
remove border
AnveshNalimela Dec 24, 2024
1d4836a
Merge branch 'develop' into issue/#9339/notice-card
AnveshNalimela Dec 25, 2024
d88651d
made the corners rounded
AnveshNalimela Dec 25, 2024
ad01648
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 26, 2024
6439216
Merge branch 'develop' into issue/#9339/notice-card
AnveshNalimela Dec 27, 2024
100dd2a
Added absolute imports
AnveshNalimela Dec 27, 2024
fe11e3e
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 28, 2024
44dccce
Resloved failed test cases
AnveshNalimela Dec 28, 2024
7a22ba7
Merge branch 'issue/#9339/notice-card' of github.com:AnveshNalimela/c…
AnveshNalimela Dec 28, 2024
bc0c259
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 29, 2024
74dcbe4
commit to trigger cypress tests
AnveshNalimela Dec 29, 2024
8179c69
Merge branch 'issue/#9339/notice-card' of github.com:AnveshNalimela/c…
AnveshNalimela Dec 29, 2024
3573070
Made changes to trigger
AnveshNalimela Dec 29, 2024
9827d3f
Merge branch 'ohcnetwork:develop' into issue/#9339/notice-card
AnveshNalimela Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@
"no_log_update_delta": "No changes since previous log update",
"no_log_updates": "No log updates found",
"no_medical_history_available": "No Medical History Available",
"no_notice_available": "No Notice Available",
"no_notices_for_you": "No notices for you.",
"no_patients_found": "No Patients Found",
"no_patients_to_show": "No patients to show.",
Expand Down Expand Up @@ -1545,6 +1546,7 @@
"view_details": "View Details",
"view_facility": "View Facility",
"view_files": "View Files",
"view_notice": "View Notice",
"view_patients": "View Patients",
"view_update_patient_files": "View/Update patient files",
"view_updates": "View Updates",
Expand Down
146 changes: 124 additions & 22 deletions src/components/Notifications/NoticeBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,164 @@
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 useTanStackQueryInstead from "@/Utils/request/useQuery";
import { formatDateTime, formatName } from "@/Utils/utils";
import query from "@/Utils/request/query";
import { formatName, relativeTime } from "@/Utils/utils";

import { NotificationData } from "./models";
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved

export const NoticeBoard = () => {
const { t } = useTranslation();
const { data, loading } = useTanStackQueryInstead(routes.getNotifications, {
query: { offset: 0, event: "MESSAGE", medium_sent: "SYSTEM" },
const { data, isLoading } = useQuery({
queryKey: ["notices"],
queryFn: query(routes.getNotifications, {
queryParams: { offset: 0, event: "MESSAGE", medium_sent: "SYSTEM" },
}),
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
});

let notices;
const [selectedNotice, setSelectedNotice] = useState<NotificationData | null>(
null,
);

const UserInfo: React.FC<NotificationData> = (notice) => (
<div className="flex items-center bg-gray-200 rounded-lg">
<Avatar
name={formatName(notice.caused_by)}
imageUrl={notice.caused_by.read_profile_picture_url}
aria-label={`${formatName(notice.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>
</div>
<div className="text-xs text-secondary-900 font-medium ">
{relativeTime(notice.created_date)}
</div>
</div>
</div>
);
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
const formatMessage = (message: string): React.ReactNode => {
const lines = message.split("\n");
return lines.slice(1).map((line, index) => (
<React.Fragment key={index}>
{line}
{index < lines.length - 1 && <br />}
</React.Fragment>
));
};
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved

const Message: React.FC<{ message: string; className: string }> = ({
message,
className,
}) => {
const formattedMessage = formatMessage(message);
return <p className={className}>{formattedMessage}</p>;
};
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved

const NoticeDialog: React.FC<{ notice: NotificationData }> = ({ notice }) => {
return (
<>
<DialogHeader>
<div className="flex justify-between w-full items-center mb-4">
<CareIcon
className="bg-primary-200 font-light text-lg p-2 text-primary-600 rounded-lg w-12 h-10 "
icon="l-envelope-open"
/>
</div>
</DialogHeader>
<div
className="flex-1 text-justify mx-2 mb-2"
id="notification-message"
>
<h1 className="font-semibold text-lg text-black mb-1">
{notice.title ? notice.title : notice.message?.split("\n")[0]}
</h1>
<Message className="" message={notice.message} />
</div>
<DialogFooter className="sm:justify-start w-full py-2 flex items-center bg-gray-200 rounded-lg mt-4">
<UserInfo {...notice} />
</DialogFooter>
</>
);
};
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved

let notices;
if (data?.results.length) {
notices = (
<div className="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-3">
<section className="grid grid-cols-1 gap-6 xl:grid-cols-2 mt-4">
{data.results.map((item) => (
<div
key={`usr_${item.id}`}
className="overflow-hidden rounded shadow-md"
className="my-2 flex-col flex justify-between rounded shadow-md min-h-[33vh]"
>
<div className="px-6 py-4">
<div className="text-justify text-lg" id="notification-message">
{item.message}
</div>
<div className="text-md my-2 text-secondary-700">
{formatName(item.caused_by)} -{" "}
<span className="font-bold text-primary-700">
{item.caused_by.user_type}
</span>
</div>
<div className="text-xs text-secondary-900">
{t("on")}: {formatDateTime(item.created_date)}
<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">
{item.title ? item.title : item.message?.split("\n")[0]}
</h1>
<Message className="line-clamp-5" message={item.message} />
</div>
<div className="h-auto md:h-1/4 flex flex-col md:flex-row justify-between items-center bg-gray-200 p-3 md:py-1 space-y-3 md:space-y-0">
<UserInfo {...item} />
<div className="flex flex-col text-left border-2 border-gray-400 rounded-md mr-10">
<Dialog>
<DialogTrigger asChild>
<Button
variant={"ghost"}
onClick={() => setSelectedNotice(item)}
className="py-2 flex w-full items-center justify-center gap-2 rounded-lg p-2 text-sm font-semibold text-inherit "
>
<CareIcon icon="l-eye" className="text-lg" />
{t("view_notice")}
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md max-h-[80vh] overflow-y-auto">
{selectedNotice && <NoticeDialog notice={selectedNotice} />}
</DialogContent>
</Dialog>
</div>
</div>
</div>
))}
</div>
</section>
);
} else {
notices = (
<div className="m-auto flex max-w-xs items-center">
<div className="my-36">
<CareIcon icon="l-bell-slash" className="h-auto text-secondary-500" />
<div className="m-auto mt-6 text-2xl text-secondary-500">
No Notice Available
{t("no_notice_available")}
</div>
</div>
</div>
);
}

if (loading) return <Loading />;
if (isLoading) return <Loading />;
return (
<Page title={t("notice_board")} hideBack={true} breadcrumbs={false}>
<div>{notices}</div>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Notifications/models.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { UserBareMinimum } from "../Users/models";

export interface NotificationData {
id: string;
title: string;
caused_objects: cause_object;
caused_by: any;
caused_by: UserBareMinimum;
content: string;
offset: number;
event: string;
Expand Down
Loading