Skip to content
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
8 changes: 4 additions & 4 deletions react/assets/forus-platform/scss/_common/includes/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ img {
text-decoration: line-through;
}

.text-white-space-normal {
white-space: normal;
}

.text-pre {
white-space: pre;
}
Expand Down Expand Up @@ -178,10 +182,6 @@ img {
color: #e63b3b !important;
}

.text-danger-dark {
color: #8b0f0f !important;
}

.text-dim {
color: #454545 !important;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import SystemNotification from '../../../props/models/SystemNotification';
import { useParams } from 'react-router';
import StateNavLink from '../../../modules/state_router/StateNavLink';
import SystemNotificationEditor from './elements/SystemNotificationEditor';
import { useFundService } from '../../../services/FundService';
import Fund from '../../../props/models/Fund';
import useTranslate from '../../../hooks/useTranslate';
import useSetProgress from '../../../hooks/useSetProgress';
import usePushApiError from '../../../hooks/usePushApiError';
Expand All @@ -23,13 +21,9 @@ export default function ImplementationNotificationEdit() {
const pushApiError = usePushApiError();
const activeOrganization = useActiveOrganization();

const fundService = useFundService();
const implementationService = useImplementationService();
const implementationNotificationsService = useImplementationNotificationService();

const [fund, setFund] = useState<Partial<Fund>>(null);
const [funds, setFunds] = useState<Array<Partial<Fund>>>(null);

const [notification, setNotification] = useState<SystemNotification>(null);
const [implementation, setImplementation] = useState<Implementation>(null);

Expand All @@ -47,35 +41,11 @@ export default function ImplementationNotificationEdit() {
setProgress(0);

implementationNotificationsService
.read(activeOrganization.id, parseInt(implementationId), parseInt(id), { fund_id: fund?.id })
.read(activeOrganization.id, parseInt(implementationId), parseInt(id))
.then((res) => setNotification(res.data.data))
.catch(pushApiError)
.finally(() => setProgress(100));
}, [
id,
fund?.id,
setProgress,
pushApiError,
implementationId,
activeOrganization.id,
implementationNotificationsService,
]);

const fetchFunds = useCallback(() => {
if (implementation.allow_per_fund_notification_templates) {
setProgress(0);

fundService
.list(activeOrganization.id, {
implementation_id: implementation.id,
with_archived: 1,
stats: 'min',
})
.then((res) => setFunds([{ id: null, name: 'Alle fondsen' }, ...res.data.data]))
.catch(pushApiError)
.finally(() => setProgress(100));
}
}, [setProgress, implementation, fundService, activeOrganization.id, pushApiError]);
}, [id, setProgress, pushApiError, implementationId, activeOrganization.id, implementationNotificationsService]);

