@selfcommunity/react-templates 0.4.5-alpha.8 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ const styles_1 = require("@mui/material/styles");
6
6
  const material_1 = require("@mui/material");
7
7
  const react_ui_1 = require("@selfcommunity/react-ui");
8
8
  const react_core_1 = require("@selfcommunity/react-core");
9
+ const types_1 = require("@selfcommunity/types");
9
10
  const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
10
11
  const system_1 = require("@mui/system");
11
12
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
@@ -54,7 +55,11 @@ function Event(inProps) {
54
55
  const { id = 'event', className, event, eventId, widgets, FeedObjectProps, FeedSidebarProps, EventFeedProps = {}, EventHeaderProps = {} } = props;
55
56
  // HOOKS
56
57
  const { scEvent } = (0, react_core_1.useSCFetchEvent)({ id: eventId, event });
57
- if (!scEvent) {
58
+ const scUserContext = (0, react_core_1.useSCUser)();
59
+ if (scUserContext.user === undefined ||
60
+ !scEvent ||
61
+ (scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
62
+ scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED) {
58
63
  return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
59
64
  }
60
65
  return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className) }, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.EventHeader, Object.assign({ event: scEvent }, EventHeaderProps)), (0, jsx_runtime_1.jsx)(EventFeed_1.default, Object.assign({ className: classes.feed, event: scEvent, widgets: widgets, FeedObjectProps: FeedObjectProps, FeedSidebarProps: FeedSidebarProps }, EventFeedProps))] })));
@@ -91,12 +91,12 @@ function EventFeed(inProps) {
91
91
  // REF
92
92
  const feedRef = (0, react_1.useRef)();
93
93
  // Hooks
94
- const { scEvent, setSCEvent } = (0, react_core_1.useSCFetchEvent)({ id: eventId, event });
94
+ const { scEvent } = (0, react_core_1.useSCFetchEvent)({ id: eventId, event });
95
95
  // HANDLERS
96
96
  const handleComposerSuccess = (feedObject) => {
97
97
  var _a;
98
98
  enqueueSnackbar((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composerIconButton.composer.success", defaultMessage: "ui.composerIconButton.composer.success" }), {
99
- action: (snackbarId) => ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes[`${feedObject.type.toUpperCase()}_ROUTE_NAME`], react_ui_1.ContributionUtils.getRouteData(feedObject)) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composerIconButton.composer.viewContribute", defaultMessage: "ui.composerIconButton.composer.viewContribute" }) }))),
99
+ action: () => ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes[`${feedObject.type.toUpperCase()}_ROUTE_NAME`], react_ui_1.ContributionUtils.getRouteData(feedObject)) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.composerIconButton.composer.viewContribute", defaultMessage: "ui.composerIconButton.composer.viewContribute" }) }))),
100
100
  variant: 'success',
101
101
  autoHideDuration: 7000
102
102
  });
