@selfcommunity/react-ui 0.7.9-alpha.4 → 0.7.9-alpha.41

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.
Files changed (132) hide show
  1. package/lib/cjs/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
  2. package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
  3. package/lib/cjs/components/Composer/Attributes/Attributes.js +3 -3
  4. package/lib/cjs/components/Composer/Composer.js +3 -5
  5. package/lib/cjs/components/Composer/Content/ContentPost/ContentPost.js +4 -3
  6. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -2
  7. package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +18 -6
  8. package/lib/cjs/components/EditGroupButton/EditGroupButton.js +4 -0
  9. package/lib/cjs/components/FeedObject/FeedObject.d.ts +1 -0
  10. package/lib/cjs/components/FeedObject/FeedObject.js +23 -6
  11. package/lib/cjs/components/FeedUpdatesWidget/FeedUpdatesWidget.js +1 -1
  12. package/lib/cjs/components/Group/Group.js +9 -3
  13. package/lib/cjs/components/GroupForm/GroupForm.js +31 -9
  14. package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +6 -5
  15. package/lib/cjs/components/GroupHeader/GroupHeader.js +52 -11
  16. package/lib/cjs/components/GroupHeader/Skeleton.d.ts +2 -4
  17. package/lib/cjs/components/GroupHeader/Skeleton.js +10 -10
  18. package/lib/cjs/components/GroupInfoWidget/GroupInfoWidget.js +40 -7
  19. package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +8 -7
  20. package/lib/cjs/components/GroupInvitedWidget/GroupInvitedWidget.d.ts +74 -0
  21. package/lib/cjs/components/GroupInvitedWidget/GroupInvitedWidget.js +197 -0
  22. package/lib/cjs/components/GroupInvitedWidget/Skeleton.d.ts +22 -0
  23. package/lib/cjs/components/GroupInvitedWidget/Skeleton.js +38 -0
  24. package/lib/cjs/components/GroupInvitedWidget/constants.d.ts +1 -0
  25. package/lib/cjs/components/GroupInvitedWidget/constants.js +4 -0
  26. package/lib/cjs/components/GroupInvitedWidget/index.d.ts +4 -0
  27. package/lib/cjs/components/GroupInvitedWidget/index.js +8 -0
  28. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
  29. package/lib/cjs/components/GroupMembersButton/GroupMembersButton.js +7 -2
  30. package/lib/cjs/components/GroupMembersWidget/GroupMembersWidget.js +25 -4
  31. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +11 -5
  32. package/lib/cjs/components/GroupRequestsWidget/GroupRequestsWidget.js +18 -7
  33. package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
  34. package/lib/cjs/components/GroupSettingsIconButton/GroupSettingsIconButton.js +145 -0
  35. package/lib/cjs/components/GroupSettingsIconButton/index.d.ts +3 -0
  36. package/lib/cjs/components/GroupSettingsIconButton/index.js +5 -0
  37. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
  38. package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +31 -10
  39. package/lib/cjs/components/Groups/Groups.d.ts +28 -13
  40. package/lib/cjs/components/Groups/Groups.js +71 -89
  41. package/lib/cjs/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
  42. package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
  43. package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
  44. package/lib/cjs/components/Notification/Group/Group.d.ts +15 -0
  45. package/lib/cjs/components/Notification/Group/Group.js +78 -0
  46. package/lib/cjs/components/Notification/Group/index.d.ts +3 -0
  47. package/lib/cjs/components/Notification/Group/index.js +5 -0
  48. package/lib/cjs/components/Notification/Notification.js +31 -1
  49. package/lib/cjs/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
  50. package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
  51. package/lib/cjs/components/PrivateMessageComponent/PrivateMessageComponent.js +10 -7
  52. package/lib/cjs/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
  53. package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
  54. package/lib/cjs/components/PrivateMessageSnippets/PrivateMessageSnippets.js +24 -6
  55. package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
  56. package/lib/cjs/components/PrivateMessageThread/PrivateMessageThread.js +45 -20
  57. package/lib/cjs/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
  58. package/lib/cjs/components/SnippetNotifications/SnippetNotifications.js +7 -0
  59. package/lib/cjs/components/ToastNotifications/ToastNotifications.js +7 -0
  60. package/lib/cjs/components/User/User.d.ts +5 -0
  61. package/lib/cjs/components/User/User.js +5 -4
  62. package/lib/cjs/constants/PubSub.d.ts +27 -0
  63. package/lib/cjs/constants/PubSub.js +21 -0
  64. package/lib/cjs/index.d.ts +5 -2
  65. package/lib/cjs/index.js +12 -4
  66. package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
  67. package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +32 -11
  68. package/lib/esm/components/Composer/Attributes/Attributes.js +3 -3
  69. package/lib/esm/components/Composer/Composer.js +3 -5
  70. package/lib/esm/components/Composer/Content/ContentPost/ContentPost.js +4 -3
  71. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -2
  72. package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +18 -6
  73. package/lib/esm/components/EditGroupButton/EditGroupButton.js +5 -1
  74. package/lib/esm/components/FeedObject/FeedObject.d.ts +1 -0
  75. package/lib/esm/components/FeedObject/FeedObject.js +24 -7
  76. package/lib/esm/components/FeedUpdatesWidget/FeedUpdatesWidget.js +1 -1
  77. package/lib/esm/components/Group/Group.js +11 -5
  78. package/lib/esm/components/GroupForm/GroupForm.js +31 -9
  79. package/lib/esm/components/GroupHeader/GroupHeader.d.ts +6 -5
  80. package/lib/esm/components/GroupHeader/GroupHeader.js +54 -13
  81. package/lib/esm/components/GroupHeader/Skeleton.d.ts +2 -4
  82. package/lib/esm/components/GroupHeader/Skeleton.js +10 -10
  83. package/lib/esm/components/GroupInfoWidget/GroupInfoWidget.js +40 -7
  84. package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +8 -7
  85. package/lib/esm/components/GroupInvitedWidget/GroupInvitedWidget.d.ts +74 -0
  86. package/lib/esm/components/GroupInvitedWidget/GroupInvitedWidget.js +194 -0
  87. package/lib/esm/components/GroupInvitedWidget/Skeleton.d.ts +22 -0
  88. package/lib/esm/components/GroupInvitedWidget/Skeleton.js +34 -0
  89. package/lib/esm/components/GroupInvitedWidget/constants.d.ts +1 -0
  90. package/lib/esm/components/GroupInvitedWidget/constants.js +1 -0
  91. package/lib/esm/components/GroupInvitedWidget/index.d.ts +4 -0
  92. package/lib/esm/components/GroupInvitedWidget/index.js +4 -0
  93. package/lib/esm/components/GroupMembersButton/GroupMembersButton.d.ts +5 -0
  94. package/lib/esm/components/GroupMembersButton/GroupMembersButton.js +8 -3
  95. package/lib/esm/components/GroupMembersWidget/GroupMembersWidget.js +26 -5
  96. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.d.ts +11 -5
  97. package/lib/esm/components/GroupRequestsWidget/GroupRequestsWidget.js +18 -7
  98. package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.d.ts +48 -0
  99. package/lib/esm/components/GroupSettingsIconButton/GroupSettingsIconButton.js +142 -0
  100. package/lib/esm/components/GroupSettingsIconButton/index.d.ts +3 -0
  101. package/lib/esm/components/GroupSettingsIconButton/index.js +2 -0
  102. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.d.ts +8 -3
  103. package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +32 -11
  104. package/lib/esm/components/Groups/Groups.d.ts +28 -13
  105. package/lib/esm/components/Groups/Groups.js +76 -94
  106. package/lib/esm/components/NavigationMenuIconButton/NavigationMenuIconButton.js +1 -1
  107. package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.d.ts +4 -0
  108. package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +2 -3
  109. package/lib/esm/components/Notification/Group/Group.d.ts +15 -0
  110. package/lib/esm/components/Notification/Group/Group.js +75 -0
  111. package/lib/esm/components/Notification/Group/index.d.ts +3 -0
  112. package/lib/esm/components/Notification/Group/index.js +2 -0
  113. package/lib/esm/components/Notification/Notification.js +31 -1
  114. package/lib/esm/components/Notification/PrivateMessage/PrivateMessage.js +16 -5
  115. package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.d.ts +1 -1
  116. package/lib/esm/components/PrivateMessageComponent/PrivateMessageComponent.js +11 -8
  117. package/lib/esm/components/PrivateMessageSnippetItem/PrivateMessageSnippetItem.js +11 -6
  118. package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.d.ts +3 -3
  119. package/lib/esm/components/PrivateMessageSnippets/PrivateMessageSnippets.js +26 -8
  120. package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.d.ts +6 -1
  121. package/lib/esm/components/PrivateMessageThread/PrivateMessageThread.js +47 -22
  122. package/lib/esm/components/SearchAutocomplete/SearchAutocomplete.js +22 -5
  123. package/lib/esm/components/SnippetNotifications/SnippetNotifications.js +7 -0
  124. package/lib/esm/components/ToastNotifications/ToastNotifications.js +7 -0
  125. package/lib/esm/components/User/User.d.ts +5 -0
  126. package/lib/esm/components/User/User.js +5 -4
  127. package/lib/esm/constants/PubSub.d.ts +27 -0
  128. package/lib/esm/constants/PubSub.js +18 -0
  129. package/lib/esm/index.d.ts +5 -2
  130. package/lib/esm/index.js +7 -4
  131. package/lib/umd/react-ui.js +1 -1
  132. package/package.json +6 -6
