@selfcommunity/react-ui 0.8.0-alpha.2 → 0.8.0-alpha.20
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.
- package/lib/cjs/components/BottomNavigation/BottomNavigation.js +11 -2
- package/lib/cjs/components/Composer/Composer.js +10 -2
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +12 -3
- package/lib/cjs/components/CreateEventButton/CreateEventButton.js +5 -1
- package/lib/cjs/components/CreateEventWidget/CreateEventWidget.js +5 -1
- package/lib/cjs/components/EventForm/EventAddress.d.ts +3 -8
- package/lib/cjs/components/EventForm/EventAddress.js +20 -20
- package/lib/cjs/components/EventForm/EventForm.d.ts +1 -1
- package/lib/cjs/components/EventForm/EventForm.js +90 -76
- package/lib/cjs/components/EventForm/constants.d.ts +4 -0
- package/lib/cjs/components/EventForm/constants.js +5 -1
- package/lib/cjs/components/EventForm/types.d.ts +27 -0
- package/lib/cjs/components/EventForm/types.js +2 -0
- package/lib/cjs/components/EventForm/utils.d.ts +4 -0
- package/lib/cjs/components/EventForm/utils.js +28 -0
- package/lib/cjs/components/EventHeader/EventHeader.js +1 -1
- package/lib/cjs/components/EventInfoWidget/EventInfoWidget.js +24 -1
- package/lib/cjs/components/Events/Events.js +4 -4
- package/lib/cjs/components/Feed/Feed.js +10 -2
- package/lib/cjs/components/GroupActionsMenu/index.d.ts +57 -0
- package/lib/cjs/components/GroupActionsMenu/index.js +157 -0
- package/lib/cjs/components/GroupHeader/GroupHeader.d.ts +6 -0
- package/lib/cjs/components/GroupHeader/GroupHeader.js +8 -4
- package/lib/cjs/components/Groups/Groups.js +26 -0
- package/lib/cjs/components/MyEventsWidget/MyEventsWidget.js +6 -2
- package/lib/cjs/components/NavigationToolbar/NavigationToolbar.js +12 -3
- package/lib/cjs/components/NavigationToolbarMobile/NavigationToolbarMobile.js +11 -2
- package/lib/cjs/components/Notification/Event/Event.js +4 -0
- package/lib/cjs/components/OnBoardingWidget/OnBoardingWidget.d.ts +10 -1
- package/lib/cjs/components/OnBoardingWidget/OnBoardingWidget.js +69 -26
- package/lib/cjs/components/OnBoardingWidget/Steps/Invite/Invite.js +26 -3
- package/lib/cjs/components/PlatformWidget/constants.d.ts +0 -4
- package/lib/cjs/components/PlatformWidget/constants.js +1 -5
- package/lib/cjs/components/UserSubscribedGroupsWidget/UserSubscribedGroupsWidget.js +7 -2
- package/lib/cjs/constants/GroupActionsMenu.d.ts +5 -0
- package/lib/cjs/constants/GroupActionsMenu.js +8 -0
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +6 -4
- package/lib/cjs/shared/ContributionActionsMenu/index.js +6 -6
- package/lib/cjs/shared/EventActionsMenu/index.d.ts +4 -0
- package/lib/cjs/shared/EventActionsMenu/index.js +13 -3
- package/lib/cjs/shared/InfiniteScroll/index.js +3 -3
- package/lib/cjs/shared/Media/Link/DisplayComponent.js +21 -5
- package/lib/cjs/utils/formatRelativeTime.js +2 -2
- package/lib/esm/components/BottomNavigation/BottomNavigation.js +11 -2
- package/lib/esm/components/Composer/Composer.js +10 -2
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +13 -4
- package/lib/esm/components/CreateEventButton/CreateEventButton.js +5 -1
- package/lib/esm/components/CreateEventWidget/CreateEventWidget.js +5 -1
- package/lib/esm/components/EventForm/EventAddress.d.ts +3 -8
- package/lib/esm/components/EventForm/EventAddress.js +20 -20
- package/lib/esm/components/EventForm/EventForm.d.ts +1 -1
- package/lib/esm/components/EventForm/EventForm.js +92 -78
- package/lib/esm/components/EventForm/constants.d.ts +4 -0
- package/lib/esm/components/EventForm/constants.js +4 -0
- package/lib/esm/components/EventForm/types.d.ts +27 -0
- package/lib/esm/components/EventForm/types.js +1 -0
- package/lib/esm/components/EventForm/utils.d.ts +4 -0
- package/lib/esm/components/EventForm/utils.js +21 -0
- package/lib/esm/components/EventHeader/EventHeader.js +1 -1
- package/lib/esm/components/EventInfoWidget/EventInfoWidget.js +25 -2
- package/lib/esm/components/Events/Events.js +4 -4
- package/lib/esm/components/Feed/Feed.js +12 -4
- package/lib/esm/components/GroupActionsMenu/index.d.ts +57 -0
- package/lib/esm/components/GroupActionsMenu/index.js +154 -0
- package/lib/esm/components/GroupHeader/GroupHeader.d.ts +6 -0
- package/lib/esm/components/GroupHeader/GroupHeader.js +9 -5
- package/lib/esm/components/Groups/Groups.js +27 -1
- package/lib/esm/components/MyEventsWidget/MyEventsWidget.js +7 -3
- package/lib/esm/components/NavigationToolbar/NavigationToolbar.js +12 -3
- package/lib/esm/components/NavigationToolbarMobile/NavigationToolbarMobile.js +11 -2
- package/lib/esm/components/Notification/Event/Event.js +4 -0
- package/lib/esm/components/OnBoardingWidget/OnBoardingWidget.d.ts +10 -1
- package/lib/esm/components/OnBoardingWidget/OnBoardingWidget.js +71 -28
- package/lib/esm/components/OnBoardingWidget/Steps/Invite/Invite.js +27 -4
- package/lib/esm/components/PlatformWidget/constants.d.ts +0 -4
- package/lib/esm/components/PlatformWidget/constants.js +0 -4
- package/lib/esm/components/UserSubscribedGroupsWidget/UserSubscribedGroupsWidget.js +8 -3
- package/lib/esm/constants/GroupActionsMenu.d.ts +5 -0
- package/lib/esm/constants/GroupActionsMenu.js +5 -0
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/shared/ContributionActionsMenu/index.js +6 -6
- package/lib/esm/shared/EventActionsMenu/index.d.ts +4 -0
- package/lib/esm/shared/EventActionsMenu/index.js +13 -3
- package/lib/esm/shared/InfiniteScroll/index.js +3 -3
- package/lib/esm/shared/Media/Link/DisplayComponent.js +21 -5
- package/lib/esm/utils/formatRelativeTime.js +2 -2
- package/lib/umd/react-ui.js +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from 'react';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { Divider, IconButton, List, ListItemIcon, Menu, MenuItem, SwipeableDrawer, useMediaQuery, useTheme } from '@mui/material';
|
|
6
|
+
import { FormattedMessage } from 'react-intl';
|
|
7
|
+
import Icon from '@mui/material/Icon';
|
|
8
|
+
import classNames from 'classnames';
|
|
9
|
+
import { useThemeProps } from '@mui/system';
|
|
10
|
+
import { SCRoutes, useSCFetchGroup, useSCRouting, useSCUser } from '@selfcommunity/react-core';
|
|
11
|
+
import ConfirmDialog from '../../shared/ConfirmDialog/ConfirmDialog';
|
|
12
|
+
import { GroupService } from '@selfcommunity/api-services';
|
|
13
|
+
import { copyTextToClipboard } from '@selfcommunity/utils';
|
|
14
|
+
import { enqueueSnackbar } from 'notistack';
|
|
15
|
+
import PubSub from 'pubsub-js';
|
|
16
|
+
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
|
|
17
|
+
import GroupForm from '../../components/GroupForm';
|
|
18
|
+
import { DELETE_GROUP, GET_GROUP_LINK } from '../../constants/GroupActionsMenu';
|
|
19
|
+
const PREFIX = 'SCGroupActionsMenu';
|
|
20
|
+
const classes = {
|
|
21
|
+
root: `${PREFIX}-root`,
|
|
22
|
+
drawerRoot: `${PREFIX}-drawer-root`,
|
|
23
|
+
menuRoot: `${PREFIX}-menu-root`,
|
|
24
|
+
paper: `${PREFIX}-paper`,
|
|
25
|
+
item: `${PREFIX}-item`
|
|
26
|
+
};
|
|
27
|
+
const Root = styled(IconButton, {
|
|
28
|
+
name: PREFIX,
|
|
29
|
+
slot: 'Root'
|
|
30
|
+
})(() => ({}));
|
|
31
|
+
const SwipeableDrawerRoot = styled(SwipeableDrawer, {
|
|
32
|
+
name: PREFIX,
|
|
33
|
+
slot: 'DrawerRoot'
|
|
34
|
+
})(() => ({}));
|
|
35
|
+
const MenuRoot = styled(Menu, {
|
|
36
|
+
name: PREFIX,
|
|
37
|
+
slot: 'MenuRoot'
|
|
38
|
+
})(() => ({}));
|
|
39
|
+
/**
|
|
40
|
+
* > API documentation for the Community-JS GroupActionsMenu component. Learn about the available props and the CSS API.
|
|
41
|
+
|
|
42
|
+
#### Import
|
|
43
|
+
|
|
44
|
+
```jsx
|
|
45
|
+
import {GroupActionsMenu} from '@selfcommunity/react-ui';
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Component Name
|
|
49
|
+
|
|
50
|
+
The name `SCGroupActionsMenu` can be used when providing style overrides in the theme.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
#### CSS
|
|
54
|
+
|
|
55
|
+
|Rule Name|Global class|Description|
|
|
56
|
+
|---|---|---|
|
|
57
|
+
|root|.SCGroupActionsMenu-root|Styles applied to the root element.|
|
|
58
|
+
|drawerRoot|.SCGroupActionsMenu-drawer-root|Styles applied to the drawer root element.|
|
|
59
|
+
|menuRoot|.SCGroupActionsMenu-menu-root|Styles applied to the menu root element.|
|
|
60
|
+
|paper|.SCGroupActionsMenu-paper|Styles applied to the paper element.|
|
|
61
|
+
|item|.SCGroupActionsMenu-item|Styles applied to the item element.|
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
* @param inProps
|
|
65
|
+
*/
|
|
66
|
+
export default function GroupActionsMenu(inProps) {
|
|
67
|
+
var _a;
|
|
68
|
+
// PROPS
|
|
69
|
+
const props = useThemeProps({
|
|
70
|
+
props: inProps,
|
|
71
|
+
name: PREFIX
|
|
72
|
+
});
|
|
73
|
+
const { className, group, groupId, onDeleteConfirm, onEditSuccess } = props, rest = __rest(props, ["className", "group", "groupId", "onDeleteConfirm", "onEditSuccess"]);
|
|
74
|
+
// STATE
|
|
75
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
76
|
+
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
|
77
|
+
const [openEdit, setOpenEdit] = useState(false);
|
|
78
|
+
// HOOKS
|
|
79
|
+
const theme = useTheme();
|
|
80
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
81
|
+
const scRoutingContext = useSCRouting();
|
|
82
|
+
const scUserContext = useSCUser();
|
|
83
|
+
const { scGroup, setSCGroup } = useSCFetchGroup({ id: groupId, group });
|
|
84
|
+
const isGroupAdmin = useMemo(() => { var _a; return scUserContext.user && ((_a = scGroup === null || scGroup === void 0 ? void 0 : scGroup.managed_by) === null || _a === void 0 ? void 0 : _a.id) === scUserContext.user.id; }, [scUserContext.user, (_a = scGroup === null || scGroup === void 0 ? void 0 : scGroup.managed_by) === null || _a === void 0 ? void 0 : _a.id]);
|
|
85
|
+
// HANDLERS
|
|
86
|
+
const handleOpen = (group) => {
|
|
87
|
+
setAnchorEl(group.currentTarget);
|
|
88
|
+
};
|
|
89
|
+
const handleClose = () => {
|
|
90
|
+
setAnchorEl(null);
|
|
91
|
+
};
|
|
92
|
+
const handleEditClick = () => {
|
|
93
|
+
setOpenEdit((o) => !o);
|
|
94
|
+
};
|
|
95
|
+
const handleCloseDialog = () => {
|
|
96
|
+
setOpenConfirmDialog(false);
|
|
97
|
+
setAnchorEl(null);
|
|
98
|
+
};
|
|
99
|
+
const handleEditSuccess = (data) => {
|
|
100
|
+
setSCGroup(data);
|
|
101
|
+
onEditSuccess && onEditSuccess(data);
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Handles thread deletion
|
|
105
|
+
*/
|
|
106
|
+
function handleDeleteThread() {
|
|
107
|
+
GroupService.deleteGroup(scGroup.id)
|
|
108
|
+
.then(() => {
|
|
109
|
+
onDeleteConfirm();
|
|
110
|
+
handleCloseDialog();
|
|
111
|
+
PubSub.publish(`${SCTopicType.GROUP}.${SCGroupEventType.DELETE}`, scGroup.id);
|
|
112
|
+
})
|
|
113
|
+
.catch((error) => {
|
|
114
|
+
setOpenConfirmDialog(false);
|
|
115
|
+
console.log(error);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Handles actions
|
|
120
|
+
*/
|
|
121
|
+
function handleAction(action) {
|
|
122
|
+
if (action === GET_GROUP_LINK) {
|
|
123
|
+
copyTextToClipboard(`${location.protocol}//${location.host}${scRoutingContext.url(SCRoutes.GROUP_ROUTE_NAME, scGroup)}`).then(() => {
|
|
124
|
+
enqueueSnackbar(_jsx(FormattedMessage, { id: "ui.common.permanentLinkCopied", defaultMessage: "ui.common.permanentLinkCopied" }), {
|
|
125
|
+
variant: 'success',
|
|
126
|
+
autoHideDuration: 3000
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
handleClose();
|
|
130
|
+
}
|
|
131
|
+
else if (action === DELETE_GROUP) {
|
|
132
|
+
setOpenConfirmDialog(true);
|
|
133
|
+
handleClose();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
*
|
|
138
|
+
*/
|
|
139
|
+
const renderList = () => {
|
|
140
|
+
return [
|
|
141
|
+
_jsxs(MenuItem, Object.assign({ className: classes.item, onClick: () => handleAction(GET_GROUP_LINK) }, { children: [_jsx(ListItemIcon, { children: _jsx(Icon, { children: "link" }) }), _jsx(FormattedMessage, { id: "ui.groupActionsMenu.item.link", defaultMessage: "ui.groupActionsMenu.item.link" })] }), "link"),
|
|
142
|
+
isGroupAdmin &&
|
|
143
|
+
scGroup.active && [
|
|
144
|
+
_jsx(Divider, {}, "divider"),
|
|
145
|
+
isMobile && (_jsxs(MenuItem, Object.assign({ className: classes.item, onClick: handleEditClick }, { children: [_jsx(ListItemIcon, { children: _jsx(Icon, { children: "edit" }) }), _jsx(FormattedMessage, { id: "ui.groupActionsMenu.item.edit", defaultMessage: "ui.groupActionsMenu.item.edit" })] }), "edit")),
|
|
146
|
+
_jsxs(MenuItem, Object.assign({ className: classes.item, onClick: () => handleAction(DELETE_GROUP) }, { children: [_jsx(ListItemIcon, { children: _jsx(Icon, { children: "delete" }) }), _jsx(FormattedMessage, { id: "ui.groupActionsMenu.item.delete", defaultMessage: "ui.groupActionsMenu.item.delete" })] }), "delete")
|
|
147
|
+
]
|
|
148
|
+
];
|
|
149
|
+
};
|
|
150
|
+
if (!scGroup) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return (_jsxs(_Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { onClick: handleOpen }, { children: _jsx(Icon, { children: "more_vert" }) })), isMobile ? (_jsx(SwipeableDrawerRoot, Object.assign({ className: classes.drawerRoot, anchor: "bottom", open: Boolean(anchorEl), onClose: handleClose, onOpen: handleOpen, PaperProps: { className: classes.paper }, disableSwipeToOpen: true }, { children: _jsx(List, { children: renderList() }) }))) : (_jsx(MenuRoot, Object.assign({ className: classes.menuRoot, anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handleClose, PaperProps: { className: classes.paper } }, { children: renderList() }))), openConfirmDialog && (_jsx(ConfirmDialog, { open: openConfirmDialog, title: _jsx(FormattedMessage, { id: "ui.groupActionsMenu.dialog.msg", defaultMessage: "ui.groupActionsMenu.dialog.msg" }), btnConfirm: _jsx(FormattedMessage, { id: "ui.groupActionsMenu.dialog.confirm", defaultMessage: "ui.groupActionsMenu.dialog.confirm" }), onConfirm: handleDeleteThread, onClose: handleCloseDialog })), openEdit && _jsx(GroupForm, { onClose: handleEditClick, group: scGroup, onSuccess: handleEditSuccess })] }));
|
|
154
|
+
}
|
|
@@ -3,6 +3,7 @@ import { ChangeGroupCoverProps } from '../ChangeGroupCover';
|
|
|
3
3
|
import { ChangeGroupPictureProps } from '../ChangeGroupPicture';
|
|
4
4
|
import { GroupMembersButtonProps } from '../GroupMembersButton';
|
|
5
5
|
import { GroupSubscribeButtonProps } from '../GroupSubscribeButton';
|
|
6
|
+
import { GroupActionsMenuProps } from '../GroupActionsMenu';
|
|
6
7
|
export interface GroupHeaderProps {
|
|
7
8
|
/**
|
|
8
9
|
* Id of group object
|
|
@@ -44,6 +45,11 @@ export interface GroupHeaderProps {
|
|
|
44
45
|
* @default {}
|
|
45
46
|
*/
|
|
46
47
|
GroupMembersButtonProps?: GroupMembersButtonProps;
|
|
48
|
+
/**
|
|
49
|
+
* Props to spread event actions menu
|
|
50
|
+
* @default {}
|
|
51
|
+
*/
|
|
52
|
+
GroupActionsProps?: Omit<GroupActionsMenuProps, 'group'>;
|
|
47
53
|
/**
|
|
48
54
|
* Any other properties
|
|
49
55
|
*/
|
|
@@ -2,7 +2,7 @@ import { __rest } from "tslib";
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
|
-
import { Avatar, Box, Icon, Paper, Typography } from '@mui/material';
|
|
5
|
+
import { Avatar, Box, Icon, Paper, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
6
6
|
import { SCGroupPrivacyType, SCGroupSubscriptionStatusType } from '@selfcommunity/types';
|
|
7
7
|
import { SCPreferences, useSCFetchGroup, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
|
|
8
8
|
import GroupHeaderSkeleton from './Skeleton';
|
|
@@ -19,6 +19,7 @@ import GroupSubscribeButton from '../GroupSubscribeButton';
|
|
|
19
19
|
import GroupInviteButton from '../GroupInviteButton';
|
|
20
20
|
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
|
|
21
21
|
import PubSub from 'pubsub-js';
|
|
22
|
+
import GroupActionsMenu from '../GroupActionsMenu';
|
|
22
23
|
const classes = {
|
|
23
24
|
root: `${PREFIX}-root`,
|
|
24
25
|
cover: `${PREFIX}-cover`,
|
|
@@ -30,7 +31,8 @@ const classes = {
|
|
|
30
31
|
visibility: `${PREFIX}-visibility`,
|
|
31
32
|
visibilityItem: `${PREFIX}-visibility-item`,
|
|
32
33
|
members: `${PREFIX}-members`,
|
|
33
|
-
membersCounter: `${PREFIX}-members-counter
|
|
34
|
+
membersCounter: `${PREFIX}-members-counter`,
|
|
35
|
+
multiActions: `${PREFIX}-multi-actions`
|
|
34
36
|
};
|
|
35
37
|
const Root = styled(Box, {
|
|
36
38
|
name: PREFIX,
|
|
@@ -74,7 +76,7 @@ export default function GroupHeader(inProps) {
|
|
|
74
76
|
props: inProps,
|
|
75
77
|
name: PREFIX
|
|
76
78
|
});
|
|
77
|
-
const { id = null, className = null, group, groupId = null, ChangePictureProps = {}, ChangeCoverProps = {}, GroupSubscribeButtonProps = {}, GroupMembersButtonProps = {} } = props, rest = __rest(props, ["id", "className", "group", "groupId", "ChangePictureProps", "ChangeCoverProps", "GroupSubscribeButtonProps", "GroupMembersButtonProps"]);
|
|
79
|
+
const { id = null, className = null, group, groupId = null, ChangePictureProps = {}, ChangeCoverProps = {}, GroupSubscribeButtonProps = {}, GroupMembersButtonProps = {}, GroupActionsProps } = props, rest = __rest(props, ["id", "className", "group", "groupId", "ChangePictureProps", "ChangeCoverProps", "GroupSubscribeButtonProps", "GroupMembersButtonProps", "GroupActionsProps"]);
|
|
78
80
|
// PREFERENCES
|
|
79
81
|
const scPreferences = useSCPreferences();
|
|
80
82
|
const visibilityEnabled = useMemo(() => scPreferences.preferences[SCPreferences.CONFIGURATIONS_GROUPS_VISIBILITY_ENABLED].value, [scPreferences.preferences]);
|
|
@@ -83,6 +85,8 @@ export default function GroupHeader(inProps) {
|
|
|
83
85
|
const scUserContext = useSCUser();
|
|
84
86
|
// HOOKS
|
|
85
87
|
const { scGroup, setSCGroup } = useSCFetchGroup({ id: groupId, group });
|
|
88
|
+
const theme = useTheme();
|
|
89
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
86
90
|
// REFS
|
|
87
91
|
const updatesSubscription = useRef(null);
|
|
88
92
|
// CONST
|
|
@@ -145,7 +149,7 @@ export default function GroupHeader(inProps) {
|
|
|
145
149
|
const _backgroundCover = Object.assign({}, (scGroup.emotional_image
|
|
146
150
|
? { background: `url('${scGroup.emotional_image}') center / cover` }
|
|
147
151
|
: { background: `url('${scPreferences.preferences[SCPreferences.IMAGES_USER_DEFAULT_COVER].value}') center / cover` }));
|
|
148
|
-
return (_jsxs(Root, Object.assign({ id: id, className: classNames(classes.root, className) }, rest, { children: [_jsxs(Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: [_jsx(Box, Object.assign({ className: classes.avatar }, { children: _jsx(Avatar, { children: _jsx("img", { alt: "group", src: scGroup.image_big ? scGroup.image_big : '' }) }) })), isGroupAdmin && (_jsxs(_Fragment, { children: [_jsx(ChangeGroupPicture, Object.assign({ groupId: scGroup.id, onChange: handleChangeAvatar, className: classes.changePicture }, ChangePictureProps)), _jsx("div", Object.assign({ className: classes.changeCover }, { children: _jsx(ChangeGroupCover, Object.assign({ groupId: scGroup.id, onChange: handleChangeCover }, ChangeCoverProps)) }))] }))] })), _jsxs(Box, Object.assign({ className: classes.info }, { children: [isGroupAdmin && _jsx(EditGroupButton, { group: scGroup, groupId: scGroup.id, onEditSuccess: (data) => setSCGroup(data) }), _jsx(Typography, Object.assign({ variant: "h5", className: classes.name }, { children: scGroup.name })), privateEnabled && (_jsxs(Box, Object.assign({ className: classes.visibility }, { children: [privateEnabled && (_jsx(_Fragment, { children: scGroup.privacy === SCGroupPrivacyType.PUBLIC ? (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.public", defaultMessage: "ui.groupHeader.visibility.public" })] }))) : (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.private", defaultMessage: "ui.groupHeader.visibility.private" })] }))) })), visibilityEnabled && (_jsxs(_Fragment, { children: [privateEnabled && _jsx(Bullet, {}), scGroup.visible ? (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "visibility" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.visible", defaultMessage: "ui.groupHeader.visibility.visible" })] }))) : (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "visibility_off" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.hidden", defaultMessage: "ui.groupHeader.visibility.hidden" })] })))] }))] }))), _jsx(_Fragment, { children: ((scGroup && scGroup.privacy === SCGroupPrivacyType.PUBLIC) ||
|
|
152
|
+
return (_jsxs(Root, Object.assign({ id: id, className: classNames(classes.root, className) }, rest, { children: [_jsxs(Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: [_jsx(Box, Object.assign({ className: classes.avatar }, { children: _jsx(Avatar, { children: _jsx("img", { alt: "group", src: scGroup.image_big ? scGroup.image_big : '' }) }) })), isGroupAdmin && (_jsxs(_Fragment, { children: [_jsx(ChangeGroupPicture, Object.assign({ groupId: scGroup.id, onChange: handleChangeAvatar, className: classes.changePicture }, ChangePictureProps)), _jsx("div", Object.assign({ className: classes.changeCover }, { children: _jsx(ChangeGroupCover, Object.assign({ groupId: scGroup.id, onChange: handleChangeCover }, ChangeCoverProps)) }))] }))] })), _jsxs(Box, Object.assign({ className: classes.info }, { children: [isGroupAdmin && !isMobile && (_jsxs(Box, Object.assign({ className: classes.multiActions }, { children: [_jsx(EditGroupButton, { group: scGroup, groupId: scGroup.id, onEditSuccess: (data) => setSCGroup(data) }), _jsx(GroupActionsMenu, Object.assign({ group: scGroup, onEditSuccess: (data) => setSCGroup(data) }, GroupActionsProps))] }))), _jsx(Typography, Object.assign({ variant: "h5", className: classes.name }, { children: scGroup.name })), privateEnabled && (_jsxs(Box, Object.assign({ className: classes.visibility }, { children: [privateEnabled && (_jsx(_Fragment, { children: scGroup.privacy === SCGroupPrivacyType.PUBLIC ? (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.public", defaultMessage: "ui.groupHeader.visibility.public" })] }))) : (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.private", defaultMessage: "ui.groupHeader.visibility.private" })] }))) })), visibilityEnabled && (_jsxs(_Fragment, { children: [privateEnabled && _jsx(Bullet, {}), scGroup.visible ? (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "visibility" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.visible", defaultMessage: "ui.groupHeader.visibility.visible" })] }))) : (_jsxs(Typography, Object.assign({ className: classes.visibilityItem }, { children: [_jsx(Icon, { children: "visibility_off" }), _jsx(FormattedMessage, { id: "ui.groupHeader.visibility.hidden", defaultMessage: "ui.groupHeader.visibility.hidden" })] })))] }))] }))), _jsx(_Fragment, { children: ((scGroup && scGroup.privacy === SCGroupPrivacyType.PUBLIC) ||
|
|
149
153
|
scGroup.subscription_status === SCGroupSubscriptionStatusType.SUBSCRIBED ||
|
|
150
|
-
isGroupAdmin) && (_jsxs(Box, Object.assign({ className: classes.members }, { children: [_jsx(Typography, Object.assign({ className: classes.membersCounter, component: "div" }, { children: _jsx(FormattedMessage, { id: "ui.groupHeader.members", defaultMessage: "ui.groupHeader.members", values: { total: scGroup.subscribers_counter } }) })), _jsx(GroupMembersButton, Object.assign({ groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, group: scGroup, autoHide: !isGroupAdmin }, GroupMembersButtonProps), scGroup.subscribers_counter)] }))) }), isGroupAdmin ? (_jsx(GroupInviteButton, { group: scGroup, groupId: scGroup.id })) : (_jsx(GroupSubscribeButton, Object.assign({ group: scGroup, onSubscribe: handleSubscribe }, GroupSubscribeButtonProps)))] }))] })));
|
|
154
|
+
isGroupAdmin) && (_jsxs(Box, Object.assign({ className: classes.members }, { children: [_jsx(Typography, Object.assign({ className: classes.membersCounter, component: "div" }, { children: _jsx(FormattedMessage, { id: "ui.groupHeader.members", defaultMessage: "ui.groupHeader.members", values: { total: scGroup.subscribers_counter } }) })), _jsx(GroupMembersButton, Object.assign({ groupId: scGroup === null || scGroup === void 0 ? void 0 : scGroup.id, group: scGroup, autoHide: !isGroupAdmin }, GroupMembersButtonProps), scGroup.subscribers_counter)] }))) }), isGroupAdmin ? (_jsxs(Box, { children: [_jsx(GroupInviteButton, { group: scGroup, groupId: scGroup.id }), isMobile && _jsx(GroupActionsMenu, Object.assign({ group: scGroup, onEditSuccess: (data) => setSCGroup(data) }, GroupActionsProps))] })) : (_jsx(GroupSubscribeButton, Object.assign({ group: scGroup, onSubscribe: handleSubscribe }, GroupSubscribeButtonProps)))] }))] })));
|
|
151
155
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
5
|
import { Box, Button, Grid, TextField, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
6
6
|
import { Endpoints, GroupService, http } from '@selfcommunity/api-services';
|
|
@@ -16,6 +16,8 @@ import { PREFIX } from './constants';
|
|
|
16
16
|
import Group, { GroupSkeleton } from '../Group';
|
|
17
17
|
import { DEFAULT_PAGINATION_OFFSET } from '../../constants/Pagination';
|
|
18
18
|
import InfiniteScroll from '../../shared/InfiniteScroll';
|
|
19
|
+
import PubSub from 'pubsub-js';
|
|
20
|
+
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
|
|
19
21
|
const classes = {
|
|
20
22
|
root: `${PREFIX}-root`,
|
|
21
23
|
filters: `${PREFIX}-filter`,
|
|
@@ -83,6 +85,8 @@ export default function Groups(inProps) {
|
|
|
83
85
|
scPreferencesContext.preferences[SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value, [scPreferencesContext.preferences]);
|
|
84
86
|
// CONST
|
|
85
87
|
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
88
|
+
// REFS
|
|
89
|
+
const updatesSubscription = useRef(null);
|
|
86
90
|
// HANDLERS
|
|
87
91
|
const handleScrollUp = () => {
|
|
88
92
|
window.scrollTo({ left: 0, top: 0, behavior: 'smooth' });
|
|
@@ -119,6 +123,28 @@ export default function Groups(inProps) {
|
|
|
119
123
|
fetchGroups();
|
|
120
124
|
}
|
|
121
125
|
}, [contentAvailability, authUserId, search]);
|
|
126
|
+
/**
|
|
127
|
+
* Subscriber for pubsub callback
|
|
128
|
+
*/
|
|
129
|
+
const onDeleteGroupHandler = useCallback((_msg, deleted) => {
|
|
130
|
+
setGroups((prev) => {
|
|
131
|
+
if (prev.some((e) => e.id === deleted)) {
|
|
132
|
+
return prev.filter((e) => e.id !== deleted);
|
|
133
|
+
}
|
|
134
|
+
return prev;
|
|
135
|
+
});
|
|
136
|
+
}, [groups]);
|
|
137
|
+
/**
|
|
138
|
+
* On mount, subscribe to receive event updates (only delete)
|
|
139
|
+
*/
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (groups) {
|
|
142
|
+
updatesSubscription.current = PubSub.subscribe(`${SCTopicType.GROUP}.${SCGroupEventType.DELETE}`, onDeleteGroupHandler);
|
|
143
|
+
}
|
|
144
|
+
return () => {
|
|
145
|
+
updatesSubscription.current && PubSub.unsubscribe(updatesSubscription.current);
|
|
146
|
+
};
|
|
147
|
+
}, [groups]);
|
|
122
148
|
const handleNext = useMemo(() => () => {
|
|
123
149
|
if (!next) {
|
|
124
150
|
return;
|
|
@@ -4,7 +4,7 @@ import { Button, CardActions, Icon, IconButton, Typography } from '@mui/material
|
|
|
4
4
|
import { styled } from '@mui/material/styles';
|
|
5
5
|
import { Box, useThemeProps } from '@mui/system';
|
|
6
6
|
import { Endpoints, EventService, http } from '@selfcommunity/api-services';
|
|
7
|
-
import { SCCache, SCRoutes, useSCPreferences, useSCRouting, useSCUser } from '@selfcommunity/react-core';
|
|
7
|
+
import { SCCache, SCPreferences, SCRoutes, useSCPreferences, useSCRouting, useSCUser } from '@selfcommunity/react-core';
|
|
8
8
|
import { SCEventSubscriptionStatusType, SCFeatureName } from '@selfcommunity/types';
|
|
9
9
|
import { Logger } from '@selfcommunity/utils';
|
|
10
10
|
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
|
|
@@ -64,8 +64,12 @@ export default function MyEventsWidget(inProps) {
|
|
|
64
64
|
// CONTEXT
|
|
65
65
|
const scUserContext = useSCUser();
|
|
66
66
|
const scRoutingContext = useSCRouting();
|
|
67
|
-
const { features } = useSCPreferences();
|
|
68
|
-
const eventsEnabled = useMemo(() =>
|
|
67
|
+
const { preferences, features } = useSCPreferences();
|
|
68
|
+
const eventsEnabled = useMemo(() => preferences &&
|
|
69
|
+
features &&
|
|
70
|
+
features.includes(SCFeatureName.TAGGING) &&
|
|
71
|
+
SCPreferences.CONFIGURATIONS_EVENTS_ENABLED in preferences &&
|
|
72
|
+
preferences[SCPreferences.CONFIGURATIONS_EVENTS_ENABLED].value, [preferences, features]);
|
|
69
73
|
// REFS
|
|
70
74
|
const updatesSubscription = useRef(null);
|
|
71
75
|
/**
|
|
@@ -108,12 +108,21 @@ export default function NavigationToolbar(inProps) {
|
|
|
108
108
|
return _preferences;
|
|
109
109
|
}, [scPreferences.preferences]);
|
|
110
110
|
const privateMessagingEnabled = useMemo(() => scPreferences.features.includes(SCFeatureName.PRIVATE_MESSAGING), [scPreferences.features]);
|
|
111
|
-
const groupsEnabled = useMemo(() => scPreferences.
|
|
112
|
-
|
|
111
|
+
const groupsEnabled = useMemo(() => scPreferences.preferences &&
|
|
112
|
+
scPreferences.features &&
|
|
113
|
+
scPreferences.features.includes(SCFeatureName.TAGGING) &&
|
|
114
|
+
scPreferences.features.includes(SCFeatureName.GROUPING) &&
|
|
115
|
+
SCPreferences.CONFIGURATIONS_GROUPS_ENABLED in scPreferences.preferences &&
|
|
116
|
+
scPreferences.preferences[SCPreferences.CONFIGURATIONS_GROUPS_ENABLED].value, [scPreferences.preferences, scPreferences.features]);
|
|
117
|
+
const eventsEnabled = useMemo(() => scPreferences.preferences &&
|
|
118
|
+
scPreferences.features &&
|
|
119
|
+
scPreferences.features.includes(SCFeatureName.TAGGING) &&
|
|
120
|
+
SCPreferences.CONFIGURATIONS_EVENTS_ENABLED in scPreferences.preferences &&
|
|
121
|
+
scPreferences.preferences[SCPreferences.CONFIGURATIONS_EVENTS_ENABLED].value, [scPreferences.preferences, scPreferences.features]);
|
|
113
122
|
const showComposer = useMemo(() => {
|
|
114
123
|
return (!disableComposer &&
|
|
115
124
|
(!scPreferences.preferences[SCPreferences.CONFIGURATIONS_POST_ONLY_STAFF_ENABLED].value || UserUtils.isStaff(scUserContext.user)));
|
|
116
|
-
}, [
|
|
125
|
+
}, [preferences, disableComposer, scUserContext.user]);
|
|
117
126
|
// STATE
|
|
118
127
|
const [anchorNotification, setAnchorNotification] = React.useState(null);
|
|
119
128
|
// HANDLERS
|
|
@@ -78,8 +78,17 @@ export default function NavigationToolbarMobile(inProps) {
|
|
|
78
78
|
// STATE
|
|
79
79
|
const [searchOpen, setSearchOpen] = useState(false);
|
|
80
80
|
// MEMO
|
|
81
|
-
const groupsEnabled = useMemo(() =>
|
|
82
|
-
|
|
81
|
+
const groupsEnabled = useMemo(() => preferences &&
|
|
82
|
+
features &&
|
|
83
|
+
features.includes(SCFeatureName.TAGGING) &&
|
|
84
|
+
features.includes(SCFeatureName.GROUPING) &&
|
|
85
|
+
SCPreferences.CONFIGURATIONS_GROUPS_ENABLED in preferences &&
|
|
86
|
+
preferences[SCPreferences.CONFIGURATIONS_GROUPS_ENABLED].value, [preferences, features]);
|
|
87
|
+
const eventsEnabled = useMemo(() => preferences &&
|
|
88
|
+
features &&
|
|
89
|
+
features.includes(SCFeatureName.TAGGING) &&
|
|
90
|
+
SCPreferences.CONFIGURATIONS_EVENTS_ENABLED in preferences &&
|
|
91
|
+
preferences[SCPreferences.CONFIGURATIONS_EVENTS_ENABLED].value, [preferences, features]);
|
|
83
92
|
const exploreStreamEnabled = preferences[SCPreferences.CONFIGURATIONS_EXPLORE_STREAM_ENABLED].value;
|
|
84
93
|
const postOnlyStaffEnabled = preferences[SCPreferences.CONFIGURATIONS_POST_ONLY_STAFF_ENABLED].value;
|
|
85
94
|
const contentAvailable = preferences[SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value;
|
|
@@ -51,6 +51,8 @@ export default function EventNotification(props) {
|
|
|
51
51
|
}), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null }, { children: _jsx(UserAvatar, Object.assign({ hide: !notificationObject.user.community_badge, smaller: true }, { children: _jsx(Avatar, { alt: notificationObject.user.username, variant: "circular", src: notificationObject.user.avatar, classes: { root: classes.avatar } }) })) })), primary: _jsxs(Box, { children: [_jsx(Link, Object.assign({}, (!notificationObject.user.deleted && {
|
|
52
52
|
to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.user)
|
|
53
53
|
}), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: notificationObject.user.username })), ' ', _jsx(FormattedMessage, { id: `ui.notification.event.${notificationObject.type}`, defaultMessage: `ui.notification.event.${notificationObject.type}`, values: {
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
55
|
+
// @ts-ignore
|
|
54
56
|
icon: (...chunks) => _jsx(Icon, { children: chunks }),
|
|
55
57
|
event: notificationObject.event.name,
|
|
56
58
|
link: (...chunks) => _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes.EVENT_ROUTE_NAME, notificationObject.event) }, { children: chunks }))
|
|
@@ -69,6 +71,8 @@ export default function EventNotification(props) {
|
|
|
69
71
|
}), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null }, { children: _jsx(UserAvatar, Object.assign({ hide: !notificationObject.user.community_badge, smaller: true }, { children: _jsx(Avatar, { className: classes.avatar, alt: notificationObject.user.username, variant: "circular", src: notificationObject.user.avatar }) })) })), primary: _jsxs(_Fragment, { children: [_jsx(Link, Object.assign({}, (!notificationObject.user.deleted && {
|
|
70
72
|
to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.user)
|
|
71
73
|
}), { onClick: notificationObject.user.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: notificationObject.user.username })), ' ', _jsx(FormattedMessage, { id: `ui.notification.${notificationObject.type}`, defaultMessage: `ui.notification.${notificationObject.type}`, values: {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
75
|
+
// @ts-ignore
|
|
72
76
|
icon: (...chunks) => _jsx(Icon, { children: chunks }),
|
|
73
77
|
event: notificationObject.event.name,
|
|
74
78
|
link: (...chunks) => _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes.EVENT_ROUTE_NAME, notificationObject.event) }, { children: chunks }))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StartStepParams } from '@selfcommunity/api-services';
|
|
2
|
-
import { SCFeedObjectType } from '@selfcommunity/types';
|
|
2
|
+
import { SCFeedObjectType, SCOnBoardingStepType } from '@selfcommunity/types';
|
|
3
3
|
import { VirtualScrollerItemProps } from '../../types/virtualScroller';
|
|
4
4
|
export interface OnBoardingWidgetProps extends VirtualScrollerItemProps {
|
|
5
5
|
/**
|
|
@@ -18,6 +18,15 @@ export interface OnBoardingWidgetProps extends VirtualScrollerItemProps {
|
|
|
18
18
|
* @default null
|
|
19
19
|
*/
|
|
20
20
|
onGeneratedContent?: (feedObjs: SCFeedObjectType[]) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Force widget expanded
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
forceExpanded?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The initial step to display
|
|
28
|
+
*/
|
|
29
|
+
initialStep?: SCOnBoardingStepType;
|
|
21
30
|
}
|
|
22
31
|
declare const OnBoardingWidget: (inProps: OnBoardingWidgetProps) => JSX.Element;
|
|
23
32
|
export default OnBoardingWidget;
|
|
@@ -8,7 +8,7 @@ import classNames from 'classnames';
|
|
|
8
8
|
import { useThemeProps } from '@mui/system';
|
|
9
9
|
import Category from './Steps/Category';
|
|
10
10
|
import { PREFIX } from './constants';
|
|
11
|
-
import { getTheme, usePreviousValue, UserUtils, useSCContext, useSCPreferences, useSCTheme, useSCUser } from '@selfcommunity/react-core';
|
|
11
|
+
import { getTheme, usePreviousValue, UserUtils, useSCContext, useSCFetchCategories, useSCPreferences, useSCTheme, useSCUser } from '@selfcommunity/react-core';
|
|
12
12
|
import Appearance from './Steps/Appearance';
|
|
13
13
|
import Profile from './Steps/Profile';
|
|
14
14
|
import Invite from './Steps/Invite';
|
|
@@ -17,13 +17,13 @@ import HiddenPlaceholder from '../../shared/HiddenPlaceholder';
|
|
|
17
17
|
import Widget from '../Widget';
|
|
18
18
|
import Content from './Steps/Content';
|
|
19
19
|
import { SCOPE_SC_UI } from '../../constants/Errors';
|
|
20
|
-
import { OnBoardingService, PreferenceService } from '@selfcommunity/api-services';
|
|
20
|
+
import { Endpoints, http, OnBoardingService, PreferenceService } from '@selfcommunity/api-services';
|
|
21
21
|
import { Logger } from '@selfcommunity/utils';
|
|
22
22
|
import { SCOnBoardingStepStatusType, SCOnBoardingStepType } from '@selfcommunity/types';
|
|
23
23
|
import OnBoardingWidgetSkeleton from './Skeleton';
|
|
24
24
|
import { closeSnackbar, useSnackbar } from 'notistack';
|
|
25
|
-
import { CONSOLE_PROD, CONSOLE_STAGE } from '../PlatformWidget/constants';
|
|
26
25
|
import HeaderPlaceholder from '../../assets/onBoarding/header';
|
|
26
|
+
import BaseDialog from '../../shared/BaseDialog';
|
|
27
27
|
const classes = {
|
|
28
28
|
root: `${PREFIX}-root`,
|
|
29
29
|
content: `${PREFIX}-content`,
|
|
@@ -50,24 +50,25 @@ const OnBoardingWidget = (inProps) => {
|
|
|
50
50
|
props: inProps,
|
|
51
51
|
name: PREFIX
|
|
52
52
|
});
|
|
53
|
-
const { className, GenerateContentsParams = {}, onGeneratedContent = null, onHeightChange } = props, rest = __rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange"]);
|
|
53
|
+
const { className, GenerateContentsParams = {}, onGeneratedContent = null, onHeightChange, onStateChange, forceExpanded = false, initialStep } = props, rest = __rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange", "onStateChange", "forceExpanded", "initialStep"]);
|
|
54
54
|
// STATE
|
|
55
|
-
const [
|
|
55
|
+
const [loading, setLoading] = useState(true);
|
|
56
56
|
const [initialized, setInitialized] = useState(false);
|
|
57
57
|
const [steps, setSteps] = useState([]);
|
|
58
58
|
const nextStep = useMemo(() => {
|
|
59
|
-
const step = steps === null || steps === void 0 ? void 0 : steps.find((step) => step.status === 'in_progress' || step.status === 'not_started');
|
|
59
|
+
const step = steps === null || steps === void 0 ? void 0 : steps.find((step) => (initialStep ? step.step === initialStep : step.status === 'in_progress' || step.status === 'not_started'));
|
|
60
60
|
return step || (steps === null || steps === void 0 ? void 0 : steps[0]);
|
|
61
61
|
}, [steps]);
|
|
62
62
|
const allStepsDone = useMemo(() => {
|
|
63
63
|
return steps === null || steps === void 0 ? void 0 : steps.every((step) => step.status === SCOnBoardingStepStatusType.COMPLETED);
|
|
64
64
|
}, [steps]);
|
|
65
|
-
const [expanded, setExpanded] = useState(!allStepsDone);
|
|
65
|
+
const [expanded, setExpanded] = useState(!allStepsDone || forceExpanded);
|
|
66
66
|
const [_step, setStep] = useState(nextStep);
|
|
67
67
|
const currentContentsStep = steps === null || steps === void 0 ? void 0 : steps.find((s) => s.step === SCOnBoardingStepType.CONTENTS);
|
|
68
68
|
const prevContentsStep = usePreviousValue(currentContentsStep);
|
|
69
69
|
const currentCategoriesStep = steps === null || steps === void 0 ? void 0 : steps.find((s) => s.step === SCOnBoardingStepType.CATEGORIES);
|
|
70
70
|
const prevCategoriesStep = usePreviousValue(currentCategoriesStep);
|
|
71
|
+
const [showCategoriesModal, setShowCategoriesModal] = useState(false);
|
|
71
72
|
// CONTEXT
|
|
72
73
|
const scUserContext = useSCUser();
|
|
73
74
|
const isAdmin = useMemo(() => UserUtils.isCommunityCreator(scUserContext.user), [scUserContext.user]);
|
|
@@ -75,12 +76,21 @@ const OnBoardingWidget = (inProps) => {
|
|
|
75
76
|
const scPreferencesContext = useSCPreferences();
|
|
76
77
|
const scThemeContext = useSCTheme();
|
|
77
78
|
const { enqueueSnackbar } = useSnackbar();
|
|
78
|
-
const isStage = scContext.settings.portal.includes('stage');
|
|
79
79
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
80
80
|
// HOOKS
|
|
81
81
|
const theme = useTheme();
|
|
82
82
|
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
|
83
|
+
const { categories, isLoading } = useSCFetchCategories();
|
|
83
84
|
// HANDLERS
|
|
85
|
+
/**
|
|
86
|
+
* Notify changes to Feed if the Widget is contained
|
|
87
|
+
*/
|
|
88
|
+
const notifyLayoutChanges = useMemo(() => (state) => {
|
|
89
|
+
if (onStateChange && state) {
|
|
90
|
+
onStateChange(state);
|
|
91
|
+
}
|
|
92
|
+
onHeightChange && onHeightChange();
|
|
93
|
+
}, [onStateChange, onHeightChange]);
|
|
84
94
|
const completeStep = (s) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
95
|
if (s.status !== SCOnBoardingStepStatusType.COMPLETED) {
|
|
86
96
|
yield OnBoardingService.completeAStep(s.id)
|
|
@@ -98,10 +108,30 @@ const OnBoardingWidget = (inProps) => {
|
|
|
98
108
|
}
|
|
99
109
|
s.step === SCOnBoardingStepType.APPEARANCE && handlePreferencesUpdate();
|
|
100
110
|
});
|
|
111
|
+
/**
|
|
112
|
+
* Fetches platform url
|
|
113
|
+
*/
|
|
114
|
+
function fetchPlatform(query) {
|
|
115
|
+
http
|
|
116
|
+
.request({
|
|
117
|
+
url: Endpoints.Platform.url(),
|
|
118
|
+
method: Endpoints.Platform.method,
|
|
119
|
+
params: {
|
|
120
|
+
next: query
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.then((res) => {
|
|
124
|
+
const platformUrl = res.data.platform_url;
|
|
125
|
+
window.open(platformUrl, '_blank').focus();
|
|
126
|
+
})
|
|
127
|
+
.catch((error) => {
|
|
128
|
+
console.log(error);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
101
131
|
const showSuccessAlert = (step) => {
|
|
102
132
|
setIsGenerating(false);
|
|
103
133
|
enqueueSnackbar(_jsx(FormattedMessage, { id: `ui.onBoardingWidget.step.${step.step}.success`, defaultMessage: `ui.onBoardingWidget.step.${step.step}.success` }), {
|
|
104
|
-
action: (snackbarId) => (_jsxs(_Fragment, { children: [step.step === SCOnBoardingStepType.CATEGORIES && (_jsx(Button, Object.assign({ sx: { textTransform: 'uppercase', color: 'white' }, size: "small", variant: "text",
|
|
134
|
+
action: (snackbarId) => (_jsxs(_Fragment, { children: [step.step === SCOnBoardingStepType.CATEGORIES && (_jsx(Button, Object.assign({ sx: { textTransform: 'uppercase', color: 'white' }, size: "small", variant: "text", onClick: () => fetchPlatform('/contents/interests/') }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.categories.success.link", defaultMessage: "ui.onBoardingWidget.step.categories.success.link" }) }))), _jsx(IconButton, Object.assign({ sx: { color: 'white' }, onClick: () => closeSnackbar(snackbarId) }, { children: _jsx(Icon, { children: "close" }) }))] })),
|
|
105
135
|
variant: 'success',
|
|
106
136
|
autoHideDuration: 7000
|
|
107
137
|
});
|
|
@@ -112,35 +142,41 @@ const OnBoardingWidget = (inProps) => {
|
|
|
112
142
|
const contentStep = res.results.find((step) => step.step === SCOnBoardingStepType.CONTENTS);
|
|
113
143
|
setIsGenerating(res.results.some((step) => step.status === 'in_progress'));
|
|
114
144
|
setSteps(res.results);
|
|
115
|
-
|
|
145
|
+
setLoading(false);
|
|
116
146
|
if (contentStep.status === SCOnBoardingStepStatusType.IN_PROGRESS && contentStep.results.length !== 0 && onGeneratedContent) {
|
|
117
147
|
onGeneratedContent(contentStep.results);
|
|
118
148
|
}
|
|
119
149
|
})
|
|
120
150
|
.catch((error) => {
|
|
121
151
|
Logger.error(SCOPE_SC_UI, error);
|
|
122
|
-
|
|
152
|
+
setLoading(false);
|
|
123
153
|
});
|
|
124
154
|
});
|
|
125
155
|
const handleChange = (newStep) => {
|
|
126
156
|
setStep(newStep);
|
|
127
157
|
};
|
|
128
158
|
const handleExpand = () => {
|
|
129
|
-
|
|
130
|
-
|
|
159
|
+
const _expanded = !expanded;
|
|
160
|
+
setExpanded(_expanded);
|
|
161
|
+
notifyLayoutChanges({ forceExpanded: _expanded });
|
|
131
162
|
};
|
|
132
163
|
const generateContent = (stepId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
164
|
+
if (!isLoading && !categories.length) {
|
|
165
|
+
setShowCategoriesModal(true);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
yield OnBoardingService.startAStep(stepId, GenerateContentsParams)
|
|
169
|
+
.then(() => {
|
|
170
|
+
setIsGenerating(true);
|
|
171
|
+
})
|
|
172
|
+
.catch((error) => {
|
|
173
|
+
Logger.error(SCOPE_SC_UI, error);
|
|
174
|
+
enqueueSnackbar(_jsx(FormattedMessage, { id: "ui.common.error.action", defaultMessage: "ui.common.error.action" }), {
|
|
175
|
+
variant: 'error',
|
|
176
|
+
autoHideDuration: 3000
|
|
177
|
+
});
|
|
142
178
|
});
|
|
143
|
-
}
|
|
179
|
+
}
|
|
144
180
|
});
|
|
145
181
|
const handlePreferencesUpdate = () => {
|
|
146
182
|
PreferenceService.getAllPreferences().then((preferences) => {
|
|
@@ -149,10 +185,14 @@ const OnBoardingWidget = (inProps) => {
|
|
|
149
185
|
scThemeContext.setTheme(getTheme(scContext.settings.theme, prefs));
|
|
150
186
|
});
|
|
151
187
|
};
|
|
188
|
+
const handleCategoriesClick = () => {
|
|
189
|
+
fetchPlatform('/contents/interests/');
|
|
190
|
+
setShowCategoriesModal(false);
|
|
191
|
+
};
|
|
152
192
|
// EFFECTS
|
|
153
193
|
useEffect(() => {
|
|
154
194
|
if (prevContentsStep &&
|
|
155
|
-
|
|
195
|
+
prevContentsStep.status === SCOnBoardingStepStatusType.IN_PROGRESS &&
|
|
156
196
|
(currentContentsStep === null || currentContentsStep === void 0 ? void 0 : currentContentsStep.status) === SCOnBoardingStepStatusType.COMPLETED) {
|
|
157
197
|
showSuccessAlert(currentContentsStep);
|
|
158
198
|
}
|
|
@@ -168,11 +208,13 @@ const OnBoardingWidget = (inProps) => {
|
|
|
168
208
|
if (!initialized && nextStep) {
|
|
169
209
|
setStep(nextStep);
|
|
170
210
|
setInitialized(true);
|
|
211
|
+
notifyLayoutChanges({ forceExpanded: expanded });
|
|
171
212
|
}
|
|
172
213
|
}, [initialized, nextStep]);
|
|
173
214
|
useEffect(() => {
|
|
174
|
-
|
|
175
|
-
|
|
215
|
+
const _expanded = !allStepsDone;
|
|
216
|
+
setExpanded(_expanded);
|
|
217
|
+
notifyLayoutChanges({ forceExpanded: _expanded });
|
|
176
218
|
}, [allStepsDone]);
|
|
177
219
|
useEffect(() => {
|
|
178
220
|
if (isAdmin) {
|
|
@@ -232,7 +274,8 @@ const OnBoardingWidget = (inProps) => {
|
|
|
232
274
|
b: (chunks) => _jsx("strong", { children: chunks }),
|
|
233
275
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
234
276
|
// @ts-ignore
|
|
235
|
-
|
|
236
|
-
|
|
277
|
+
// eslint-disable-next-line prettier/prettier
|
|
278
|
+
icon: (...chunks) => _jsx(Icon, Object.assign({ color: "secondary", fontSize: "medium" }, { children: chunks }))
|
|
279
|
+
} }) }))) }) })), _jsx(AccordionDetails, { children: _jsx(Widget, Object.assign({ className: classes.content, elevation: 0 }, { children: loading ? (_jsx(OnBoardingWidgetSkeleton, {})) : (_jsxs(CardContent, { children: [_jsx(List, Object.assign({ className: isMobile ? classes.stepsMobile : classes.steps }, { children: steps === null || steps === void 0 ? void 0 : steps.map((step) => (_jsx(ListItem, { children: isMobile ? (_jsx(Chip, { size: "small", label: _jsxs(_Fragment, { children: [_jsx(FormattedMessage, { id: `ui.onBoardingWidget.${step.step}`, defaultMessage: `ui.onBoardingWidget.${step.step}` }), ' ', step.status === SCOnBoardingStepStatusType.COMPLETED && (_jsx(Icon, Object.assign({ color: (step === null || step === void 0 ? void 0 : step.status) === SCOnBoardingStepStatusType.COMPLETED && (step === null || step === void 0 ? void 0 : step.step) !== (_step === null || _step === void 0 ? void 0 : _step.step) ? 'success' : 'inherit' }, { children: "check" })))] }), onClick: () => handleChange(step), variant: step.step === (_step === null || _step === void 0 ? void 0 : _step.step) ? 'filled' : 'outlined', color: step.status === SCOnBoardingStepStatusType.COMPLETED ? 'success' : 'default' })) : (_jsxs(ListItemButton, Object.assign({ onClick: () => handleChange(step), selected: (step === null || step === void 0 ? void 0 : step.step) === (_step === null || _step === void 0 ? void 0 : _step.step) }, { children: [_jsx(ListItemIcon, { children: _jsx(Checkbox, { edge: "start", checked: step.status === SCOnBoardingStepStatusType.COMPLETED, tabIndex: -1, disableRipple: true, inputProps: { 'aria-labelledby': step.step }, size: 'small' }) }), _jsx(ListItemText, { primary: _jsx(FormattedMessage, { id: `ui.onBoardingWidget.${step.step}`, defaultMessage: `ui.onBoardingWidget.${step.step}` }) })] }))) }, step.id))) })), _jsxs(Box, Object.assign({ className: classes.stepContent }, { children: [_jsx(Fade, Object.assign({ in: true, timeout: 2400 }, { children: _jsx(Box, { children: getStepContent() }) })), showCategoriesModal && (_jsx(BaseDialog, Object.assign({ title: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.ai.no.categories", defaultMessage: "ui.onBoardingWidget.ai.no.categories" }), DialogContentProps: { dividers: false }, open: showCategoriesModal, onClose: () => setShowCategoriesModal(false), actions: _jsx(Button, Object.assign({ color: "secondary", onClick: () => setShowCategoriesModal(false) }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.ai.no.categories.cancel", defaultMessage: "ui.onBoardingWidget.ai.no.categories.cancel" }) })) }, { children: _jsx(Button, Object.assign({ color: "primary", onClick: handleCategoriesClick, startIcon: _jsx(Icon, Object.assign({ fontSize: "small" }, { children: "edit" })) }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.ai.no.categories.link", defaultMessage: "ui.onBoardingWidget.ai.no.categories.link" }) })) })))] }))] })) })) })] })) })));
|
|
237
280
|
};
|
|
238
281
|
export default OnBoardingWidget;
|