@selfcommunity/react-templates 0.4.8-payments.181 → 0.4.8-payments.183

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.
@@ -84,14 +84,27 @@ function EventFeed(inProps) {
84
84
  name: constants_1.PREFIX
85
85
  });
86
86
  const { id = 'event_feed', className, event, eventId, widgets = WIDGETS, FeedObjectProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
87
+ // STATUS
88
+ const [status, setStatus] = (0, react_1.useState)(undefined);
87
89
  // CONTEXT
88
90
  const scRoutingContext = (0, react_core_1.useSCRouting)();
89
91
  const scUserContext = (0, react_core_1.useSCUser)();
92
+ const scEventsManager = scUserContext.managers.events;
90
93
  const { enqueueSnackbar } = (0, notistack_1.useSnackbar)();
94
+ const { scEvent } = (0, react_core_1.useSCFetchEvent)({ id: eventId, event });
91
95
  // REF
92
96
  const feedRef = (0, react_1.useRef)();
93
- // Hooks
94
- const { scEvent } = (0, react_core_1.useSCFetchEvent)({ id: eventId, event });
97
+ // CONST
98
+ const authUserId = scUserContext.user ? scUserContext.user.id : null;
99
+ (0, react_1.useEffect)(() => {
100
+ /**
101
+ * Call scEventsManager.subscriptionStatus inside an effect
102
+ * to avoid warning rendering child during update parent state
103
+ */
104
+ if (authUserId) {
105
+ setStatus(scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus(scEvent));
106
+ }
107
+ }, [authUserId, scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus, scEvent]);
95
108
  // HANDLERS
96
109
  const handleComposerSuccess = (feedObject) => {
97
110
  var _a;
@@ -119,17 +132,17 @@ function EventFeed(inProps) {
119
132
  return w;
120
133
  }), [widgets, scEvent]);
121
134
  if (scUserContext.user === undefined ||
135
+ (scUserContext.user && status === undefined) ||
122
136
  !scEvent ||
123
- (scUserContext.user &&
124
- ((scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
125
- scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.INVITED)) ||
137
+ (scUserContext.user && scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC && !status) ||
126
138
  (scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
127
139
  return (0, jsx_runtime_1.jsx)(Skeleton_1.default, {});
128
140
  }
129
141
  else if (scEvent.privacy === types_1.SCEventPrivacyType.PRIVATE &&
130
- scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.SUBSCRIBED &&
131
- scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.GOING &&
132
- scEvent.subscription_status !== types_1.SCEventSubscriptionStatusType.NOT_GOING) {
142
+ (status === types_1.SCEventSubscriptionStatusType.INVITED ||
143
+ (status !== types_1.SCEventSubscriptionStatusType.SUBSCRIBED &&
144
+ status !== types_1.SCEventSubscriptionStatusType.GOING &&
145
+ status !== types_1.SCEventSubscriptionStatusType.NOT_GOING))) {
133
146
  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 }) })));
134
147
  }
