UNPKG

@selfcommunity/react-ui

Version:

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

78 lines (77 loc) 7.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = tslib_1.__importStar(require("react")); const styles_1 = require("@mui/material/styles"); const material_1 = require("@mui/material"); const react_core_1 = require("@selfcommunity/react-core"); const types_1 = require("@selfcommunity/types"); const react_intl_1 = require("react-intl"); const Bullet_1 = tslib_1.__importDefault(require("../../../shared/Bullet")); const DateTimeAgo_1 = tslib_1.__importDefault(require("../../../shared/DateTimeAgo")); const contribution_1 = require("../../../utils/contribution"); const classnames_1 = tslib_1.__importDefault(require("classnames")); const types_2 = require("../../../types"); const NotificationItem_1 = tslib_1.__importDefault(require("../../../shared/NotificationItem")); const VoteButton_1 = tslib_1.__importDefault(require("../../VoteButton")); const UserDeletedSnackBar_1 = tslib_1.__importDefault(require("../../../shared/UserDeletedSnackBar")); const UserAvatar_1 = tslib_1.__importDefault(require("../../../shared/UserAvatar")); const constants_1 = require("../constants"); const messages = (0, react_intl_1.defineMessages)({ comment: { id: 'ui.notification.comment.comment', defaultMessage: 'ui.notification.comment.comment' }, nestedComment: { id: 'ui.notification.comment.nestedComment', defaultMessage: 'ui.notification.comment.nestedComment' } }); const classes = { root: `${constants_1.PREFIX}-comment-root`, avatar: `${constants_1.PREFIX}-avatar`, username: `${constants_1.PREFIX}-username`, voteButton: `${constants_1.PREFIX}-vote-button`, contributionText: `${constants_1.PREFIX}-contribution-text`, activeAt: `${constants_1.PREFIX}-active-at`, bullet: `${constants_1.PREFIX}-bullet` }; const Root = (0, styles_1.styled)(NotificationItem_1.default, { name: constants_1.PREFIX, slot: 'CommentRoot' })(() => ({})); /** * This component render the content of the notification of type comment/nested comment * @param props * @constructor */ function CommentNotification(props) { // PROPS const { notificationObject, onVote, id = `n_${props.notificationObject['sid']}`, template = types_2.SCNotificationObjectTemplateType.DETAIL, className } = props, rest = tslib_1.__rest(props, ["notificationObject", "onVote", "id", "template", "className"]); // STATE const [openAlert, setOpenAlert] = (0, react_1.useState)(false); // ROUTING const scRoutingContext = (0, react_core_1.useSCRouting)(); //INTL const intl = (0, react_intl_1.useIntl)(); // HANDLERS const handleVote = (contribution) => { return onVote && onVote(contribution); }; /** * Renders root object */ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(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)(react_core_1.Link, Object.assign({}, (!notificationObject.comment.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.comment.author) }), { onClick: notificationObject.comment.author.deleted ? () => setOpenAlert(true) : null }, { children: (0, jsx_runtime_1.jsx)(UserAvatar_1.default, Object.assign({ hide: !notificationObject.comment.author.community_badge, smaller: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { alt: notificationObject.comment.author.username, variant: "circular", src: notificationObject.comment.author.avatar, classes: { root: classes.avatar } }) })) })), primary: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!notificationObject.comment.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.comment.author) }), { onClick: notificationObject.comment.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: notificationObject.comment.author.username })), ' ', notificationObject.type === types_1.SCNotificationTypologyType.NESTED_COMMENT ? intl.formatMessage(messages.nestedComment, { b: (...chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks }) }) : intl.formatMessage(messages.comment, { b: (...chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks }) })] }), secondary: (0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.COMMENT_ROUTE_NAME, (0, contribution_1.getRouteData)(notificationObject.comment)) }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2", className: classes.contributionText }, { children: (0, contribution_1.getContributionSnippet)(notificationObject.comment) })) })), (template === types_2.SCNotificationObjectTemplateType.DETAIL || template === types_2.SCNotificationObjectTemplateType.SNIPPET) && ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", justifyContent: "flex-start", alignItems: "center", spacing: 1 }, { children: [(0, jsx_runtime_1.jsx)(DateTimeAgo_1.default, { date: notificationObject.active_at, className: classes.activeAt }), (0, jsx_runtime_1.jsx)(Bullet_1.default, { className: classes.bullet }), (0, jsx_runtime_1.jsx)(VoteButton_1.default, { className: classes.voteButton, variant: "text", size: "small", contributionId: notificationObject.comment.id, contributionType: types_1.SCContributionType.COMMENT, contribution: notificationObject.comment, onVote: handleVote })] })))] }), footer: template === types_2.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.COMMENT_ROUTE_NAME, (0, contribution_1.getRouteData)(notificationObject.comment)) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.userToastNotifications.viewContribution", defaultMessage: 'ui.userToastNotifications.viewContribution' }) })) }))] }))) }, rest)), openAlert && (0, jsx_runtime_1.jsx)(UserDeletedSnackBar_1.default, { open: openAlert, handleClose: () => setOpenAlert(false) })] })); } exports.default = CommentNotification;