@selfcommunity/react-ui 0.7.9-alpha.10 → 0.7.9-alpha.12

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.
@@ -35,10 +35,10 @@ export interface GroupHeaderProps {
35
35
  */
36
36
  ChangeCoverProps?: ChangeGroupCoverProps;
37
37
  /**
38
- * Props to spread category button followed
38
+ * Props to spread group button followed
39
39
  * @default {}
40
40
  */
41
- GroupSubscribeButtonProps?: Pick<GroupSubscribeButtonProps, Exclude<keyof GroupSubscribeButtonProps, 'group' | 'onSubscribe'>>;
41
+ GroupSubscribeButtonProps?: GroupSubscribeButtonProps;
42
42
  /**
43
43
  * Props to spread to the group memebers button
44
44
  * @default {}
@@ -173,13 +173,14 @@ function GroupRequestsWidget(inProps) {
173
173
  };
174
174
  const handleSubscribeAction = (0, react_1.useMemo)(() => (userId) => {
175
175
  const newRequests = [...state.results];
176
- const index = newRequests.findIndex((u) => u.id === userId);
177
- if (index !== -1) {
178
- dispatch({ type: widget_1.actionWidgetTypes.SET_RESULTS, payload: { results: newRequests } });
179
- }
176
+ const _updated = newRequests.findIndex((u) => u.id !== userId);
177
+ dispatch({
178
+ type: widget_1.actionWidgetTypes.SET_RESULTS,
179
+ payload: { results: newRequests.length > 1 ? _updated : [] }
180
+ });
180
181
  }, [dispatch, state.count, state.results]);
181
182
  // RENDER
182
- if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count) {
183
+ if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count || !state.results.length) {
183
184
  return react_1.default.createElement(HiddenPlaceholder_1.default, null);
184
185
  }
185
186
  if (!state.initialized) {
@@ -22,6 +22,10 @@ export interface GroupsProps {
22
22
  * @default null
23
23
  */
24
24
  prefetchedGroups?: SCGroupType[];
25
+ /** If true, it means that the endpoint fetches all groups available
26
+ * @default null
27
+ */
28
+ general?: boolean;
25
29
  /**
26
30
  * Other props
27
31
  */
@@ -64,7 +64,7 @@ function Groups(inProps) {
64
64
  props: inProps,
65
65
  name: constants_1.PREFIX
66
66
  });
67
- const { endpoint, className, GroupComponentProps = { variant: 'outlined', ButtonBaseProps: { disableRipple: true, component: material_1.Box } }, prefetchedGroups = [] } = props, rest = tslib_1.__rest(props, ["endpoint", "className", "GroupComponentProps", "prefetchedGroups"]);
67
+ const { endpoint, className, GroupComponentProps = { variant: 'outlined', ButtonBaseProps: { disableRipple: true, component: material_1.Box } }, prefetchedGroups = [], general } = props, rest = tslib_1.__rest(props, ["endpoint", "className", "GroupComponentProps", "prefetchedGroups", "general"]);
68
68
  // STATE
69
69
  const [groups, setGroups] = (0, react_1.useState)([]);
70
70
  const [loading, setLoading] = (0, react_1.useState)(true);
@@ -113,6 +113,13 @@ function Groups(inProps) {
113
113
  });
114
114
  }
115
115
  }, [contentAvailability, authUserId, prefetchedGroups.length]);
116
+ const handleSubscribe = (group) => {
117
+ if (general) {
118
+ const newGroups = [...groups];
119
+ const _updated = newGroups.filter((g) => g.id !== group.id);
120
+ setGroups(_updated);
121
+ }
122
+ };
116
123
  // RENDER
117
124
  if (!contentAvailability && !scUserContext.user) {
118
125
  return react_1.default.createElement(HiddenPlaceholder_1.default, null);
@@ -122,7 +129,7 @@ function Groups(inProps) {
122
129
  react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groups.noGroups.title", defaultMessage: "ui.groups.noGroups.title" })),
123
130
  react_1.default.createElement(material_1.Typography, { variant: "body1" },
124
131
  react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groups.noGroups.subtitle", defaultMessage: "ui.groups.noGroups.subtitle" })))) : (react_1.default.createElement(react_1.default.Fragment, null, groups.map((group) => (react_1.default.createElement(material_1.Grid, { item: true, xs: 12, sm: 8, md: 6, key: group.id, className: classes.item },
125
- react_1.default.createElement(Group_1.default, Object.assign({ group: group, groupId: group.id }, GroupComponentProps)))))))))));
132
+ react_1.default.createElement(Group_1.default, Object.assign({ group: group, groupId: group.id, groupSubscribeButtonProps: { onSubscribe: handleSubscribe } }, GroupComponentProps)))))))))));
126
133
  return (react_1.default.createElement(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest), content));