135
148
  return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), id: id, ref: feedRef, endpoint: Object.assign(Object.assign({}, api_services_1.Endpoints.GetEventFeed), { url: () => api_services_1.Endpoints.GetEventFeed.url({ id: scEvent.id }) }), widgets: _widgets, ItemComponent: react_ui_1.FeedObject, itemPropsGenerator: (scUser, item) => {
@@ -145,9 +158,9 @@ function EventFeed(inProps) {
145
158
  }, FeedSidebarProps: FeedSidebarProps, HeaderComponent: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_ui_1.EventInfoWidget, { className: classes.root, event: scEvent }), Boolean(scEvent &&
146
159
  ((!scUserContext.user && scEvent.privacy === types_1.SCEventPrivacyType.PUBLIC) ||
147
160
  (scUserContext.user &&
148
- (scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.SUBSCRIBED ||
149
- scEvent.subscription_status === types_1.SCEventSubscriptionStatusType.GOING ||
150
- 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: [
161
+ (status === types_1.SCEventSubscriptionStatusType.SUBSCRIBED ||
162
+ status === types_1.SCEventSubscriptionStatusType.GOING ||
163
+ 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: [
151
164
  types_1.SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
152
165
  types_1.SCCustomAdvPosition.POSITION_FEED,
153
166
  types_1.SCCustomAdvPosition.POSITION_BELOW_TOPBAR
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useMemo, useRef } from 'react';
2
+ import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { styled } from '@mui/material/styles';
4
4
  import { ContributionUtils, EventInfoWidget, EventLocationWidget, EventMediaWidget, EventMembersWidget, Feed, FeedObject, FeedObjectSkeleton, InlineComposerWidget, RelatedEventsWidget, SCFeedObjectTemplateType } from '@selfcommunity/react-ui';
5
5
  import { Endpoints } from '@selfcommunity/api-services';
@@ -81,14 +81,27 @@ export default function EventFeed(inProps) {
81
81
  name: PREFIX
82
82
  });
83
83
  const { id = 'event_feed', className, event, eventId, widgets = WIDGETS, FeedObjectProps = {}, FeedSidebarProps = null, FeedProps = {} } = props;
84
+ // STATUS
85
+ const [status, setStatus] = useState(undefined);
84
86
  // CONTEXT
85
87
  const scRoutingContext = useSCRouting();
86
88
  const scUserContext = useSCUser();
89
+ const scEventsManager = scUserContext.managers.events;
87
90
  const { enqueueSnackbar } = useSnackbar();
91
+ const { scEvent } = useSCFetchEvent({ id: eventId, event });
88
92
  // REF
89
93
  const feedRef = useRef();
90
- // Hooks
91
- const { scEvent } = useSCFetchEvent({ id: eventId, event });
94
+ // CONST
95
+ const authUserId = scUserContext.user ? scUserContext.user.id : null;
96
+ useEffect(() => {
97
+ /**
98
+ * Call scEventsManager.subscriptionStatus inside an effect
99
+ * to avoid warning rendering child during update parent state
100
+ */
101
+ if (authUserId) {
102
+ setStatus(scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus(scEvent));
103
+ }
104
+ }, [authUserId, scEventsManager === null || scEventsManager === void 0 ? void 0 : scEventsManager.subscriptionStatus, scEvent]);
92
105
  // HANDLERS
93
106
  const handleComposerSuccess = (feedObject) => {
94
107
  var _a;
@@ -116,17 +129,17 @@ export default function EventFeed(inProps) {
116
129
  return w;
117
130
  }), [widgets, scEvent]);
118
131
  if (scUserContext.user === undefined ||
132
+ (scUserContext.user && status === undefined) ||
119
133
  !scEvent ||
120
- (scUserContext.user &&
121
- ((scEvent.privacy === SCEventPrivacyType.PUBLIC && !scEvent.subscription_status) ||
122
- scEvent.subscription_status === SCEventSubscriptionStatusType.INVITED)) ||
134
+ (scUserContext.user && scEvent.privacy === SCEventPrivacyType.PUBLIC && !status) ||
123
135
  (scEvent && ((eventId !== undefined && scEvent.id !== eventId) || (event && scEvent.id !== event.id)))) {
124
136
  return _jsx(EventFeedSkeleton, {});
125
137
  }
126
138
  else if (scEvent.privacy === SCEventPrivacyType.PRIVATE &&
127
- scEvent.subscription_status !== SCEventSubscriptionStatusType.SUBSCRIBED &&
128
- scEvent.subscription_status !== SCEventSubscriptionStatusType.GOING &&
129
- scEvent.subscription_status !== SCEventSubscriptionStatusType.NOT_GOING) {
139
+ (status === SCEventSubscriptionStatusType.INVITED ||
140
+ (status !== SCEventSubscriptionStatusType.SUBSCRIBED &&
141
+ status !== SCEventSubscriptionStatusType.GOING &&
142
+ status !== SCEventSubscriptionStatusType.NOT_GOING))) {
130
143
  return (_jsx(Box, Object.assign({ mt: 2 }, { children: _jsx(EventInfoWidget, { className: classes.root, event: scEvent }) })));
131
144
  }
132
145
  return (_jsx(Root, Object.assign({ className: classNames(classes.root, className), id: id, ref: feedRef, endpoint: Object.assign(Object.assign({}, Endpoints.GetEventFeed), { url: () => Endpoints.GetEventFeed.url({ id: scEvent.id }) }), widgets: _widgets, ItemComponent: FeedObject, itemPropsGenerator: (scUser, item) => {
@@ -142,9 +155,9 @@ export default function EventFeed(inProps) {
142
155
  }, FeedSidebarProps: FeedSidebarProps, HeaderComponent: _jsxs(_Fragment, { children: [_jsx(EventInfoWidget, { className: classes.root, event: scEvent }), Boolean(scEvent &&
143
156
  ((!scUserContext.user && scEvent.privacy === SCEventPrivacyType.PUBLIC) ||
144
157
  (scUserContext.user &&
145
- (scEvent.subscription_status === SCEventSubscriptionStatusType.SUBSCRIBED ||
146
- scEvent.subscription_status === SCEventSubscriptionStatusType.GOING ||
147
- 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: [
158
+ (status === SCEventSubscriptionStatusType.SUBSCRIBED ||
159
+ status === SCEventSubscriptionStatusType.GOING ||
160
+ 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: [
148
161
  SCCustomAdvPosition.POSITION_FEED_SIDEBAR,
149
162
  SCCustomAdvPosition.POSITION_FEED,
150
163
  SCCustomAdvPosition.POSITION_BELOW_TOPBAR