@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
72 lines (71 loc) • 6.02 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 { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { getContributionType, getContributionSnippet, getRouteData } from '../../../utils/contribution';
import DateTimeAgo from '../../../shared/DateTimeAgo';
import NewChip from '../../../shared/NewChip/NewChip';
import { camelCase } from '@selfcommunity/utils';
import { Link, useSCRouting, SCRoutes } from '@selfcommunity/react-core';
import classNames from 'classnames';
import { SCNotificationObjectTemplateType } from '../../../types';
import NotificationItem from '../../../shared/NotificationItem';
import { PREFIX } from '../constants';
const messages = defineMessages({
deletedForAdvertising: {
id: 'ui.notification.deletedFor.deletedForAdvertising',
defaultMessage: 'ui.notification.deletedFor.deletedForAdvertising'
},
deletedForAggressive: {
id: 'ui.notification.deletedFor.deletedForAggressive',
defaultMessage: 'ui.notification.deletedFor.deletedForAggressive'
},
deletedForVulgar: {
id: 'ui.notification.deletedFor.deletedForVulgar',
defaultMessage: 'ui.notification.deletedFor.deletedForVulgar'
},
deletedForPoor: {
id: 'ui.notification.deletedFor.deletedForPoor',
defaultMessage: 'ui.notification.deletedFor.deletedForPoor'
},
deletedForOfftopic: {
id: 'ui.notification.deletedFor.deletedForOfftopic',
defaultMessage: 'ui.notification.deletedFor.deletedForOfftopic'
}
});
const classes = {
root: `${PREFIX}-deleted-for-root`,
flagIcon: `${PREFIX}-flag-icon`,
flagText: `${PREFIX}-flag-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: 'DeletedForRoot',
overridesResolver: (props, styles) => styles.root
})(() => ({}));
/**
* This component render the content of the notification of type deleted for
* @constructor
* @param props
*/
export default function DeletedForNotification(props) {
// PROPS
const { notificationObject = null, id = `n_${props.notificationObject['feed_serialization_id']}`, template = SCNotificationObjectTemplateType.DETAIL, className } = props, rest = __rest(props, ["notificationObject", "id", "template", "className"]);
// ROUTING
const scRoutingContext = useSCRouting();
// CONST
const contributionType = getContributionType(notificationObject);
const isSnippetTemplate = template === SCNotificationObjectTemplateType.SNIPPET;
//INTL
const intl = useIntl();
/**
* 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.flagIcon } }, { 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.flagText }, { children: _jsx(FormattedMessage, { id: `ui.notification.deletedFor.${camelCase(notificationObject.type)}Snippet`, defaultMessage: `ui.notification.deletedFor.${camelCase(notificationObject.type)}Snippet` }) })) }))) : (_jsxs(_Fragment, { children: [template === SCNotificationObjectTemplateType.DETAIL && notificationObject.is_new && _jsx(NewChip, {}), _jsx(Typography, Object.assign({ component: "div", color: "inherit", className: classes.flagText }, { children: intl.formatMessage(messages[camelCase(notificationObject.type)], { b: (...chunks) => _jsx("strong", { children: chunks }) }) }))] })) }), 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', classes: { root: classes.contributionYouWroteLabel } }, { children: _jsx(FormattedMessage, { id: "ui.notification.deletedFor.youWrote", defaultMessage: "ui.notification.deletedFor.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', color: 'inherit', 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)));
}