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 clear all button in notifications #3893

Merged
merged 11 commits into from
Sep 29, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ export function Notifications({
count: notifications.length,
})
: notificationsText.notificationsLoading();

function handleClearAll() {
if (notifications === undefined) return;
notifications.forEach((notification) => {
ping('/notifications/delete/', {
method: 'POST',
// eslint-disable-next-line @typescript-eslint/naming-convention
body: formData({ message_id: notification.messageId }),
errorMode: 'dismissible',
});
});
setNotifications([]);
}

return (
<>
<MenuButton
Expand All @@ -62,7 +76,17 @@ export function Notifications({
/>
{Array.isArray(notifications) ? (
<Dialog
buttons={commonText.close()}
buttons={
<>
{notifications.length > 1 && (
<Button.Secondary onClick={handleClearAll}>
{commonText.clearAll()}
</Button.Secondary>
)}
<span className="-ml-2 flex-1" />
<Button.DialogClose>{commonText.close()}</Button.DialogClose>
</>
}
className={{
container: `${dialogClassNames.narrowContainer} min-w-[50%]`,
content: `${dialogClassNames.flexContent} gap-3 divide-y divide-gray-500`,
Expand Down