@@ -1,31 +1,46 @@
1
+ import { SCGroupType } from '@selfcommunity/types';
1
2
  import { EndpointType } from '@selfcommunity/api-services';
2
- import { CacheStrategies } from '@selfcommunity/utils';
3
3
  import { GroupProps } from '../Group';
4
4
  export interface GroupsProps {
5
+ /**
6
+ * Overrides or extends the styles applied to the component.
7
+ * @default null
8
+ */
9
+ className?: string;
5
10
  /**
6
11
  * Endpoint to call
7
12
  */
8
- endpoint: EndpointType;
13
+ endpoint?: EndpointType;
9
14
  /**
10
- * Hides this component
11
- * @default false
15
+ * Props to spread to single group object
16
+ * @default {variant: 'outlined', ButtonBaseProps: {disableRipple: 'true'}}
12
17
  */
13
- autoHide?: boolean;
18
+ GroupComponentProps?: GroupProps;
14
19
  /**
15
- * Limit the number of users to show
20
+ * Prefetch groups. Useful for SSR.
21
+ * Use this to init the component with groups
22
+ * @default null
23
+ */
24
+ prefetchedGroups?: SCGroupType[];
25
+ /** If true, it means that the endpoint fetches all groups available
26
+ * @default null
27
+ */
28
+ general?: boolean;
29
+ /**
30
+ * Show/Hide filters
16
31
  * @default false
17
32
  */
18
- limit?: number;
33
+ showFilters?: boolean;
19
34
  /**
20
- * Caching strategies
21
- * @default CacheStrategies.CACHE_FIRST
35
+ * Override filter func
36
+ * @default null
22
37
  */
23
- cacheStrategy?: CacheStrategies;
38
+ handleFilterGroups?: (groups: SCGroupType[]) => SCGroupType[];
24
39
  /**
25
- * Props to spread to single group object
26
- * @default empty object
40
+ * Filters component
41
+ * @param props
27
42
  */
28
- GroupProps?: GroupProps;
43
+ filters?: JSX.Element;
29
44
  /**
30
45
  * Other props
31
46
  */
@@ -1,11 +1,10 @@
1
- import { __rest } from "tslib";
2
- import React, { useEffect, useMemo, useReducer } from 'react';
1
+ import { __awaiter, __rest } from "tslib";
2
+ import React, { useEffect, useMemo, useState } from 'react';
3
3
  import { styled } from '@mui/material/styles';
4
- import { Box, Button, Grid, Typography } from '@mui/material';
4
+ import { Box, Grid, TextField, Typography } from '@mui/material';
5
5
  import { http } from '@selfcommunity/api-services';
6
- import { CacheStrategies, Logger } from '@selfcommunity/utils';
7
- import { SCCache, SCPreferences, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
8
- import { actionWidgetTypes, dataWidgetReducer, stateWidgetInitializer } from '../../utils/widget';
6
+ import { Logger, sortByAttr } from '@selfcommunity/utils';
7
+ import { SCPreferences, useIsComponentMountedRef, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
9
8
  import Skeleton from './Skeleton';
10
9
  import { FormattedMessage } from 'react-intl';
11
10
  import classNames from 'classnames';
@@ -16,6 +15,7 @@ import { PREFIX } from './constants';
16
15
  import Group from '../Group';
17
16
  const classes = {
18
17
  root: `${PREFIX}-root`,
18
+ filters: `${PREFIX}-filter`,
19
19
  groups: `${PREFIX}-groups`,
20
20
  item: `${PREFIX}-item`,
21
21
  noResults: `${PREFIX}-no-results`,
@@ -63,116 +63,98 @@ export default function Groups(inProps) {
63
63
  props: inProps,
64
64
  name: PREFIX
65
65
  });
66
- const { endpoint, autoHide = false, limit = 6, className, cacheStrategy = CacheStrategies.NETWORK_ONLY, onHeightChange, onStateChange, GroupProps = { variant: 'outlined', ButtonBaseProps: { disableRipple: true, component: Box } } } = props, rest = __rest(props, ["endpoint", "autoHide", "limit", "className", "cacheStrategy", "onHeightChange", "onStateChange", "GroupProps"]);
66
+ const { endpoint, className, GroupComponentProps = { variant: 'outlined', ButtonBaseProps: { disableRipple: true, component: Box } }, prefetchedGroups = [], showFilters = false, filters, handleFilterGroups, general } = props, rest = __rest(props, ["endpoint", "className", "GroupComponentProps", "prefetchedGroups", "showFilters", "filters", "handleFilterGroups", "general"]);
67
67
  // STATE
68
- const [state, dispatch] = useReducer(dataWidgetReducer, {
69
- isLoadingNext: false,
70
- next: null,
71
- cacheKey: SCCache.getWidgetStateCacheKey(SCCache.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY),
72
- cacheStrategy,
73
- visibleItems: limit
74
- }, stateWidgetInitializer);
68
+ const [groups, setGroups] = useState([]);
69
+ const [loading, setLoading] = useState(true);
70
+ const [filterName, setFilterName] = useState('');
75
71
  // CONTEXT
76
72
  const scUserContext = useSCUser();
77
73
  const scPreferencesContext = useSCPreferences();
78
74
  // MEMO
79
75
  const contentAvailability = useMemo(() => SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY in scPreferencesContext.preferences &&
80
76
  scPreferencesContext.preferences[SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value, [scPreferencesContext.preferences]);
81
- // HOOKS
82
- // const theme = useTheme<SCThemeType>();
83
- // const isMobile = useMediaQuery(theme.breakpoints.down('md'));
77
+ // CONST
78
+ const authUserId = scUserContext.user ? scUserContext.user.id : null;
79
+ // REFS
80
+ const isMountedRef = useIsComponentMountedRef();
84
81
  /**
85
- * Initialize component
86
- * Fetch data only if the component is not initialized, and it is not loading data
82
+ * Fetches groups list
83
+ */
84
+ const fetchGroups = (next = endpoint.url({})) => __awaiter(this, void 0, void 0, function* () {
85
+ const response = yield http.request({
86
+ url: next,
87
+ method: endpoint.method
88
+ });
89
+ const data = response.data;
90
+ return data.next ? data.results.concat(yield fetchGroups(data.next)) : data.results;
91
+ });
92
+ /**
93
+ * On mount, fetches groups list
87
94
  */
88
- const _initComponent = useMemo(() => () => {
89
- if (!state.initialized && !state.isLoadingNext) {
90
- dispatch({ type: actionWidgetTypes.LOADING_NEXT });
91
- http
92
- .request({
93
- url: endpoint.url({ limit }),
94
- method: endpoint.method
95
- })
96
- .then((payload) => {
97
- dispatch({ type: actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: Object.assign(Object.assign({}, payload.data), { initialized: true }) });
98
- })
99
- .catch((error) => {
100
- dispatch({ type: actionWidgetTypes.LOAD_NEXT_FAILURE, payload: { errorLoadNext: error } });
101
- Logger.error(SCOPE_SC_UI, error);
102
- });
103
- }
104
- }, [state.isLoadingNext, state.initialized, endpoint, limit, dispatch]);
105
- // EFFECTS
106
95
  useEffect(() => {
107
- var _a;
108
- let _t;
109
- if ((contentAvailability || (!contentAvailability && ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id))) && scUserContext.user !== undefined) {
110
- _t = setTimeout(_initComponent);
111
- return () => {
112
- _t && clearTimeout(_t);
113
- };
96
+ if (!contentAvailability && !authUserId) {
97
+ return;
114
98
  }
115
- }, [scUserContext.user, contentAvailability]);
116
- useEffect(() => {
117
- if (state.next && state.results.length === limit && state.initialized) {
118
- dispatch({ type: actionWidgetTypes.LOADING_NEXT });
119
- http
120
- .request({
121
- url: endpoint.url({ offset: limit, limit: 10 }),
122
- method: endpoint.method
123
- })
124
- .then((payload) => {
125
- dispatch({ type: actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: payload.data });
99
+ else if (prefetchedGroups.length) {
100
+ setGroups(prefetchedGroups);
101
+ setLoading(false);
102
+ }
103
+ else {
104
+ fetchGroups()
105
+ .then((data) => {
106
+ if (isMountedRef.current) {
107
+ setGroups(data);
108
+ setLoading(false);
109
+ }
126
110
  })
127
111
  .catch((error) => {
128
- dispatch({ type: actionWidgetTypes.LOAD_NEXT_FAILURE, payload: { errorLoadNext: error } });
129
112
  Logger.error(SCOPE_SC_UI, error);
130
113
  });
131
114
  }
132
- }, [state.next, state.results.length, state.initialized, limit]);
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
+ };
133
123
  /**
134
- * Virtual feed update
124
+ * Get groups filtered
135
125
  */
136
- useEffect(() => {
137
- onHeightChange && onHeightChange();
138
- }, [state.results]);
139
- useEffect(() => {
140
- if (!endpoint || (!contentAvailability && !scUserContext.user)) {
141
- return;
126
+ const getFilteredGroups = () => {
127
+ if (handleFilterGroups) {
128
+ return handleFilterGroups(groups);
142
129
  }
143
- else if (cacheStrategy === CacheStrategies.NETWORK_ONLY) {
144
- onStateChange && onStateChange({ cacheStrategy: CacheStrategies.CACHE_FIRST });
145
- }
146
- }, [scUserContext.user, endpoint, contentAvailability]);
147
- useEffect(() => {
148
- if (!endpoint || !scUserContext.user || !state.initialized) {
149
- return;
130
+ if (filterName) {
131
+ return groups.filter((g) => g.name.toLowerCase().includes(filterName.toLowerCase()));
150
132
  }
151
- }, []);
152
- // HANDLERS
153
- const handleNext = useMemo(() => () => {
154
- dispatch({ type: actionWidgetTypes.LOADING_NEXT });
155
- http
156
- .request({
157
- url: state.next,
158
- method: endpoint.method
159
- })
160
- .then((res) => {
161
- dispatch({ type: actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: res.data });
162
- });
163
- }, [dispatch, state.next, state.isLoadingNext, state.initialized, endpoint.method]);
133
+ return groups;
134
+ };
135
+ /**
136
+ * Handle change filter name
137
+ * @param event
138
+ */
139
+ const handleOnChangeFilterName = (event) => {
140
+ setFilterName(event.target.value);
141
+ };
142
+ /**
143
+ * Renders groups list
144
+ */
145
+ const filteredGroups = sortByAttr(getFilteredGroups(), 'order');
146
+ const content = (React.createElement(React.Fragment, null,
147
+ showFilters && (React.createElement(Grid, { container: true, direction: "row", justifyContent: "center", alignItems: "center", className: classes.filters }, filters ? (filters) : (React.createElement(Grid, { item: true, xs: 12, md: 6 },
148
+ React.createElement(TextField, { fullWidth: true, value: filterName, label: React.createElement(FormattedMessage, { id: "ui.groups.filterByName", defaultMessage: "ui.groups.filterByName" }), variant: "outlined", onChange: handleOnChangeFilterName, disabled: loading }))))),
149
+ loading ? (React.createElement(Skeleton, null)) : (React.createElement(React.Fragment, null, !groups.length ? (React.createElement(Box, { className: classes.noResults },
150
+ React.createElement(Typography, { variant: "h4" },
151
+ React.createElement(FormattedMessage, { id: "ui.groups.noGroups.title", defaultMessage: "ui.groups.noGroups.title" })),
152
+ React.createElement(Typography, { variant: "body1" },
153
+ React.createElement(FormattedMessage, { id: "ui.groups.noGroups.subtitle", defaultMessage: "ui.groups.noGroups.subtitle" })))) : (React.createElement(Grid, { container: true, spacing: { xs: 3 }, className: classes.groups }, filteredGroups.map((group) => (React.createElement(Grid, { item: true, xs: 12, sm: 8, md: 6, key: group.id, className: classes.item },
154
+ React.createElement(Group, Object.assign({ group: group, groupId: group.id, groupSubscribeButtonProps: { onSubscribe: handleSubscribe } }, GroupComponentProps)))))))))));
164
155
  // RENDER
165
- if ((autoHide && !state.count && state.initialized) || (!contentAvailability && !scUserContext.user) || !endpoint) {
156
+ if (!contentAvailability && !scUserContext.user) {
166
157
  return React.createElement(HiddenPlaceholder, null);
167
158
  }
168
- if (!state.initialized) {
169
- return React.createElement(Skeleton, null);
170
- }
171
- const content = (React.createElement(React.Fragment, null, !state.count ? (React.createElement(Typography, { className: classes.noResults, variant: "body2" },
172
- React.createElement(FormattedMessage, { id: "ui.groupRequestsWidget.subtitle.noResults", defaultMessage: "" }))) : (React.createElement(React.Fragment, null,
173
- React.createElement(Grid, { container: true, spacing: { xs: 3 }, className: classes.groups }, state.results.slice(0, state.visibleItems).map((group) => (React.createElement(Grid, { item: true, xs: 12, sm: 8, md: 6, key: group.id, className: classes.item },
174
- React.createElement(Group, Object.assign({ actions: React.createElement(React.Fragment, null), group: group, groupId: group.id, buttonProps: { onClick: () => console.log(group) } }, GroupProps)))))),
175
- state.count > state.visibleItems && (React.createElement(Button, { className: classes.showMore, onClick: handleNext },
176
- React.createElement(FormattedMessage, { id: "ui.groupRequestsWidget.button.showMore", defaultMessage: "ui.groupRequestsWidget.button.showMore" })))))));
177
159
  return (React.createElement(Root, Object.assign({ className: classNames(classes.root, className) }, rest), content));
178
160
  }
@@ -60,7 +60,7 @@ export default function NavigationMenuIconButton(inProps) {
60
60
  props: inProps,
61
61
  name: PREFIX
62
62
  });
63
- const { className = null, DrawerProps = { anchor: 'left' }, drawerContent = React.createElement(DefaultDrawerContent, null), drawerHeaderContent = React.createElement(DefaultHeaderContent, null), ScrollContainerProps = {} } = props, rest = __rest(props, ["className", "DrawerProps", "drawerContent", "drawerHeaderContent", "ScrollContainerProps"]);
63
+ const { className = null, DrawerProps = { anchor: 'left' }, drawerHeaderContent = React.createElement(DefaultHeaderContent, null), drawerContent = React.createElement(DefaultDrawerContent, null), ScrollContainerProps = {} } = props, rest = __rest(props, ["className", "DrawerProps", "drawerHeaderContent", "drawerContent", "ScrollContainerProps"]);
64
64
  // STATE
65
65
  const [anchorEl, setAnchorEl] = useState(null);
66
66
  // CONTEXT
@@ -8,6 +8,10 @@ export interface NavigationToolbarMobileProps extends ToolbarProps {
8
8
  * Disable search action if possible
9
9
  */
10
10
  disableSearch?: boolean;
11
+ /**
12
+ * Preserve the same as the desktop version
13
+ */
14
+ preserveDesktopLogo?: boolean;
11
15
  /**
12
16
  * Props spread to SearchAutocomplete component
13
17
  */
@@ -62,7 +62,7 @@ export default function NavigationToolbarMobile(inProps) {
62
62
  props: inProps,
63
63
  name: PREFIX
64
64
  });
65
- const { className = '', disableSearch = false, SearchAutocompleteProps = {}, children = null, startActions = null, endActions = null, NavigationMenuIconButtonComponent = NavigationMenuIconButton, NavigationSettingsIconButtonComponent = NavigationSettingsIconButton } = props, rest = __rest(props, ["className", "disableSearch", "SearchAutocompleteProps", "children", "startActions", "endActions", "NavigationMenuIconButtonComponent", "NavigationSettingsIconButtonComponent"]);
65
+ const { className = '', disableSearch = false, preserveDesktopLogo = false, SearchAutocompleteProps = {}, children = null, startActions = null, endActions = null, NavigationMenuIconButtonComponent = NavigationMenuIconButton, NavigationSettingsIconButtonComponent = NavigationSettingsIconButton } = props, rest = __rest(props, ["className", "disableSearch", "preserveDesktopLogo", "SearchAutocompleteProps", "children", "startActions", "endActions", "NavigationMenuIconButtonComponent", "NavigationSettingsIconButtonComponent"]);
66
66
  // CONTEXT
67
67
  const scUserContext = useSCUser();
68
68
  const scRoutingContext = useSCRouting();
@@ -83,8 +83,7 @@ export default function NavigationToolbarMobile(inProps) {
83
83
  }
84
84
  const _children = children || (React.createElement(React.Fragment, null,
85
85
  React.createElement(NavigationMenuIconButtonComponent, null),
86
- React.createElement(Link, { to: scRoutingContext.url(SCRoutes.HOME_ROUTE_NAME, {}), className: classes.logo },
87
- React.createElement("img", { src: preferences[SCPreferences.LOGO_NAVBAR_LOGO_MOBILE].value, alt: "logo" }))));
86
+ React.createElement(Link, { to: scRoutingContext.url(SCRoutes.HOME_ROUTE_NAME, {}), className: classes.logo }, !preserveDesktopLogo ? (React.createElement("img", { src: preferences[SCPreferences.LOGO_NAVBAR_LOGO_MOBILE].value, alt: "logo" })) : (React.createElement("img", { src: preferences[SCPreferences.LOGO_NAVBAR_LOGO].value, alt: "logo" })))));
88
87
  return (React.createElement(Root, Object.assign({ className: classNames(className, classes.root) }, rest),
89
88
  _children,
90
89
  startActions,
@@ -0,0 +1,15 @@
1
+ import { SCNotificationGroupActivityType } from '@selfcommunity/types';
2
+ import { NotificationItemProps } from '../../../shared/NotificationItem';
3
+ export interface NotificationGroupProps extends Pick<NotificationItemProps, Exclude<keyof NotificationItemProps, 'image' | 'disableTypography' | 'primary' | 'primaryTypographyProps' | 'secondary' | 'secondaryTypographyProps' | 'actions' | 'footer' | 'isNew'>> {
4
+ /**
5
+ * Notification obj
6
+ * @default null
7
+ */
8
+ notificationObject: SCNotificationGroupActivityType;
9
+ }
10
+ /**
11
+ * This component render the content of the notification of type group
12
+ * @constructor
13
+ * @param props
14
+ */
15
+ export default function GroupNotification(props: NotificationGroupProps): JSX.Element;
@@ -0,0 +1,75 @@
1
+ import { __rest } from "tslib";
2
+ import React, { useContext, useEffect, useState } from 'react';
3
+ import { styled } from '@mui/material/styles';
4
+ import { Avatar, Box, Stack, Typography } from '@mui/material';
5
+ import { Link, SCRoutes, SCUserContext, useSCRouting } from '@selfcommunity/react-core';
6
+ import { SCGroupSubscriptionStatusType } from '@selfcommunity/types';
7
+ import { FormattedMessage } from 'react-intl';
8
+ import DateTimeAgo from '../../../shared/DateTimeAgo';
9
+ import classNames from 'classnames';
10
+ import { SCNotificationObjectTemplateType } from '../../../types';
11
+ import NotificationItem from '../../../shared/NotificationItem';
12
+ import { LoadingButton } from '@mui/lab';
13
+ import UserDeletedSnackBar from '../../../shared/UserDeletedSnackBar';
14
+ import UserAvatar from '../../../shared/UserAvatar';
15
+ import { PREFIX } from '../constants';
16
+ const classes = {
17
+ root: `${PREFIX}-group-root`,
18
+ avatar: `${PREFIX}-avatar`,
19
+ actions: `${PREFIX}-actions`,
20
+ acceptButton: `${PREFIX}-reply-button`,
21
+ activeAt: `${PREFIX}-active-at`,
22
+ username: `${PREFIX}-username`
23
+ };
24
+ const Root = styled(NotificationItem, {
25
+ name: PREFIX,
26
+ slot: 'GroupRoot'
27
+ })(() => ({}));
28
+ /**
29
+ * This component render the content of the notification of type group
30
+ * @constructor
31
+ * @param props
32
+ */
33
+ export default function GroupNotification(props) {
34
+ // PROPS
35
+ const { notificationObject, id = `n_${props.notificationObject['sid']}`, className, template = SCNotificationObjectTemplateType.DETAIL } = props, rest = __rest(props, ["notificationObject", "id", "className", "template"]);
36
+ // CONTEXT
37
+ const scRoutingContext = useSCRouting();
38
+ const scUserContext = useContext(SCUserContext);
39
+ const manager = scUserContext.managers.groups;
40
+ // STATE
41
+ const [status, setStatus] = useState(null);
42
+ const [openAlert, setOpenAlert] = useState(false);
43
+ // CONST
44
+ const isSnippetTemplate = template === SCNotificationObjectTemplateType.SNIPPET;
45
+ const isToastTemplate = template === SCNotificationObjectTemplateType.TOAST;
46
+ useEffect(() => {
47
+ setStatus(manager.subscriptionStatus(notificationObject.group));
48
+ }, [manager.subscriptionStatus, notificationObject.group]);
49
+ // RENDER
50
+ if (isSnippetTemplate || isToastTemplate) {
51
+ return (React.createElement(Root, Object.assign({ id: id, className: classNames(classes.root, className, `${PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, image: React.createElement(Link, Object.assign({}, (!notificationObject.user.deleted && {
52
+ to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.user)
53
+ }), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null }),
54
+ React.createElement(UserAvatar, { hide: !notificationObject.user.community_badge, smaller: true },
55
+ React.createElement(Avatar, { alt: notificationObject.user.username, variant: "circular", src: notificationObject.user.avatar, classes: { root: classes.avatar } }))), primary: React.createElement(Box, null,
56
+ React.createElement(Link, Object.assign({}, (!notificationObject.user.deleted && {
57
+ to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.user)
58
+ }), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null, className: classes.username }), notificationObject.user.username),
59
+ ' ',
60
+ React.createElement(FormattedMessage, { id: `ui.notification.${notificationObject.type}`, defaultMessage: `ui.notification.${notificationObject.type}`, values: {
61
+ group: notificationObject.group.name,
62
+ link: (...chunks) => React.createElement(Link, { to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, notificationObject.group) }, chunks)
63
+ } })), footer: isToastTemplate && (React.createElement(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
64
+ React.createElement(DateTimeAgo, { date: notificationObject.active_at }),
65
+ status && status !== SCGroupSubscriptionStatusType.SUBSCRIBED && (React.createElement(Typography, { color: "primary" },
66
+ React.createElement(Link, { to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, notificationObject.group) },
67
+ React.createElement(FormattedMessage, { id: "ui.groupSubscribeButton.accept", defaultMessage: "ui.groupSubscribeButton.accept" })))))) }, rest)));
68
+ }
69
+ return (React.createElement(React.Fragment, null,
70
+ React.createElement(Root, Object.assign({ id: id, className: classNames(classes.root, className, `${PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, actions: React.createElement(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
71
+ React.createElement(DateTimeAgo, { date: notificationObject.active_at, className: classes.activeAt }),
72
+ status && status !== SCGroupSubscriptionStatusType.SUBSCRIBED && (React.createElement(LoadingButton, { color: 'primary', variant: "outlined", size: "small", classes: { root: classes.acceptButton }, component: Link, loading: scUserContext.user ? status === null || manager.isLoading(notificationObject.group) : null, to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, notificationObject.group) },
73
+ React.createElement(FormattedMessage, { id: "ui.groupSubscribeButton.accept", defaultMessage: "ui.groupSubscribeButton.accept" })))) }, rest)),
74
+ openAlert && React.createElement(UserDeletedSnackBar, { open: openAlert, handleClose: () => setOpenAlert(false) })));
75
+ }
@@ -0,0 +1,3 @@
1
+ import GroupNotification, { NotificationGroupProps } from './Group';
2
+ export default GroupNotification;
3
+ export { NotificationGroupProps };
@@ -0,0 +1,2 @@
1
+ import GroupNotification from './Group';
2
+ export default GroupNotification;
@@ -33,6 +33,7 @@ import { SCNotificationTypologyType } from '@selfcommunity/types';
33
33
  import UserDeletedSnackBar from '../../shared/UserDeletedSnackBar';
34
34
  import UserAvatar from '../../shared/UserAvatar';
35
35
  import { PREFIX } from './constants';
36
+ import GroupNotification from './Group';
36
37
  const messages = defineMessages({
37
38
  receivePrivateMessage: {
38
39
  id: 'ui.notification.receivePrivateMessage',
@@ -149,7 +150,7 @@ export default function UserNotification(inProps) {
149
150
  }
150
151
  /**
151
152
  * Handles vote
152
- * @param comment
153
+ * @param index
153
154
  */
154
155
  const handleVote = (index) => {
155
156
  return (contribution) => {
@@ -194,6 +195,29 @@ export default function UserNotification(inProps) {
194
195
  b: (...chunks) => React.createElement("strong", null, chunks)
195
196
  })) }));
196
197
  }
198
+ /**
199
+ * Group notifications header
200
+ */
201
+ if (notificationObject.aggregated &&
202
+ (notificationObject.aggregated[0].type === SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP ||
203
+ notificationObject.aggregated[0].type === SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP ||
204
+ notificationObject.aggregated[0].type === SCNotificationTypologyType.USER_ADDED_TO_GROUP ||
205
+ notificationObject.aggregated[0].type === SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP)) {
206
+ let groupNotification = notificationObject.aggregated[0];
207
+ return (React.createElement(CardHeader, { className: classes.header, avatar: React.createElement(Link, Object.assign({}, (!groupNotification.user.deleted && {
208
+ to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, groupNotification.user)
209
+ }), { onClick: groupNotification.user.deleted ? () => setOpenAlert(true) : null }),
210
+ React.createElement(UserAvatar, { hide: !groupNotification.user.community_badge, smaller: true },
211
+ React.createElement(Avatar, { className: classes.avatar, alt: groupNotification.user.username, variant: "circular", src: groupNotification.user.avatar }))), titleTypographyProps: { className: classes.title, variant: 'subtitle1' }, title: React.createElement(React.Fragment, null,
212
+ React.createElement(Link, Object.assign({}, (!groupNotification.user.deleted && {
213
+ to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, groupNotification.user)
214
+ }), { onClick: groupNotification.user.deleted ? () => setOpenAlert(true) : null, className: classes.username }), groupNotification.user.username),
215
+ ' ',
216
+ React.createElement(FormattedMessage, { id: `ui.notification.${notificationObject.aggregated[0].type}`, defaultMessage: `ui.notification.${notificationObject.aggregated[0].type}`, values: {
217
+ group: groupNotification.group.name,
218
+ link: (...chunks) => React.createElement(Link, { to: scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, groupNotification.group) }, chunks)
219
+ } })) }));
220
+ }
197
221
  /**
198
222
  * Comment, NestedComment, Follow Contribution header
199
223
  */
@@ -276,6 +300,12 @@ export default function UserNotification(inProps) {
276
300
  else if (n.type === SCNotificationTypologyType.CONTRIBUTION) {
277
301
  return React.createElement(ContributionNotification, { notificationObject: n, key: i, onVote: handleVote(i) });
278
302
  }
303
+ else if (n.type === SCNotificationTypologyType.USER_ADDED_TO_GROUP ||
304
+ n.type === SCNotificationTypologyType.USER_INVITED_TO_JOIN_GROUP ||
305
+ n.type === SCNotificationTypologyType.USER_ACCEPTED_TO_JOIN_GROUP ||
306
+ n.type === SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_GROUP) {
307
+ return React.createElement(GroupNotification, { notificationObject: n, key: i });
308
+ }
279
309
  return null;
280
310
  }
281
311
  /**
@@ -39,6 +39,7 @@ const Root = styled(NotificationItem, {
39
39
  * @param props
40
40
  */
41
41
  export default function PrivateMessageNotification(props) {
42
+ var _a, _b, _c, _d, _e;
42
43
  // PROPS
43
44
  const { notificationObject, id = `n_${props.notificationObject['sid']}`, className, template = SCNotificationObjectTemplateType.DETAIL } = props, rest = __rest(props, ["notificationObject", "id", "className", "template"]);
44
45
  // CONTEXT
@@ -89,7 +90,9 @@ export default function PrivateMessageNotification(props) {
89
90
  React.createElement(FormattedMessage, { id: 'ui.userToastNotifications.privateMessage.sentMessage', defaultMessage: 'ui.userToastNotifications.privateMessage.sentMessage' }),
90
91
  ":",
91
92
  React.createElement(Box, { className: classes.messageWrap },
92
- React.createElement(Link, { to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
93
+ React.createElement(Link, { to: ((_a = notificationObject.message) === null || _a === void 0 ? void 0 : _a.group)
94
+ ? scRoutingContext.url(SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
95
+ : scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
93
96
  React.createElement(Typography, { variant: "body2", dangerouslySetInnerHTML: { __html: notificationObject.message.message } }))))),
94
97
  isSnippetTemplate && (React.createElement(Box, null,
95
98
  React.createElement(Typography, { component: "div", color: "inherit" },
@@ -97,13 +100,17 @@ export default function PrivateMessageNotification(props) {
97
100
  to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.message.sender)
98
101
  }), { onClick: notificationObject.message.sender.deleted ? () => setOpenAlert(true) : null, className: classes.username }), notificationObject.message.sender.username),
99
102
  ' ',
100
- React.createElement(Link, { to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.messageLabel }, intl.formatMessage(messages.receivePrivateMessage, {
103
+ React.createElement(Link, { to: ((_b = notificationObject.message) === null || _b === void 0 ? void 0 : _b.group)
104
+ ? scRoutingContext.url(SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
105
+ : scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.messageLabel }, intl.formatMessage(messages.receivePrivateMessage, {
101
106
  total: 1,
102
107
  b: (...chunks) => React.createElement("strong", null, chunks)
103
108
  })))))), footer: isToastTemplate && (React.createElement(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
104
109
  React.createElement(DateTimeAgo, { date: notificationObject.active_at }),
105
110
  React.createElement(Typography, { color: "primary" },
106
- React.createElement(Link, { to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (React.createElement(FormattedMessage, { id: "ui.userToastNotifications.replyMessage", defaultMessage: 'ui.userToastNotifications.replyMessage' })) : (React.createElement(FormattedMessage, { id: "ui.userToastNotifications.viewMessage", defaultMessage: 'ui.userToastNotifications.viewMessage' })))))) }, rest)));
111
+ React.createElement(Link, { to: ((_c = notificationObject.message) === null || _c === void 0 ? void 0 : _c.group)
112
+ ? scRoutingContext.url(SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
113
+ : scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (React.createElement(FormattedMessage, { id: "ui.userToastNotifications.replyMessage", defaultMessage: 'ui.userToastNotifications.replyMessage' })) : (React.createElement(FormattedMessage, { id: "ui.userToastNotifications.viewMessage", defaultMessage: 'ui.userToastNotifications.viewMessage' })))))) }, rest)));
107
114
  }
