UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

79 lines (78 loc) 7.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const styles_1 = require("@mui/material/styles"); const material_1 = require("@mui/material"); const Icon_1 = tslib_1.__importDefault(require("@mui/material/Icon")); const utils_1 = require("@selfcommunity/utils"); const react_core_1 = require("@selfcommunity/react-core"); const react_intl_1 = require("react-intl"); const contribution_1 = require("../../../utils/contribution"); const DateTimeAgo_1 = tslib_1.__importDefault(require("../../../shared/DateTimeAgo")); const classnames_1 = tslib_1.__importDefault(require("classnames")); const types_1 = require("../../../types"); const NotificationItem_1 = tslib_1.__importDefault(require("../../../shared/NotificationItem")); const constants_1 = require("../constants"); const messages = (0, react_intl_1.defineMessages)({ youWrote: { id: 'ui.notification.kindlyNoticeFor.youWrote', defaultMessage: 'ui.notification.kindlyNoticeFor.youWrote' }, kindlyNoticeAdvertising: { id: 'ui.notification.kindlyNoticeFor.kindlyNoticeAdvertising', defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeAdvertising' }, kindlyNoticeAggressive: { id: 'ui.notification.kindlyNoticeFor.kindlyNoticeAggressive', defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeAggressive' }, kindlyNoticeVulgar: { id: 'ui.notification.kindlyNoticeFor.kindlyNoticeVulgar', defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeVulgar' }, kindlyNoticePoor: { id: 'ui.notification.kindlyNoticeFor.kindlyNoticePoor', defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticePoor' }, kindlyNoticeOfftopic: { id: 'ui.notification.kindlyNoticeFor.kindlyNoticeOfftopic', defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeOfftopic' } }); const classes = { root: `${constants_1.PREFIX}-kindly-notice-for-root`, flagIcon: `${constants_1.PREFIX}-flag-icon`, flagText: `${constants_1.PREFIX}-flag-text`, activeAt: `${constants_1.PREFIX}-active-at`, contributionWrap: `${constants_1.PREFIX}-contribution-wrap`, contributionYouWroteLabel: `${constants_1.PREFIX}-contribution-you-wrote-label`, contributionText: `${constants_1.PREFIX}-contribution-text` }; const Root = (0, styles_1.styled)(NotificationItem_1.default, { name: constants_1.PREFIX, slot: 'KindlyNoticeForRoot' })(() => ({})); /** * This component render the content of the notification of type kindly notice for * @constructor * @param props */ function KindlyNoticeForNotification(props) { // PROPS const { notificationObject, id = `n_${props.notificationObject['sid']}`, className, template = types_1.SCNotificationObjectTemplateType.DETAIL } = props, rest = tslib_1.__rest(props, ["notificationObject", "id", "className", "template"]); // ROUTING const scRoutingContext = (0, react_core_1.useSCRouting)(); // CONST const isSnippetTemplate = template === types_1.SCNotificationObjectTemplateType.SNIPPET; const contributionType = (0, contribution_1.getContributionType)(notificationObject); //INTL const intl = (0, react_intl_1.useIntl)(); /** * Renders root object */ return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className, `${constants_1.PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, image: (0, jsx_runtime_1.jsx)(material_1.Avatar, Object.assign({ variant: "circular", classes: { root: classes.flagIcon } }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "outlined_flag" }) })), primary: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: isSnippetTemplate ? ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], (0, contribution_1.getRouteData)(notificationObject[contributionType])) }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "div", color: "inherit", className: classes.flagText }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.notification.kindlyNoticeFor.${(0, utils_1.camelCase)(notificationObject.type)}Snippet`, defaultMessage: `ui.notification.kindlyNoticeFor.${(0, utils_1.camelCase)(notificationObject.type)}Snippet` }) })) }))) : ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "div", color: "inherit", className: classes.flagText }, { children: intl.formatMessage(messages[(0, utils_1.camelCase)(notificationObject.type)], { b: (...chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks }) }) }))) }), secondary: (template === types_1.SCNotificationObjectTemplateType.DETAIL || template === types_1.SCNotificationObjectTemplateType.SNIPPET) && ((0, jsx_runtime_1.jsx)(DateTimeAgo_1.default, { date: notificationObject.active_at, className: classes.activeAt })), footer: isSnippetTemplate ? null : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.contributionWrap }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: 'body2', color: 'inherit', component: 'div', classes: { root: classes.contributionYouWroteLabel } }, { children: intl.formatMessage(messages.youWrote, { b: (...chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks }) }) })), (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], (0, contribution_1.getRouteData)(notificationObject[contributionType])), className: classes.contributionText }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: 'span', variant: "body2" }, { children: (0, contribution_1.getContributionSnippet)(notificationObject[contributionType]) })) }))] })), template === types_1.SCNotificationObjectTemplateType.TOAST && ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 }, { children: [(0, jsx_runtime_1.jsx)(DateTimeAgo_1.default, { date: notificationObject.active_at }), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ color: "primary", component: 'div' }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes[`${notificationObject[contributionType]['type'].toUpperCase()}_ROUTE_NAME`], (0, contribution_1.getRouteData)(notificationObject[contributionType])) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.userToastNotifications.viewContribution", defaultMessage: 'ui.userToastNotifications.viewContribution' }) })) }))] })))] })) }, rest))); } exports.default = KindlyNoticeForNotification;