@@ -114,16 +114,19 @@ function EventFeed(inProps) {
114
114
  // WIDGETS
115
115
  const _widgets = (0, react_1.useMemo)(() => widgets.map((w) => {
116
116
  if (scEvent) {
117
- return Object.assign(Object.assign({}, w), { componentProps: Object.assign(Object.assign({}, w.componentProps), { eventId: scEvent.id }) });
117
+ return Object.assign(Object.assign({}, w), { componentProps: Object.assign(Object.assign({}, w.componentProps), { event: scEvent }) });
118
118
  }
119
119
  return w;
120
120
  }), [widgets, scEvent]);
121
- if (!scEvent || (scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
121
+ if (scUserContext.user === undefined ||
122
+ !scEvent ||
123
+ scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED ||
124
+ (scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
125
+ (scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
122
126
  return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
123
127
  }
124
128
  else if (scEvent.privacy === types_1.SCEventPrivacyType.PRIVATE &&
125
129
  scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.SUBSCRIBED &&
126
- scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.INVITED &&
127
130
  scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.GOING &&
128
131
  scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.NOT_GOING) {
129
132
  return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ mt: 2 }, { children: (0, jsx_runtime_1.jsx)(react_ui_1.EventInfoWidget, { className: classes.root, event: scEvent }) })));
@@ -142,7 +145,6 @@ function EventFeed(inProps) {
142
145
  ((!scUserContext.user && scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC) ||
143
146
  (scUserContext.user &&
144
147
  (scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.SUBSCRIBED ||
145
- scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED ||
146
148
  scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.GOING ||
147
149
  scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.NOT_GOING)))) && ((0, jsx_runtime_1.jsx)(react_ui_1.InlineComposerWidget, { onSuccess: handleComposerSuccess, defaultValue: { event: scEvent }, label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "templates.eventFeed.composer.label", defaultMessage: "templates.eventFeed.composer.label" }), feedType: types_1.SCFeedTypologyType.EVENT }))] }), CustomAdvProps: { position: types_1.SCCustomAdvPosition.POSITION_FEED, groupsId: [scEvent.id] }, enabledCustomAdvPositions: [
148
150
  types_1.SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
@@ -2,7 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { styled } from '@mui/material/styles';
3
3
  import { Box } from '@mui/material';
4
4
  import { EventHeader } from '@selfcommunity/react-ui';
5
- import { useSCFetchEvent } from '@selfcommunity/react-core';
5
+ import { useSCFetchEvent, useSCUser } from '@selfcommunity/react-core';
6
+ import { SCEventPrivacyType, SCEventSubscriptionStatusType } from '@selfcommunity/types';
6
7
  import EventSkeletonTemplate from './Skeleton';
7
8
  import { useThemeProps } from '@mui/system';
8
9
  import classNames from 'classnames';
@@ -51,7 +52,11 @@ export default function Event(inProps) {
51
52
  const { id = 'event', className, event, eventId, widgets, FeedObjectProps, FeedSidebarProps, EventFeedProps = {}, EventHeaderProps = {} } = props;
52
53
  // HOOKS
53
54
  const { scEvent } = useSCFetchEvent({ id: eventId, event });
54
- if (!scEvent) {
55
+ const scUserContext = useSCUser();
56
+ if (scUserContext.user === undefined ||
57
+ !scEvent ||
58
+ (scEvent.privacy === SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
59
+ scEvent.subscription_status === SCEventSubscriptionStatusType.INVITED) {
55
60
  return _jsx(EventSkeletonTemplate, {});
56
61
  }
57
62
  return (_jsxs(Root, Object.assign({ id: id, className: classNames(classes.root, className) }, { children: [_jsx(EventHeader, Object.assign({ event: scEvent }, EventHeaderProps)), _jsx(EventFeed, Object.assign({ className: classes.feed, event: scEvent, widgets: widgets, FeedObjectProps: FeedObjectProps, FeedSidebarProps: FeedSidebarProps }, EventFeedProps))] })));
@@ -88,12 +88,12 @@ export default function EventFeed(inProps) {
88
88
  // REF
89
89
  const feedRef = useRef();
90
90
  // Hooks
91
- const { scEvent, setSCEvent } = useSCFetchEvent({ id: eventId, event });
91
+ const { scEvent } = useSCFetchEvent({ id: eventId, event });
92
92
  // HANDLERS
93
93
  const handleComposerSuccess = (feedObject) => {
94
94
  var _a;
95
95
  enqueueSnackbar(_jsx(FormattedMessage, { id: "ui.composerIconButton.composer.success", defaultMessage: "ui.composerIconButton.composer.success" }), {
96
- action: (snackbarId) => (_jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${feedObject.type.toUpperCase()}_ROUTE_NAME`], ContributionUtils.getRouteData(feedObject)) }, { children: _jsx(FormattedMessage, { id: "ui.composerIconButton.composer.viewContribute", defaultMessage: "ui.composerIconButton.composer.viewContribute" }) }))),
96
+ action: () => (_jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${feedObject.type.toUpperCase()}_ROUTE_NAME`], ContributionUtils.getRouteData(feedObject)) }, { children: _jsx(FormattedMessage, { id: "ui.composerIconButton.composer.viewContribute", defaultMessage: "ui.composerIconButton.composer.viewContribute" }) }))),
97
97
  variant: 'success',
98
98
  autoHideDuration: 7000
99
99
  });
@@ -111,16 +111,19 @@ export default function EventFeed(inProps) {
111
111
  // WIDGETS
112
112
  const _widgets = useMemo(() => widgets.map((w) => {
113
113
  if (scEvent) {
114
- return Object.assign(Object.assign({}, w), { componentProps: Object.assign(Object.assign({}, w.componentProps), { eventId: scEvent.id }) });
114
+ return Object.assign(Object.assign({}, w), { componentProps: Object.assign(Object.assign({}, w.componentProps), { event: scEvent }) });
115
115
  }
116
116
  return w;
117
117
  }), [widgets, scEvent]);
118
- if (!scEvent || (scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
118
+ if (scUserContext.user === undefined ||
119
+ !scEvent ||
120
+ scEvent.subscription_status === SCEventSubscriptionStatusType.INVITED ||
121
+ (scEvent.privacy === SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
122
+ (scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
119
123
  return _jsx(EventFeedSkeleton, {});
120
124
  }
121
125
  else if (scEvent.privacy === SCEventPrivacyType.PRIVATE &&
122
126
  scEvent.subscription_status !== SCEventSubscriptionStatusType.SUBSCRIBED &&
123
- scEvent.subscription_status !== SCEventSubscriptionStatusType.INVITED &&
124
127
  scEvent.subscription_status !== SCEventSubscriptionStatusType.GOING &&
125
128
  scEvent.subscription_status !== SCEventSubscriptionStatusType.NOT_GOING) {
126
129
  return (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(EventInfoWidget, { className: classes.root, event: scEvent }) })));
@@ -139,7 +142,6 @@ export default function EventFeed(inProps) {
139
142
  ((!scUserContext.user && scEvent.privacy === SCEventPrivacyType.PUBLIC) ||
140
143
  (scUserContext.user &&
141
144
  (scEvent.subscription_status === SCEventSubscriptionStatusType.SUBSCRIBED ||
142
- scEvent.subscription_status === SCEventSubscriptionStatusType.INVITED ||
143
145
  scEvent.subscription_status === SCEventSubscriptionStatusType.GOING ||
144
146
  scEvent.subscription_status === SCEventSubscriptionStatusType.NOT_GOING)))) && (_jsx(InlineComposerWidget, { onSuccess: handleComposerSuccess, defaultValue: { event: scEvent }, label: _jsx(FormattedMessage, { id: "templates.eventFeed.composer.label", defaultMessage: "templates.eventFeed.composer.label" }), feedType: SCFeedTypologyType.EVENT }))] }), CustomAdvProps: { position: SCCustomAdvPosition.POSITION_FEED, groupsId: [scEvent.id] }, enabledCustomAdvPositions: [
145
147
  SCCustomAdvPosition.POSITION_FEED_SIDEBAR,