127
134
  }
128
135
  exports.default = Groups;
@@ -35,10 +35,10 @@ export interface GroupHeaderProps {
35
35
  */
36
36
  ChangeCoverProps?: ChangeGroupCoverProps;
37
37
  /**
38
- * Props to spread category button followed
38
+ * Props to spread group button followed
39
39
  * @default {}
40
40
  */
41
- GroupSubscribeButtonProps?: Pick<GroupSubscribeButtonProps, Exclude<keyof GroupSubscribeButtonProps, 'group' | 'onSubscribe'>>;
41
+ GroupSubscribeButtonProps?: GroupSubscribeButtonProps;
42
42
  /**
43
43
  * Props to spread to the group memebers button
44
44
  * @default {}
@@ -171,13 +171,14 @@ export default function GroupRequestsWidget(inProps) {
171
171
  };
172
172
  const handleSubscribeAction = useMemo(() => (userId) => {
173
173
  const newRequests = [...state.results];
174
- const index = newRequests.findIndex((u) => u.id === userId);
175
- if (index !== -1) {
176
- dispatch({ type: actionWidgetTypes.SET_RESULTS, payload: { results: newRequests } });
177
- }
174
+ const _updated = newRequests.findIndex((u) => u.id !== userId);
175
+ dispatch({
176
+ type: actionWidgetTypes.SET_RESULTS,
177
+ payload: { results: newRequests.length > 1 ? _updated : [] }
178
+ });
178
179
  }, [dispatch, state.count, state.results]);
179
180
  // RENDER
180
- if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count) {
181
+ if ((!state.count && state.initialized) || (!contentAvailability && !isGroupAdmin) || !scGroup || !state.count || !state.results.length) {
181
182
  return React.createElement(HiddenPlaceholder, null);
182
183
  }
183
184
  if (!state.initialized) {
@@ -22,6 +22,10 @@ export interface GroupsProps {
22
22
  * @default null
23
23
  */
24
24
  prefetchedGroups?: SCGroupType[];
25
+ /** If true, it means that the endpoint fetches all groups available
26
+ * @default null
27
+ */
28
+ general?: boolean;
25
29
  /**
26
30
  * Other props
27
31
  */
@@ -62,7 +62,7 @@ export default function Groups(inProps) {
62
62
  props: inProps,
63
63
  name: PREFIX
64
64
  });
65
- const { endpoint, className, GroupComponentProps = { variant: 'outlined', ButtonBaseProps: { disableRipple: true, component: Box } }, prefetchedGroups = [] } = props, rest = __rest(props, ["endpoint", "className", "GroupComponentProps", "prefetchedGroups"]);
65
+ const { endpoint, className, GroupComponentProps = { variant: 'outlined', ButtonBaseProps: { disableRipple: true, component: Box } }, prefetchedGroups = [], general } = props, rest = __rest(props, ["endpoint", "className", "GroupComponentProps", "prefetchedGroups", "general"]);
66
66
  // STATE
67
67
  const [groups, setGroups] = useState([]);
68
68
  const [loading, setLoading] = useState(true);
@@ -111,6 +111,13 @@ export default function Groups(inProps) {
111
111
  });
112
112
  }
113
113
  }, [contentAvailability, authUserId, prefetchedGroups.length]);
114
+ const handleSubscribe = (group) => {
115
+ if (general) {
116
+ const newGroups = [...groups];
117
+ const _updated = newGroups.filter((g) => g.id !== group.id);
118
+ setGroups(_updated);
119
+ }
120
+ };
114
121
  // RENDER
115
122
  if (!contentAvailability && !scUserContext.user) {
116
123
  return React.createElement(HiddenPlaceholder, null);
@@ -120,6 +127,6 @@ export default function Groups(inProps) {
120
127
  React.createElement(FormattedMessage, { id: "ui.groups.noGroups.title", defaultMessage: "ui.groups.noGroups.title" })),
121
128
  React.createElement(Typography, { variant: "body1" },
122
129
  React.createElement(FormattedMessage, { id: "ui.groups.noGroups.subtitle", defaultMessage: "ui.groups.noGroups.subtitle" })))) : (React.createElement(React.Fragment, null, groups.map((group) => (React.createElement(Grid, { item: true, xs: 12, sm: 8, md: 6, key: group.id, className: classes.item },
123
- React.createElement(Group, Object.assign({ group: group, groupId: group.id }, GroupComponentProps)))))))))));
130
+ React.createElement(Group, Object.assign({ group: group, groupId: group.id, groupSubscribeButtonProps: { onSubscribe: handleSubscribe } }, GroupComponentProps)))))))))));
124
131
  return (React.createElement(Root, Object.assign({ className: classNames(classes.root, className) }, rest), content));
125
132
  }