108
115
  return (React.createElement(React.Fragment, null,
109
116
  React.createElement(Root, Object.assign({ id: id, className: classNames(classes.root, className, `${PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, actions: React.createElement(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 },
@@ -112,8 +119,12 @@ export default function PrivateMessageNotification(props) {
112
119
  ? null
113
120
  : scUserContext.user
114
121
  ? follower === null || manager.isLoading(notificationObject.message.sender)
115
- : null, to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (React.createElement(FormattedMessage, { id: "ui.notification.privateMessage.btnReplyLabel", defaultMessage: "ui.notification.privateMessage.btnReplyLabel" })) : (React.createElement(FormattedMessage, { id: "ui.notification.privateMessage.btnViewLabel", defaultMessage: "ui.notification.privateMessage.btnViewLabel" })))), primary: React.createElement(Box, { className: classes.messageWrap },
116
- React.createElement(Link, { to: scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
122
+ : null, to: ((_d = notificationObject.message) === null || _d === void 0 ? void 0 : _d.group)
123
+ ? scRoutingContext.url(SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
124
+ : scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender) }, scUserContext.user && follower ? (React.createElement(FormattedMessage, { id: "ui.notification.privateMessage.btnReplyLabel", defaultMessage: "ui.notification.privateMessage.btnReplyLabel" })) : (React.createElement(FormattedMessage, { id: "ui.notification.privateMessage.btnViewLabel", defaultMessage: "ui.notification.privateMessage.btnViewLabel" })))), primary: React.createElement(Box, { className: classes.messageWrap },
125
+ React.createElement(Link, { to: ((_e = notificationObject.message) === null || _e === void 0 ? void 0 : _e.group)
126
+ ? scRoutingContext.url(SCRoutes.GROUP_MESSAGES_ROUTE_NAME, notificationObject.message.group)
127
+ : scRoutingContext.url(SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message.sender), className: classes.message },
117
128
  React.createElement(Typography, { variant: "body2", dangerouslySetInnerHTML: { __html: notificationObject.message.message } }))) }, rest)),
118
129
  openAlert && React.createElement(UserDeletedSnackBar, { open: openAlert, handleClose: () => setOpenAlert(false) })));
119
130
  }
@@ -8,7 +8,7 @@ export interface PrivateMessageComponentProps {
8
8
  * Handler on message click
9
9
  * @default null
10
10
  */
11
- onItemClick?: (id: any) => void;
11
+ onItemClick?: (id: any, type: any) => void;
12
12
  /**
13
13
  * Handler on single message open
14
14
  * @default null
@@ -5,7 +5,7 @@ import { Grid, useMediaQuery, useTheme } from '@mui/material';
5
5
  import { useSCPreferences, useSCUser } from '@selfcommunity/react-core';
6
6
  import classNames from 'classnames';
7
7
  import { useThemeProps } from '@mui/system';
8
- import { SCFeatureName, SCPrivateMessageStatusType } from '@selfcommunity/types';
8
+ import { SCFeatureName, SCPrivateMessageStatusType, SCPrivateMessageType } from '@selfcommunity/types';
9
9
  import PrivateMessageThread from '../PrivateMessageThread';
10
10
  import PrivateMessageSnippets from '../PrivateMessageSnippets';
11
11
  import { PREFIX } from './constants';
@@ -65,6 +65,7 @@ export default function PrivateMessageComponent(inProps) {
65
65
  const isMobile = useMediaQuery(theme.breakpoints.down('md'));
66
66
  const [layout, setLayout] = useState('default');
67
67
  const [obj, setObj] = useState(id !== null && id !== void 0 ? id : null);
68
+ const [type, setType] = useState(null);
68
69
  const isNew = obj && obj === SCPrivateMessageStatusType.NEW;
69
70
  const [openNewMessage, setOpenNewMessage] = useState(isNew !== null && isNew !== void 0 ? isNew : false);
70
71
  const mobileSnippetsView = (layout === 'default' && !obj) || (layout === 'mobile' && !obj);
@@ -86,10 +87,12 @@ export default function PrivateMessageComponent(inProps) {
86
87
  /**
87
88
  * Handles thread opening on click
88
89
  * @param item
90
+ * @param type
89
91
  */
90
- const handleThreadOpening = (item) => {
91
- onItemClick && onItemClick(messageReceiver(item, authUserId));
92
- setObj(messageReceiver(item, authUserId));
92
+ const handleThreadOpening = (item, type) => {
93
+ onItemClick && onItemClick(item.group ? item.group.id : messageReceiver(item, authUserId), type);
94
+ setType(type);
95
+ setObj(item.group ? item : messageReceiver(item, authUserId));
93
96
  setOpenNewMessage(false);
94
97
  };
95
98
  /**
@@ -105,7 +108,7 @@ export default function PrivateMessageComponent(inProps) {
105
108
  const handleOpenNewMessage = () => {
106
109
  setOpenNewMessage(!openNewMessage);
107
110
  setObj(SCPrivateMessageStatusType.NEW);
108
- onItemClick && onItemClick(SCPrivateMessageStatusType.NEW);
111
+ onItemClick && onItemClick(SCPrivateMessageStatusType.NEW, SCPrivateMessageType.NEW);
109
112
  };
110
113
  /**
111
114
  * Handles new messages open from user profile page or notifications section
@@ -127,7 +130,7 @@ export default function PrivateMessageComponent(inProps) {
127
130
  * Handles state update when a new message is sent
128
131
  */
129
132
  const handleOnNewMessageSent = (msg, isOne) => {
130
- onItemClick && onItemClick(isOne ? messageReceiver(msg, authUserId) : '');
133
+ onItemClick && onItemClick(isOne ? messageReceiver(msg, authUserId) : '', msg.group ? SCPrivateMessageType.GROUP : SCPrivateMessageType.USER);
131
134
  setObj(isOne ? messageReceiver(msg, authUserId) : null);
132
135
  setOpenNewMessage(false);
133
136
  };
@@ -147,14 +150,14 @@ export default function PrivateMessageComponent(inProps) {
147
150
  onSnippetClick: handleThreadOpening,
148
151
  onNewMessageClick: handleOpenNewMessage,
149
152
  onDeleteConfirm: handleDeleteThread
150
- }, userObj: obj, clearSearch: clear, elevation: 0 })));
153
+ }, threadObj: obj, clearSearch: clear, elevation: 0 })));
151
154
  }
152
155
  /**
153
156
  * Renders thread section
154
157
  */
155
158
  function renderThread() {
156
159
  return (React.createElement(Grid, { item: true, xs: 12, md: 7, className: classNames(classes.threadBox, { [classes.hide]: isMobile && mobileSnippetsView }) },
157
- React.createElement(PrivateMessageThread, { userObj: obj, openNewMessage: openNewMessage, onNewMessageClose: handleMessageBack, onNewMessageSent: handleOnNewMessageSent, onSingleMessageOpen: handleSingleMessage, elevation: 0 })));
160
+ React.createElement(PrivateMessageThread, { threadObj: obj, type: type, openNewMessage: openNewMessage, onNewMessageClose: handleMessageBack, onNewMessageSent: handleOnNewMessageSent, onSingleMessageOpen: handleSingleMessage, elevation: 0 })));
158
161
  }
159
162
  /**
160
163
  * Renders the component (if not hidden by autoHide prop)