refactor: height of popover & api fetch call (#1587)

This commit is contained in:
Dakshesh Jain 2023-07-20 14:33:24 +05:30 committed by GitHub
parent 5e625ab132
commit 780573dadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 43 deletions

View File

@ -118,7 +118,7 @@ export const NotificationPopover = () => {
leaveFrom="opacity-100 translate-y-0" leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1" leaveTo="opacity-0 translate-y-1"
> >
<Popover.Panel className="absolute bg-custom-background-100 flex flex-col left-0 md:left-full ml-8 z-10 top-0 md:w-[36rem] w-[20rem] h-[27rem] border border-custom-border-300 shadow-lg rounded-xl"> <Popover.Panel className="absolute bg-custom-background-100 flex flex-col left-0 md:left-full ml-8 z-10 top-0 md:w-[36rem] w-[20rem] h-[50vh] border border-custom-border-300 shadow-lg rounded-xl">
<div className="flex items-center justify-between px-5 pt-5"> <div className="flex items-center justify-between px-5 pt-5">
<h2 className="text-xl font-semibold mb-2">Notifications</h2> <h2 className="text-xl font-semibold mb-2">Notifications</h2>
<div className="flex gap-x-4 justify-center items-center text-custom-text-200"> <div className="flex gap-x-4 justify-center items-center text-custom-text-200">

View File

@ -54,10 +54,8 @@ const useUserNotification = () => {
notifications?.find((notification) => notification.id === notificationId)?.read_at !== null; notifications?.find((notification) => notification.id === notificationId)?.read_at !== null;
if (isRead) { if (isRead) {
await userNotificationServices notificationsMutate(
.markUserNotificationAsUnread(workspaceSlug.toString(), notificationId) (prev) =>
.then(() => {
notificationsMutate((prev) =>
prev?.map((prevNotification) => { prev?.map((prevNotification) => {
if (prevNotification.id === notificationId) { if (prevNotification.id === notificationId) {
return { return {
@ -66,18 +64,20 @@ const useUserNotification = () => {
}; };
} }
return prevNotification; return prevNotification;
}) }),
false
); );
mutateNotificationCount(); await userNotificationServices
}) .markUserNotificationAsUnread(workspaceSlug.toString(), notificationId)
.catch(() => { .catch(() => {
throw new Error("Something went wrong"); throw new Error("Something went wrong");
})
.finally(() => {
notificationsMutate();
}); });
} else { } else {
await userNotificationServices notificationsMutate(
.markUserNotificationAsRead(workspaceSlug.toString(), notificationId) (prev) =>
.then(() => {
notificationsMutate((prev) =>
prev?.map((prevNotification) => { prev?.map((prevNotification) => {
if (prevNotification.id === notificationId) { if (prevNotification.id === notificationId) {
return { return {
@ -86,12 +86,16 @@ const useUserNotification = () => {
}; };
} }
return prevNotification; return prevNotification;
}) }),
false
); );
mutateNotificationCount(); await userNotificationServices
}) .markUserNotificationAsRead(workspaceSlug.toString(), notificationId)
.catch(() => { .catch(() => {
throw new Error("Something went wrong"); throw new Error("Something went wrong");
})
.finally(() => {
notificationsMutate();
}); });
} }
}; };
@ -105,22 +109,24 @@ const useUserNotification = () => {
if (isArchived) { if (isArchived) {
await userNotificationServices await userNotificationServices
.markUserNotificationAsUnarchived(workspaceSlug.toString(), notificationId) .markUserNotificationAsUnarchived(workspaceSlug.toString(), notificationId)
.then(() => {
notificationsMutate();
})
.catch(() => { .catch(() => {
throw new Error("Something went wrong"); throw new Error("Something went wrong");
})
.finally(() => {
notificationsMutate();
}); });
} else { } else {
notificationsMutate(
(prev) => prev?.filter((prevNotification) => prevNotification.id !== notificationId),
false
);
await userNotificationServices await userNotificationServices
.markUserNotificationAsArchived(workspaceSlug.toString(), notificationId) .markUserNotificationAsArchived(workspaceSlug.toString(), notificationId)
.then(() => {
notificationsMutate((prev) =>
prev?.filter((prevNotification) => prevNotification.id !== notificationId)
);
})
.catch(() => { .catch(() => {
throw new Error("Something went wrong"); throw new Error("Something went wrong");
})
.finally(() => {
notificationsMutate();
}); });
} }
}; };
@ -137,19 +143,25 @@ const useUserNotification = () => {
.patchUserNotification(workspaceSlug.toString(), notificationId, { .patchUserNotification(workspaceSlug.toString(), notificationId, {
snoozed_till: null, snoozed_till: null,
}) })
.then(() => { .finally(() => {
notificationsMutate(); notificationsMutate();
}); });
} else } else {
notificationsMutate(
(prevData) => prevData?.filter((prev) => prev.id !== notificationId) || [],
false
);
await userNotificationServices await userNotificationServices
.patchUserNotification(workspaceSlug.toString(), notificationId, { .patchUserNotification(workspaceSlug.toString(), notificationId, {
snoozed_till: dateTime, snoozed_till: dateTime,
}) })
.then(() => { .catch(() => {
notificationsMutate( new Error("Something went wrong");
(prevData) => prevData?.filter((prev) => prev.id !== notificationId) || [] })
); .finally(() => {
notificationsMutate();
}); });
}
}; };
return { return {