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

Add option to mark notification as unread #7553

Merged
merged 6 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 26 additions & 7 deletions src/Components/Notifications/NotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ const NotificationTile = ({
setIsMarkingAsRead(false);
};

const handleMarkAsUnRead = async () => {
setIsMarkingAsRead(true);
await request(routes.markNotificationAsUnRead, {
pathParams: { id: result.id },
body: { read_at: null },
});
setResult({ ...result, read_at: null });
setIsMarkingAsRead(false);
};

const resultUrl = (event: string, data: any) => {
switch (event) {
case "PATIENT_CREATED":
Expand Down Expand Up @@ -107,24 +117,33 @@ const NotificationTile = ({
</div>
<div className="flex justify-end gap-2">
<ButtonV2
className={classNames(
"bg-white px-2 py-1 font-semibold hover:bg-secondary-300",
result.read_at && "invisible",
)}
className="bg-white px-2 py-1 font-semibold hover:bg-secondary-300"
variant="secondary"
border
ghost
disabled={isMarkingAsRead}
onClick={(event) => {
event.stopPropagation();
handleMarkAsRead();
if (result.read_at) {
handleMarkAsUnRead();
} else {
handleMarkAsRead();
}
}}
>
<CareIcon
icon={isMarkingAsRead ? "l-spinner" : "l-envelope-check"}
icon={
isMarkingAsRead
? "l-spinner"
: result.read_at
? "l-envelope"
: "l-envelope-check"
}
className={isMarkingAsRead ? "animate-spin" : ""}
/>
<span className="text-xs">{t("mark_as_read")}</span>
<span className="text-xs">
{result.read_at ? t("mark_as_unread") : t("mark_as_read")}
</span>
</ButtonV2>
<ButtonV2
border
Expand Down
1 change: 1 addition & 0 deletions src/Locale/en/Notifications.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"no_notices_for_you": "No notices for you.",
"mark_as_read": "Mark as Read",
"mark_as_unread": "Mark as Unread",
"subscribe": "Subscribe",
"subscribe_on_this_device": "Subscribe on this device",
"show_unread_notifications": "Show Unread",
Expand Down
5 changes: 5 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,11 @@ const routes = {
method: "PATCH",
TRes: Type<NotificationData>(),
},
markNotificationAsUnRead: {
path: "/api/v1/notification/{id}/",
method: "PATCH",
TRes: Type<NotificationData>(),
},
getPublicKey: {
path: "/api/v1/notification/public_key/",
method: "GET",
Expand Down
Loading