UNPKG

@selfcommunity/react-templates

Version:

React Templates Components to integrate a Community created with SelfCommunity.

52 lines (51 loc) 4.18 kB
import { __rest } from "tslib"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useMemo } from 'react'; import { SCPreferences, useSCPreferences } from '@selfcommunity/react-core'; import { Divider, Grid, Typography, styled } from '@mui/material'; import { FormattedMessage } from 'react-intl'; import classNames from 'classnames'; const PREFERENCES = [ SCPreferences.POINTS_MAKE_DISCUSSION, SCPreferences.POINTS_MAKE_POST, SCPreferences.POINTS_MAKE_COMMENT, SCPreferences.POINTS_RECEIVE_VOTE, SCPreferences.POINTS_CONNECTION_OR_FOLLOWER, SCPreferences.POINTS_SOCIAL_SHARE, SCPreferences.POINTS_APP_USED, SCPreferences.POINTS_DAILY_VISIT ]; import { PREFIX } from './constants'; const classes = { root: `${PREFIX}-points-list-root`, element: `${PREFIX}-element` }; export function PointElement({ message, points }) { if (points > 0) { return (_jsxs(Grid, Object.assign({ size: { xs: 12, md: 6 } }, { children: [_jsxs(Typography, Object.assign({ component: "div", className: classes.element }, { children: [_jsx(Typography, { children: message }), _jsxs(Typography, { children: ["+", _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points", defaultMessage: "templates.loyaltyProgramDetail.points", values: { total: points } })] })] })), _jsx(Divider, {})] }))); } } const Root = styled(Grid, { name: PREFIX, slot: 'PointsListRoot' })(() => ({})); /** * * @constructor * @param props */ export default function PointsList(props) { // PROPS const { className } = props, rest = __rest(props, ["className"]); // CONTEXT const { preferences } = useSCPreferences(); const _preferences = useMemo(() => { const _preferences = {}; PREFERENCES.map((p) => (_preferences[p] = p in preferences ? preferences[p].value : null)); return _preferences; }, [preferences]); /** * Renders the component (if not hidden by autoHide prop) */ return (_jsxs(Root, Object.assign({ className: classNames(classes.root, className), container: true, width: "100%", spacing: 2 }, rest, { children: [preferences[SCPreferences.CONFIGURATIONS_POST_TYPE_ENABLED].value && (_jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.post", defaultMessage: "templates.loyaltyProgramDetail.points.post" }), points: _preferences[SCPreferences.POINTS_MAKE_POST] })), preferences[SCPreferences.CONFIGURATIONS_DISCUSSION_TYPE_ENABLED].value && (_jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.discussion", defaultMessage: "templates.loyaltyProgramDetail.points.discussion" }), points: _preferences[SCPreferences.POINTS_MAKE_DISCUSSION] })), _jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.comment", defaultMessage: "templates.loyaltyProgramDetail.points.comment" }), points: _preferences[SCPreferences.POINTS_MAKE_COMMENT] }), _jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.appreciation", defaultMessage: "templates.loyaltyProgramDetail.points.appreciation" }), points: _preferences[SCPreferences.POINTS_RECEIVE_VOTE] }), _jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.follower", defaultMessage: "templates.loyaltyProgramDetail.points.follower" }), points: _preferences[SCPreferences.POINTS_CONNECTION_OR_FOLLOWER] }), _jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.share", defaultMessage: "templates.loyaltyProgramDetail.points.share" }), points: _preferences[SCPreferences.POINTS_SOCIAL_SHARE] }), _jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.app", defaultMessage: "templates.loyaltyProgramDetail.points.app" }), points: _preferences[SCPreferences.POINTS_APP_USED] }), _jsx(PointElement, { message: _jsx(FormattedMessage, { id: "templates.loyaltyProgramDetail.points.visit", defaultMessage: "templates.loyaltyProgramDetail.points.visit" }), points: _preferences[SCPreferences.POINTS_DAILY_VISIT] })] }))); }