diff --git a/app/components/Notifications/NotificationListItem.tsx b/app/components/Notifications/NotificationListItem.tsx index 0faaa5fbba..80947f1e53 100644 --- a/app/components/Notifications/NotificationListItem.tsx +++ b/app/components/Notifications/NotificationListItem.tsx @@ -18,6 +18,7 @@ import Time from "../Time"; import { UnreadBadge } from "../UnreadBadge"; import { Permission } from "~/types"; import lazyWithRetry from "~/utils/lazyWithRetry"; +import { client } from "~/utils/ApiClient"; const CommentEditor = lazyWithRetry( () => import("~/scenes/Document/components/CommentEditor") @@ -30,7 +31,7 @@ type Props = { function NotificationListItem({ notification, onNavigate }: Props) { const { t } = useTranslation(); - const { collections, userMemberships } = useStores(); + const { collections } = useStores(); const collectionId = notification.document?.collectionId; const collection = collectionId ? collections.get(collectionId) : undefined; const [processing, setProcessing] = React.useState(false); @@ -76,13 +77,19 @@ function NotificationListItem({ notification, onNavigate }: Props) { event.preventDefault(); event.stopPropagation(); - if (!collection || !notification.actor || processing) {return;} + if ( + !collection || + !notification.actor || + processing || + !notification.accessRequestId + ) { + return; + } setProcessing(true); try { - await userMemberships.create({ - documentId: notification.documentId, - userId: notification.actor?.id, + await client.post("/access_requests.approve", { + id: notification.accessRequestId, permission: selectedPermission, }); toast.success( @@ -97,14 +104,32 @@ function NotificationListItem({ notification, onNavigate }: Props) { setProcessing(false); } }, - [ - notification, - processing, - selectedPermission, - t, - userMemberships, - collection, - ] + [notification, processing, selectedPermission, t, collection] + ); + + const handleDismiss = React.useCallback( + async (event: React.MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + + if (!notification.accessRequestId || processing) { + return; + } + + setProcessing(true); + try { + await client.post("/access_requests.dismiss", { + id: notification.accessRequestId, + }); + toast.success(t("Access request dismissed")); + void notification.markAsRead(); + } catch { + toast.error(t("Failed to dismiss access request")); + } finally { + setProcessing(false); + } + }, + [notification, processing, t] ); return ( @@ -148,7 +173,7 @@ function NotificationListItem({ notification, onNavigate }: Props) { {t("Approve")}