@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
70 lines (69 loc) • 5.84 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 { camelCase } from '@selfcommunity/utils';
import { Link, useSCRouting, SCRoutes } from '@selfcommunity/react-core';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { getContributionType, getContributionSnippet, 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 messages = defineMessages({
collapsedForAdvertising: {
id: 'ui.notification.collapsedFor.collapsedForAdvertising',
defaultMessage: 'ui.notification.collapsedFor.collapsedForAdvertising'
},
collapsedForAggressive: {
id: 'ui.notification.collapsedFor.collapsedForAggressive',
defaultMessage: 'ui.notification.collapsedFor.collapsedForAggressive'
},
collapsedForVulgar: {
id: 'ui.notification.collapsedFor.collapsedForVulgar',
defaultMessage: 'ui.notification.collapsedFor.collapsedForVulgar'
},
collapsedForPoor: {
id: 'ui.notification.collapsedFor.collapsedForPoor',
defaultMessage: 'ui.notification.collapsedFor.collapsedForPoor'
},
collapsedForOfftopic: {
id: 'ui.notification.collapsedFor.collapsedForOfftopic',
defaultMessage: 'ui.notification.collapsedFor.collapsedForOfftopic'
}
});
const classes = {
root: `${PREFIX}-collapsed-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: 'CollapsedForRoot'
})(() => ({}));
/**
* This component render the content of the notification of type collapsed for
* @constructor
* @param props
*/
export default function CollapsedForNotification(props) {
// PROPS
const { notificationObject, id = `n_${props.notificationObject['sid']}`, 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.collapsedFor.${camelCase(notificationObject.type)}Snippet`, defaultMessage: `ui.notification.collapsedFor.${camelCase(notificationObject.type)}Snippet` }) })) }))) : (_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', component: 'div', classes: { root: classes.contributionYouWroteLabel } }, { children: _jsx(FormattedMessage, { id: "ui.notification.collapsedFor.youWrote", defaultMessage: "ui.notification.collapsedFor.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", gutterBottom: true }, { 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)));
}