useEffect(() => {
fetchImplementation();
Expand All @@ -85,13 +55,7 @@ export default function ImplementationNotificationEdit() {
fetchNotification();
}, [fetchNotification]);

useEffect(() => {
if (implementation) {
fetchFunds();
}
}, [fetchFunds, implementation]);

if (!implementation || !notification || (implementation?.allow_per_fund_notification_templates && !funds)) {
if (!implementation || !notification) {
return <LoadingCard />;
}

Expand All @@ -112,9 +76,6 @@ export default function ImplementationNotificationEdit() {
</div>

<SystemNotificationEditor
fund={fund}
setFund={setFund}
funds={funds}
organization={activeOrganization}
implementation={implementation}
notification={notification}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import useImplementationNotificationService from '../../../services/Implementati
import SystemNotification from '../../../props/models/SystemNotification';
import useTranslate from '../../../hooks/useTranslate';
import usePushApiError from '../../../hooks/usePushApiError';
import Label from '../../elements/label/Label';
import TableRowActions from '../../elements/tables/TableRowActions';
import InfoBox from '../../elements/info-box/InfoBox';
import { useParams } from 'react-router';
import ImplementationsRootBreadcrumbs from '../implementations/elements/ImplementationsRootBreadcrumbs';
import { DashboardRoutes } from '../../../modules/state_router/RouterBuilder';
import LoaderTableCard from '../../elements/loader-table-card/LoaderTableCard';
import SystemNotificationChannelIcons from './elements/SystemNotificationChannelIcons';
import SystemNotificationStatusLabel from './elements/SystemNotificationStatusLabel';

export default function ImplementationNotifications() {
const { id } = useParams();
Expand All @@ -28,7 +29,6 @@ export default function ImplementationNotifications() {
const implementationService = useImplementationService();
const implementationNotificationsService = useImplementationNotificationService();

const [channels] = useState<Array<'mail' | 'push' | 'database'>>(['mail', 'push', 'database']);
const [notifications, setNotifications] = useState<PaginationData<SystemNotification>>(null);
const [implementation, setImplementation] = useState<Implementation>(null);

Expand All @@ -52,7 +52,6 @@ export default function ImplementationNotifications() {

const list = notifications?.data?.map((notification) => ({
...notification,
state: implementationNotificationsService.notificationToStateLabel(notification),
title: translate(`system_notifications.notifications.${notification.key}.title`),
description: translate(`system_notifications.notifications.${notification.key}.description`),
}));
Expand All @@ -63,67 +62,7 @@ export default function ImplementationNotifications() {
.map((group) => ({ group, groupLabel: groupLabels[group], notifications: grouped[group] }))
.map((item) => ({ ...item, notifications: item.notifications.sort((a, b) => a.order - b.order) }))
.sort((a, b) => groupOrder.indexOf(a.group) - groupOrder.indexOf(b.group));
}, [translate, groupLabels, notifications, implementationNotificationsService]);

const notificationIconColor = useCallback(
(notification: SystemNotification, type: 'database' | 'mail' | 'push') => {
const templateChanged = notification.templates.filter((item) => item.type == type).length > 0;

if (!notification.channels.includes(type)) {
return 'text-muted-light';
}

if (!notification.enable_all || !notification['enable_' + type]) {
return 'text-danger-dark';
}

return templateChanged ? 'text-primary-dark' : 'text-success-dark';
},
[],
);

const notificationIcon = useCallback((notification: SystemNotification, type: 'database' | 'mail' | 'push') => {
const iconOff = {
mail: 'email-off-outline',
push: 'cellphone-off',
database: 'bell-off-outline',
}[type];

const iconsOn = {
mail: 'email',
push: 'cellphone',
database: 'bell',
}[type];

if (!notification.channels.includes(type) || !notification.enable_all || !notification['enable_' + type]) {
return iconOff;
}

return iconsOn;
}, []);

const notificationIconTooltip = useCallback(
(notification: SystemNotification, type: 'database' | 'mail' | 'push') => {
const heading = translate(`system_notifications.types.${type}.title`);
const templateChanged = notification.templates.filter((item) => item.type == type).length > 0;

if (!notification.channels.includes(type)) {
return { heading, text: translate(`system_notifications.tooltips.channel_not_available`) };
}

if (!notification.enable_all || !notification[`enable_${type}`]) {
return { heading, text: translate(`system_notifications.tooltips.disabled_by_you`) };
}

return {
heading,
text: translate(
'system_notifications.tooltips.' + (templateChanged ? 'enabled_edited' : 'enabled_default'),
),
};
},
[translate],
);
}, [translate, groupLabels, notifications]);

const fetchImplementationNotifications = useCallback(() => {
implementationNotificationsService
Expand Down Expand Up @@ -214,54 +153,25 @@ export default function ImplementationNotifications() {
customElement={'tr'}
className={'tr-clickable'}>
<td className="td-grow">
<div>
<div className="text-semibold">
{notification.editable ? (
<em className="mdi mdi-pencil-outline text-muted-dark"> </em>
) : (
<em className="mdi mdi-lock-outline text-muted-dark"> </em>
)}
<span>{notification.title}</span>
</div>
<small>{notification.description}</small>
<div className="text-white-space-normal text-muted-dark">
{notification.description}
</div>
</td>
<td className="nowrap">{notification.optional ? 'Nee' : 'Ja'}</td>
<td className="nowrap">
<div className="td-icons">
{channels.map((channel, index) => (
<em
key={index}
className={`block block-tooltip-details block-tooltip-hover mdi mdi-${notificationIcon(
notification,
channel,
)} ${notificationIconColor(notification, channel)}`}>
<div className="tooltip-content tooltip-content-fit tooltip-content-ghost">
<div className="tooltip-heading text-left">
{notificationIconTooltip(notification, channel).heading}
</div>
<div className="tooltip-text text-left">
{notificationIconTooltip(notification, channel).text}
</div>
</div>
</em>
))}
</div>
<SystemNotificationChannelIcons notification={notification} />
</td>

<td className="nowrap">
{notification.state?.state === 'active' && (
<Label type="success">{notification.state.stateLabel}</Label>
)}

{notification.state?.state === 'inactive' && (
<Label type="danger">{notification.state.stateLabel}</Label>
)}

{notification.state?.state === 'active_partly' && (
<Label type="warning">{notification.state.stateLabel}</Label>
)}

{!['active', 'inactive', 'active_partly'].includes(notification.state?.state) && (
<Label type="default">{notification.state.stateLabel}</Label>
)}
<SystemNotificationStatusLabel notification={notification} />
</td>

<td className={'td-narrow text-right'}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import React, { useMemo } from 'react';
import classNames from 'classnames';
import useTranslate from '../../../../hooks/useTranslate';
import SystemNotification from '../../../../props/models/SystemNotification';

export default function SystemNotificationChannelIcon({
notification,
type,
}: {
notification: SystemNotification;
type: 'database' | 'mail' | 'push';
}) {
const translate = useTranslate();

const hasAnyFundChannelDisabled = useMemo(() => {
return Boolean(
notification.funds?.some((fund) => {
const enabled = {
database: fund.enable_database,
mail: fund.enable_mail,
push: fund.enable_push,
}[type];

return !fund.enable_all || !enabled;
}),
);
}, [notification.funds, type]);

const hasAllFundsChannelDisabled = useMemo(() => {
return Boolean(
notification.funds?.length &&
notification.funds.every((fund) => {
const enabled = {
database: fund.enable_database,
mail: fund.enable_mail,
push: fund.enable_push,
}[type];

return !fund.enable_all || !enabled;
}),
);
}, [notification.funds, type]);

const templateChanged = useMemo(() => {
return notification.templates.filter((item) => item.type == type).length > 0;
}, [notification.templates, type]);

const icon = useMemo(() => {
const iconOff = {
mail: 'email-off-outline',
push: 'cellphone-off',
database: 'bell-off-outline',
}[type];

const iconOn = {
mail: 'email',
push: 'cellphone',
database: 'bell',
}[type];

if (
!notification.channels.includes(type) ||
!notification.enable_all ||
!notification['enable_' + type] ||
hasAllFundsChannelDisabled
) {
return iconOff;
}

return iconOn;
}, [hasAllFundsChannelDisabled, notification, type]);

const color = useMemo(() => {
if (!notification.channels.includes(type)) {
return classNames('text-muted-light');
}

if (!notification.enable_all || !notification['enable_' + type] || hasAllFundsChannelDisabled) {
return classNames('text-danger');
}

if (hasAnyFundChannelDisabled) {
return classNames('text-warning');
}

return classNames(templateChanged ? 'text-primary-dark' : 'text-success-dark');
}, [hasAllFundsChannelDisabled, hasAnyFundChannelDisabled, notification, templateChanged, type]);

const tooltip = useMemo(() => {
const heading = translate(`system_notifications.types.${type}.title`);

if (!notification.channels.includes(type)) {
return { heading, text: translate(`system_notifications.tooltips.channel_not_available`) };
}

if (!notification.enable_all || !notification[`enable_${type}`]) {
return { heading, text: translate(`system_notifications.tooltips.disabled_by_you`) };
}

if (hasAllFundsChannelDisabled) {
return { heading, text: 'Voor alle fondsen uitgeschakeld.' };
}

if (hasAnyFundChannelDisabled) {
return { heading, text: 'Voor een of meer fondsen uitgeschakeld.' };
}

return {
heading,
text: translate(
'system_notifications.tooltips.' + (templateChanged ? 'enabled_edited' : 'enabled_default'),
),
};
}, [hasAllFundsChannelDisabled, hasAnyFundChannelDisabled, notification, templateChanged, translate, type]);

return (
<em className={classNames('block', 'block-tooltip-details', 'block-tooltip-hover', `mdi mdi-${icon}`, color)}>
<div className="tooltip-content tooltip-content-fit tooltip-content-ghost">
<div className="tooltip-heading text-left nowrap">{tooltip.heading}</div>
<div className="tooltip-text text-left">{tooltip.text}</div>
</div>
</em>
);
}
Loading
Loading