@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
45 lines (44 loc) • 4.8 kB
JavaScript
import { __rest } from "tslib";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { styled } from '@mui/material/styles';
import { Avatar, Box, Stack, Typography } from '@mui/material';
import Icon from '@mui/material/Icon';
import { Link, SCRoutes, useSCRouting } from '@selfcommunity/react-core';
import { FormattedMessage } from 'react-intl';
import { getContributionSnippet, getContributionType, getRouteData } from '../../../utils/contribution';
import DateTimeAgo from '../../../shared/DateTimeAgo';
import classNames from 'classnames';
import { SCNotificationObjectTemplateType } from '../../../types';
import NotificationItem from '../../../shared/NotificationItem';
import { PREFIX } from '../constants';
const classes = {
root: `${PREFIX}-undeleted-for-root`,
undeletedIcon: `${PREFIX}-undeleted-icon`,
undeletedText: `${PREFIX}-undeleted-text`,
activeAt: `${PREFIX}-active-at`,
contributionWrap: `${PREFIX}-contribution-wrap`,
contributionYouWroteLabel: `${PREFIX}-contribution-you-wrote-label`,
contributionText: `${PREFIX}-contribution-text`
};
const Root = styled(NotificationItem, {
name: PREFIX,
slot: 'UndeletedForRoot'
})(() => ({}));
/**
* This component render the content of the notification of type undeleted for
* @constructor
* @param props
*/
export default function UndeletedForNotification(props) {
// PROPS
const { notificationObject, id = `n_${props.notificationObject['sid']}`, className, template = SCNotificationObjectTemplateType.DETAIL } = props, rest = __rest(props, ["notificationObject", "id", "className", "template"]);
// CONTEXT
const scRoutingContext = useSCRouting();
// CONST
const isSnippetTemplate = template === SCNotificationObjectTemplateType.SNIPPET;
const contributionType = getContributionType(notificationObject);
/**
* Renders root object
*/
return (_jsx(Root, Object.assign({ id: id, className: classNames(classes.root, className, `${PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, image: _jsx(Avatar, Object.assign({ variant: "circular", classes: { root: classes.undeletedIcon } }, { children: _jsx(Icon, { children: "outlined_flag" }) })), primary: _jsx(_Fragment, { children: isSnippetTemplate ? (_jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], getRouteData(notificationObject[contributionType])) }, { children: _jsx(Typography, Object.assign({ component: "div", color: "inherit", className: classes.undeletedText }, { children: _jsx(FormattedMessage, { id: "ui.notification.undeletedFor.restoredContentSnippet", defaultMessage: "ui.notification.undeletedFor.restoredContentSnippet" }) })) }))) : (_jsx(Typography, Object.assign({ component: "div", color: "inherit", className: classes.undeletedText }, { children: _jsx(FormattedMessage, { id: "ui.notification.undeletedFor.restoredContent", defaultMessage: "ui.notification.undeletedFor.restoredContent" }) }))) }), secondary: (template === SCNotificationObjectTemplateType.DETAIL || template === SCNotificationObjectTemplateType.SNIPPET) && (_jsx(DateTimeAgo, { date: notificationObject.active_at, className: classes.activeAt })), footer: isSnippetTemplate ? null : (_jsxs(_Fragment, { children: [_jsxs(Box, Object.assign({ className: classes.contributionWrap }, { children: [_jsx(Typography, Object.assign({ variant: 'body2', color: 'inherit', component: 'div', classes: { root: classes.contributionYouWroteLabel } }, { children: _jsx(FormattedMessage, { id: "ui.notification.undeletedFor.youWrote", defaultMessage: "ui.notification.undeletedFor.youWrote" }) })), _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], getRouteData(notificationObject[contributionType])), className: classes.contributionText }, { children: _jsx(Typography, Object.assign({ component: 'span', variant: "body2" }, { children: getContributionSnippet(notificationObject[contributionType]) })) }))] })), template === SCNotificationObjectTemplateType.TOAST && (_jsxs(Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 }, { children: [_jsx(DateTimeAgo, { date: notificationObject.active_at }), _jsx(Typography, Object.assign({ color: "primary", component: 'div' }, { children: _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${notificationObject[contributionType]['type'].toUpperCase()}_ROUTE_NAME`], getRouteData(notificationObject[contributionType])) }, { children: _jsx(FormattedMessage, { id: "ui.userToastNotifications.viewContribution", defaultMessage: 'ui.userToastNotifications.viewContribution' }) })) }))] })))] })) }, rest)));
}