Only disable single notification row when toggling, not all rows

This commit is contained in:
mabashian
2020-08-20 14:24:05 -04:00
parent 681b765b9a
commit daeb5a8de8

View File

@@ -25,7 +25,7 @@ function NotificationList({
showApprovalsToggle, showApprovalsToggle,
}) { }) {
const location = useLocation(); const location = useLocation();
const [isToggleLoading, setIsToggleLoading] = useState(false); const [loadingToggleIds, setLoadingToggleIds] = useState([]);
const [toggleError, setToggleError] = useState(null); const [toggleError, setToggleError] = useState(null);
const { const {
@@ -123,7 +123,7 @@ function NotificationList({
isCurrentlyOn, isCurrentlyOn,
status status
) => { ) => {
setIsToggleLoading(true); setLoadingToggleIds(loadingToggleIds.concat([notificationId]));
try { try {
if (isCurrentlyOn) { if (isCurrentlyOn) {
await apiModel.disassociateNotificationTemplate( await apiModel.disassociateNotificationTemplate(
@@ -153,7 +153,9 @@ function NotificationList({
} catch (err) { } catch (err) {
setToggleError(err); setToggleError(err);
} finally { } finally {
setIsToggleLoading(false); setLoadingToggleIds(
loadingToggleIds.filter(item => item !== notificationId)
);
} }
}; };
@@ -208,7 +210,10 @@ function NotificationList({
key={notification.id} key={notification.id}
notification={notification} notification={notification}
detailUrl={`/notifications/${notification.id}`} detailUrl={`/notifications/${notification.id}`}
canToggleNotifications={canToggleNotifications && !isToggleLoading} canToggleNotifications={
canToggleNotifications &&
!loadingToggleIds.includes(notification.id)
}
toggleNotification={handleNotificationToggle} toggleNotification={handleNotificationToggle}
approvalsTurnedOn={approvalsTemplateIds.includes(notification.id)} approvalsTurnedOn={approvalsTemplateIds.includes(notification.id)}
errorTurnedOn={errorTemplateIds.includes(notification.id)} errorTurnedOn={errorTemplateIds.includes(notification.id)}
@@ -223,7 +228,7 @@ function NotificationList({
<AlertModal <AlertModal
variant="error" variant="error"
title={i18n._(t`Error!`)} title={i18n._(t`Error!`)}
isOpen={!isToggleLoading} isOpen={loadingToggleIds.length === 0}
onClose={() => setToggleError(null)} onClose={() => setToggleError(null)}
> >
{i18n._(t`Failed to toggle notification.`)} {i18n._(t`Failed to toggle notification.`)}