@selfcommunity/react-ui 0.7.9-alpha.5 → 0.7.9-alpha.7
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/ChangeGroupCover/ChangeGroupCover.js +24 -1
- package/lib/cjs/components/ChangeGroupPicture/ChangeGroupPicture.js +22 -4
- package/lib/cjs/components/Composer/Composer.js +3 -5
- package/lib/cjs/components/Composer/Content/ContentPost/ContentPost.js +4 -3
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -2
- package/lib/cjs/components/Composer/Layer/AudienceLayer/AudienceLayer.js +18 -6
- package/lib/cjs/components/EditGroupButton/EditGroupButton.js +4 -0
- package/lib/cjs/components/Group/Group.js +2 -2
- package/lib/cjs/components/GroupHeader/Skeleton.d.ts +2 -4
- package/lib/cjs/components/GroupHeader/Skeleton.js +10 -10
- package/lib/cjs/components/GroupInviteButton/GroupInviteButton.js +3 -3
- package/lib/cjs/components/GroupSubscribeButton/GroupSubscribeButton.js +3 -1
- package/lib/cjs/components/Groups/Groups.d.ts +13 -17
- package/lib/cjs/components/Groups/Groups.js +40 -93
- package/lib/esm/components/ChangeGroupCover/ChangeGroupCover.js +24 -1
- package/lib/esm/components/ChangeGroupPicture/ChangeGroupPicture.js +22 -4
- package/lib/esm/components/Composer/Composer.js +3 -5
- package/lib/esm/components/Composer/Content/ContentPost/ContentPost.js +4 -3
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.d.ts +1 -2
- package/lib/esm/components/Composer/Layer/AudienceLayer/AudienceLayer.js +18 -6
- package/lib/esm/components/EditGroupButton/EditGroupButton.js +5 -1
- package/lib/esm/components/Group/Group.js +2 -2
- package/lib/esm/components/GroupHeader/Skeleton.d.ts +2 -4
- package/lib/esm/components/GroupHeader/Skeleton.js +10 -10
- package/lib/esm/components/GroupInviteButton/GroupInviteButton.js +3 -3
- package/lib/esm/components/GroupSubscribeButton/GroupSubscribeButton.js +4 -2
- package/lib/esm/components/Groups/Groups.d.ts +13 -17
- package/lib/esm/components/Groups/Groups.js +45 -98
- package/lib/umd/react-ui.js +1 -1
- package/package.json +4 -4
|
@@ -25,6 +25,10 @@ const messages = (0, react_intl_1.defineMessages)({
|
|
|
25
25
|
errorLoadImage: {
|
|
26
26
|
id: 'ui.changeGroupCover.button.change.alertErrorImage',
|
|
27
27
|
defaultMessage: 'ui.changeGroupCover.button.change.alertErrorImage'
|
|
28
|
+
},
|
|
29
|
+
errorImageSize: {
|
|
30
|
+
id: 'ui.changeGroupCover.alert',
|
|
31
|
+
defaultMessage: 'ui.changeGroupCover.alert'
|
|
28
32
|
}
|
|
29
33
|
});
|
|
30
34
|
/**
|
|
@@ -75,7 +79,26 @@ function ChangeGroupCover(inProps) {
|
|
|
75
79
|
*/
|
|
76
80
|
const handleUpload = (event) => {
|
|
77
81
|
fileInput = event.target.files[0];
|
|
78
|
-
|
|
82
|
+
if (fileInput) {
|
|
83
|
+
const reader = new FileReader();
|
|
84
|
+
reader.onload = (e) => {
|
|
85
|
+
const img = new Image();
|
|
86
|
+
img.onload = () => {
|
|
87
|
+
if (img.width < 1920) {
|
|
88
|
+
setAlert(intl.formatMessage(messages.errorImageSize));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
isCreationMode ? onChange && onChange(fileInput) : handleSave();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
img.src = e.target.result;
|
|
97
|
+
};
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
reader.readAsDataURL(fileInput);
|
|
101
|
+
}
|
|
79
102
|
};
|
|
80
103
|
/**
|
|
81
104
|
* Handles cover saving after upload action
|
|
@@ -16,8 +16,8 @@ const react_intl_1 = require("react-intl");
|
|
|
16
16
|
const lab_1 = require("@mui/lab");
|
|
17
17
|
const messages = (0, react_intl_1.defineMessages)({
|
|
18
18
|
errorLoadImage: {
|
|
19
|
-
id: 'ui.
|
|
20
|
-
defaultMessage: 'ui.
|
|
19
|
+
id: 'ui.changeGroupPicture.alert',
|
|
20
|
+
defaultMessage: 'ui.changeGroupPicture.alert'
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
const classes = {
|
|
@@ -76,9 +76,27 @@ function ChangeGroupPicture(inProps) {
|
|
|
76
76
|
* @param event
|
|
77
77
|
*/
|
|
78
78
|
function handleUpload(event) {
|
|
79
|
-
fileInput = event.target.files[0];
|
|
80
|
-
|
|
79
|
+
const fileInput = event.target.files[0];
|
|
80
|
+
if (fileInput) {
|
|
81
|
+
const reader = new FileReader();
|
|
82
|
+
reader.onload = (e) => {
|
|
83
|
+
const img = new Image();
|
|
84
|
+
img.onload = () => {
|
|
85
|
+
if (img.width < 600 && img.height < 600) {
|
|
86
|
+
setAlert(intl.formatMessage(messages.errorLoadImage));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
isCreationMode ? onChange && onChange(fileInput) : handleSave();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
img.src = e.target.result;
|
|
95
|
+
};
|
|
96
|
+
reader.readAsDataURL(fileInput);
|
|
97
|
+
}
|
|
81
98
|
}
|
|
99
|
+
// ui.changeGroupPicture.alert
|
|
82
100
|
/**
|
|
83
101
|
* Performs save avatar after upload
|
|
84
102
|
*/
|
|
@@ -29,7 +29,6 @@ const Attributes_1 = tslib_1.__importDefault(require("./Attributes"));
|
|
|
29
29
|
const constants_1 = require("./constants");
|
|
30
30
|
const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
|
|
31
31
|
const CloseLayer_1 = tslib_1.__importDefault(require("./Layer/CloseLayer"));
|
|
32
|
-
const AudienceLayer_2 = require("./Layer/AudienceLayer/AudienceLayer");
|
|
33
32
|
const DialogTransition = (0, react_1.forwardRef)(function Transition(props, ref) {
|
|
34
33
|
return react_1.default.createElement(material_1.Fade, Object.assign({ ref: ref }, props));
|
|
35
34
|
});
|
|
@@ -308,7 +307,7 @@ function Composer(inProps) {
|
|
|
308
307
|
}
|
|
309
308
|
}), [handleAddLayer, handleRemoveLayer, handleChangeCategories, categories]);
|
|
310
309
|
const handleChangeAudience = (0, react_1.useCallback)((value) => {
|
|
311
|
-
if (group) {
|
|
310
|
+
if (group || typeof value === 'object') {
|
|
312
311
|
dispatch({ type: 'group', value });
|
|
313
312
|
}
|
|
314
313
|
else {
|
|
@@ -322,8 +321,7 @@ function Composer(inProps) {
|
|
|
322
321
|
ComponentProps: {
|
|
323
322
|
onClose: handleRemoveLayer,
|
|
324
323
|
onSave: handleChangeAudience,
|
|
325
|
-
defaultValue: group ? group : addressing
|
|
326
|
-
defaultType: group ? AudienceLayer_2.AudienceTypes.AUDIENCE_GROUP : addressing ? AudienceLayer_2.AudienceTypes.AUDIENCE_TAG : AudienceLayer_2.AudienceTypes.AUDIENCE_ALL
|
|
324
|
+
defaultValue: group || typeof addressing === 'object' ? group : addressing
|
|
327
325
|
}
|
|
328
326
|
}), [handleAddLayer, handleRemoveLayer, handleChangeAudience, addressing, group]);
|
|
329
327
|
const handleChangeLocation = (0, react_1.useCallback)((value) => {
|
|
@@ -555,7 +553,7 @@ function Composer(inProps) {
|
|
|
555
553
|
}),
|
|
556
554
|
react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting, onClick: handleAddCategoryLayer },
|
|
557
555
|
react_1.default.createElement(Icon_1.default, null, "category")),
|
|
558
|
-
react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting || !features.includes(types_1.SCFeatureName.TAGGING), onClick: handleAddAudienceLayer }, addressing === null || addressing.length === 0 ? react_1.default.createElement(Icon_1.default, null, "public") : react_1.default.createElement(Icon_1.default, null, "label")),
|
|
556
|
+
react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting || !features.includes(types_1.SCFeatureName.TAGGING), onClick: handleAddAudienceLayer }, addressing === null || addressing.length === 0 ? (react_1.default.createElement(Icon_1.default, null, "public")) : typeof addressing === 'object' ? (react_1.default.createElement(Icon_1.default, null, "groups")) : (react_1.default.createElement(Icon_1.default, null, "label"))),
|
|
559
557
|
preferences[react_core_1.SCPreferences.ADDONS_POST_GEOLOCATION_ENABLED].value && (react_1.default.createElement(material_1.IconButton, { disabled: isSubmitting, onClick: handleAddLocationLayer, color: location !== null ? 'primary' : 'default' },
|
|
560
558
|
react_1.default.createElement(Icon_1.default, null, "add_location_alt"))))),
|
|
561
559
|
layer && (react_1.default.createElement(LayerTransitionRoot, { className: classes.layerTransitionRoot, in: true, container: dialogRef.current, direction: "left" },
|
|
@@ -25,7 +25,8 @@ const DEFAULT_POST = {
|
|
|
25
25
|
categories: [],
|
|
26
26
|
medias: [],
|
|
27
27
|
html: '',
|
|
28
|
-
addressing: []
|
|
28
|
+
addressing: [],
|
|
29
|
+
group: null
|
|
29
30
|
};
|
|
30
31
|
exports.default = (props) => {
|
|
31
32
|
// PROPS
|
|
@@ -43,7 +44,7 @@ exports.default = (props) => {
|
|
|
43
44
|
}, [value]);
|
|
44
45
|
// RENDER
|
|
45
46
|
return (react_1.default.createElement(Root, { className: (0, classnames_1.default)(classes.root, className) },
|
|
46
|
-
generalError && react_1.default.createElement(material_1.Typography, { className: classes.generalError },
|
|
47
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: `ui.composer.error.${generalError}`, defaultMessage: `ui.composer.error.${generalError}` })),
|
|
47
|
+
generalError && (react_1.default.createElement(material_1.Typography, { className: classes.generalError },
|
|
48
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: `ui.composer.error.${generalError}`, defaultMessage: `ui.composer.error.${generalError}` }))),
|
|
48
49
|
react_1.default.createElement(Editor_1.default, Object.assign({ ref: editorRef }, EditorProps, { editable: !disabled, className: classes.editor, onChange: handleChangeHtml, defaultValue: value.html }))));
|
|
49
50
|
};
|
|
@@ -10,9 +10,8 @@ export declare enum AudienceTypes {
|
|
|
10
10
|
AUDIENCE_GROUP = "group"
|
|
11
11
|
}
|
|
12
12
|
export interface AudienceLayerProps extends Omit<BoxProps, 'defaultValue'>, ComposerLayerProps {
|
|
13
|
-
defaultType: AudienceTypes;
|
|
14
13
|
defaultValue: SCTagType[] | SCGroupType;
|
|
15
14
|
TextFieldProps?: TextFieldProps;
|
|
16
15
|
}
|
|
17
|
-
declare const AudienceLayer: React.ForwardRefExoticComponent<Pick<AudienceLayerProps, "p" | "slot" | "style" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "zIndex" | "position" | "top" | "right" | "bottom" | "left" | "boxShadow" | "width" | "maxWidth" | "minWidth" | "height" | "maxHeight" | "minHeight" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "marginInline" | "marginInlineStart" | "marginInlineEnd" | "marginBlock" | "marginBlockStart" | "marginBlockEnd" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "paddingInline" | "paddingInlineStart" | "paddingInlineEnd" | "paddingBlock" | "paddingBlockStart" | "paddingBlockEnd" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textAlign" | "textTransform" | "component" | "sx" | "classes" | "onClose" | "TextFieldProps" | "
|
|
16
|
+
declare const AudienceLayer: React.ForwardRefExoticComponent<Pick<AudienceLayerProps, "p" | "slot" | "style" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "zIndex" | "position" | "top" | "right" | "bottom" | "left" | "boxShadow" | "width" | "maxWidth" | "minWidth" | "height" | "maxHeight" | "minHeight" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "marginInline" | "marginInlineStart" | "marginInlineEnd" | "marginBlock" | "marginBlockStart" | "marginBlockEnd" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "paddingInline" | "paddingInlineStart" | "paddingInlineEnd" | "paddingBlock" | "paddingBlockStart" | "paddingBlockEnd" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textAlign" | "textTransform" | "component" | "sx" | "classes" | "onClose" | "TextFieldProps" | "onSave"> & React.RefAttributes<unknown>>;
|
|
18
17
|
export default AudienceLayer;
|
|
@@ -35,10 +35,10 @@ const Root = (0, styles_1.styled)(material_1.Box, {
|
|
|
35
35
|
})(() => ({}));
|
|
36
36
|
const AudienceLayer = react_1.default.forwardRef((props, ref) => {
|
|
37
37
|
// Props
|
|
38
|
-
const { className, onClose, onSave,
|
|
38
|
+
const { className, onClose, onSave, defaultValue = AudienceTypes.AUDIENCE_TAG ? [] : null, TextFieldProps = {
|
|
39
39
|
variant: 'outlined',
|
|
40
40
|
label: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tags.label", defaultMessage: "ui.composer.layer.audience.tags.label" })
|
|
41
|
-
} } = props, rest = tslib_1.__rest(props, ["className", "onClose", "onSave", "
|
|
41
|
+
} } = props, rest = tslib_1.__rest(props, ["className", "onClose", "onSave", "defaultValue", "TextFieldProps"]);
|
|
42
42
|
// STATE
|
|
43
43
|
const [autocompleteOpen, setAutocompleteOpen] = (0, react_1.useState)(false);
|
|
44
44
|
const [audience, setAudience] = (0, react_1.useState)(
|
|
@@ -46,7 +46,7 @@ const AudienceLayer = react_1.default.forwardRef((props, ref) => {
|
|
|
46
46
|
// @ts-ignore
|
|
47
47
|
defaultValue === null || defaultValue.length === 0
|
|
48
48
|
? AudienceTypes.AUDIENCE_ALL
|
|
49
|
-
:
|
|
49
|
+
: typeof defaultValue === 'object'
|
|
50
50
|
? AudienceTypes.AUDIENCE_GROUP
|
|
51
51
|
: AudienceTypes.AUDIENCE_TAG);
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -58,7 +58,7 @@ const AudienceLayer = react_1.default.forwardRef((props, ref) => {
|
|
|
58
58
|
const handleSave = (0, react_1.useCallback)(
|
|
59
59
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
60
60
|
// @ts-ignore
|
|
61
|
-
() => (
|
|
61
|
+
() => (typeof defaultValue === 'object' ? onSave(value) : onSave((value === null || value === void 0 ? void 0 : value.length) && (value === null || value === void 0 ? void 0 : value.length) > 0 ? value : null)), [value, onSave]);
|
|
62
62
|
const handleChange = (0, react_1.useCallback)((event, tags) => setValue(tags), []);
|
|
63
63
|
const handleGroupChange = (0, react_1.useCallback)((group) => setValue(group), []);
|
|
64
64
|
const handleChangeAudience = (0, react_1.useCallback)((event, data) => setAudience(data), []);
|
|
@@ -75,8 +75,20 @@ const AudienceLayer = react_1.default.forwardRef((props, ref) => {
|
|
|
75
75
|
react_1.default.createElement(DialogContent_1.default, { className: classes.content },
|
|
76
76
|
react_1.default.createElement(material_1.Tabs, { value: audience, onChange: handleChangeAudience, "aria-label": "audience type" },
|
|
77
77
|
react_1.default.createElement(material_1.Tab, { value: AudienceTypes.AUDIENCE_ALL, icon: react_1.default.createElement(Icon_1.default, null, "public"), label: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.all", defaultMessage: "ui.composer.layer.audience.all" }) }),
|
|
78
|
-
react_1.default.createElement(material_1.Tab
|
|
79
|
-
|
|
78
|
+
react_1.default.createElement(material_1.Tab
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
, {
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
disabled: defaultValue && defaultValue.length !== 0, value: AudienceTypes.AUDIENCE_GROUP, icon: react_1.default.createElement(Icon_1.default, null, "groups"), label: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.group", defaultMessage: "ui.composer.layer.audience.group" }) }),
|
|
85
|
+
react_1.default.createElement(material_1.Tab
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
, {
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
disabled: typeof defaultValue === 'object', value: AudienceTypes.AUDIENCE_TAG, icon: react_1.default.createElement(Icon_1.default, null, "label"), label: react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.tag", defaultMessage: "ui.composer.layer.audience.tag" }) })),
|
|
80
92
|
react_1.default.createElement(material_1.Typography, { className: classes.message },
|
|
81
93
|
audience === AudienceTypes.AUDIENCE_ALL && (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.all.message", defaultMessage: "ui.composer.audience.layer.all.message" })),
|
|
82
94
|
audience === AudienceTypes.AUDIENCE_GROUP && (react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.composer.layer.audience.group.message", defaultMessage: "ui.composer.audience.layer.group.message" })),
|
|
@@ -44,10 +44,14 @@ function EditGroupButton(inProps) {
|
|
|
44
44
|
});
|
|
45
45
|
const { className, groupId, group, onEditSuccess } = props, rest = tslib_1.__rest(props, ["className", "groupId", "group", "onEditSuccess"]);
|
|
46
46
|
const { scGroup, setSCGroup } = (0, react_core_1.useSCFetchGroup)({ id: groupId, group });
|
|
47
|
+
const scUserContext = (0, react_core_1.useSCUser)();
|
|
47
48
|
const handleSuccess = (data) => {
|
|
48
49
|
setSCGroup(data);
|
|
49
50
|
onEditSuccess && onEditSuccess(data);
|
|
50
51
|
};
|
|
52
|
+
if (!scUserContext.user) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
51
55
|
/**
|
|
52
56
|
* Renders root object
|
|
53
57
|
*/
|
|
@@ -63,7 +63,7 @@ function Group(inProps) {
|
|
|
63
63
|
props: inProps,
|
|
64
64
|
name: constants_1.PREFIX
|
|
65
65
|
});
|
|
66
|
-
const { groupId = null, group = null, className = null, elevation, hideActions = false, groupSubscribeButtonProps = {},
|
|
66
|
+
const { groupId = null, group = null, className = null, elevation, hideActions = false, groupSubscribeButtonProps = {}, visible = true } = props, rest = tslib_1.__rest(props, ["groupId", "group", "className", "elevation", "hideActions", "groupSubscribeButtonProps", "visible"]);
|
|
67
67
|
// STATE
|
|
68
68
|
const { scGroup } = (0, react_core_1.useSCFetchGroup)({ id: groupId, group });
|
|
69
69
|
// CONTEXT
|
|
@@ -90,7 +90,7 @@ function Group(inProps) {
|
|
|
90
90
|
* Renders root object
|
|
91
91
|
*/
|
|
92
92
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
93
|
-
react_1.default.createElement(Root, Object.assign({ elevation: elevation }, rest, { className: (0, classnames_1.default)(classes.root, className), ButtonBaseProps:
|
|
93
|
+
react_1.default.createElement(Root, Object.assign({ elevation: elevation }, rest, { className: (0, classnames_1.default)(classes.root, className), ButtonBaseProps: { component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.GROUP_ROUTE_NAME, scGroup) }, image: react_1.default.createElement(material_1.Avatar, { alt: scGroup.name, src: scGroup.image_medium, className: classes.avatar }), primary: scGroup.name, secondary: `${intl.formatMessage(messages.groupMembers, { total: scGroup.subscribers_counter })}`, actions: hideActions ? null : renderAuthenticatedActions() })),
|
|
94
94
|
openAlert && react_1.default.createElement(UserDeletedSnackBar_1.default, { open: openAlert, handleClose: () => setOpenAlert(false) })));
|
|
95
95
|
}
|
|
96
96
|
exports.default = Group;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* > API documentation for the Community-JS Group
|
|
2
|
+
* > API documentation for the Community-JS Group Header Skeleton component. Learn about the available props and the CSS API.
|
|
3
3
|
|
|
4
4
|
#### Import
|
|
5
5
|
|
|
@@ -18,9 +18,7 @@
|
|
|
18
18
|
|root|.SCGroupHeader-skeleton-root|Styles applied to the root element.|
|
|
19
19
|
|avatar|.SCGroupHeader-avatar|Styles applied to the avatar element.|
|
|
20
20
|
|cover|.SCGroupHeader-cover|Styles applied to the cover element.|
|
|
21
|
-
|
|
|
22
|
-
|section|.SCGroupHeader-section|Styles applied to the info section.|
|
|
23
|
-
|username|.SCGroupHeader-username|Styles applied to the username element.|
|
|
21
|
+
|info|.SCGroupHeader-info|Styles applied to the info info.|
|
|
24
22
|
*
|
|
25
23
|
*/
|
|
26
24
|
declare function GroupHeaderSkeleton(): JSX.Element;
|
|
@@ -10,16 +10,14 @@ const classes = {
|
|
|
10
10
|
root: `${constants_1.PREFIX}-skeleton-root`,
|
|
11
11
|
cover: `${constants_1.PREFIX}-cover`,
|
|
12
12
|
avatar: `${constants_1.PREFIX}-avatar`,
|
|
13
|
-
|
|
14
|
-
section: `${constants_1.PREFIX}-section`,
|
|
15
|
-
username: `${constants_1.PREFIX}-username`
|
|
13
|
+
info: `${constants_1.PREFIX}-info`
|
|
16
14
|
};
|
|
17
15
|
const Root = (0, styles_1.styled)(material_1.Box, {
|
|
18
16
|
name: constants_1.PREFIX,
|
|
19
17
|
slot: 'SkeletonRoot'
|
|
20
18
|
})(() => ({}));
|
|
21
19
|
/**
|
|
22
|
-
* > API documentation for the Community-JS Group
|
|
20
|
+
* > API documentation for the Community-JS Group Header Skeleton component. Learn about the available props and the CSS API.
|
|
23
21
|
|
|
24
22
|
#### Import
|
|
25
23
|
|
|
@@ -38,9 +36,7 @@ const Root = (0, styles_1.styled)(material_1.Box, {
|
|
|
38
36
|
|root|.SCGroupHeader-skeleton-root|Styles applied to the root element.|
|
|
39
37
|
|avatar|.SCGroupHeader-avatar|Styles applied to the avatar element.|
|
|
40
38
|
|cover|.SCGroupHeader-cover|Styles applied to the cover element.|
|
|
41
|
-
|
|
|
42
|
-
|section|.SCGroupHeader-section|Styles applied to the info section.|
|
|
43
|
-
|username|.SCGroupHeader-username|Styles applied to the username element.|
|
|
39
|
+
|info|.SCGroupHeader-info|Styles applied to the info info.|
|
|
44
40
|
*
|
|
45
41
|
*/
|
|
46
42
|
function GroupHeaderSkeleton() {
|
|
@@ -49,8 +45,12 @@ function GroupHeaderSkeleton() {
|
|
|
49
45
|
react_1.default.createElement(Skeleton_1.default, { className: classes.cover, animation: "wave", variant: "rectangular" }),
|
|
50
46
|
react_1.default.createElement(material_1.Box, { className: classes.avatar },
|
|
51
47
|
react_1.default.createElement(Skeleton_1.default, { animation: "wave", variant: "circular", width: theme.selfcommunity.group.avatar.sizeLarge, height: theme.selfcommunity.group.avatar.sizeLarge })),
|
|
52
|
-
react_1.default.createElement(material_1.Box, { className: classes.
|
|
53
|
-
react_1.default.createElement(material_1.Typography, { variant: "h5"
|
|
54
|
-
react_1.default.createElement(Skeleton_1.default, { animation: "wave", sx: { height: 30, width:
|
|
48
|
+
react_1.default.createElement(material_1.Box, { className: classes.info },
|
|
49
|
+
react_1.default.createElement(material_1.Typography, { variant: "h5" },
|
|
50
|
+
react_1.default.createElement(Skeleton_1.default, { animation: "wave", sx: { height: 30, width: 200 } })),
|
|
51
|
+
react_1.default.createElement(material_1.Typography, null,
|
|
52
|
+
react_1.default.createElement(Skeleton_1.default, { animation: "wave", sx: { height: 20, width: 150 } })),
|
|
53
|
+
react_1.default.createElement(material_1.Typography, null,
|
|
54
|
+
react_1.default.createElement(Skeleton_1.default, { animation: "wave", sx: { height: 20, width: 100 } })))));
|
|
55
55
|
}
|
|
56
56
|
exports.default = GroupHeaderSkeleton;
|
|
@@ -226,9 +226,9 @@ function GroupInviteButton(inProps) {
|
|
|
226
226
|
setList((prev) => [...prev, option]);
|
|
227
227
|
};
|
|
228
228
|
/**
|
|
229
|
-
* If
|
|
229
|
+
* If in group edit mode and logged-in user is not also the group manager, the component is hidden.
|
|
230
230
|
// */
|
|
231
|
-
if (!canEdit) {
|
|
231
|
+
if (group && !canEdit) {
|
|
232
232
|
return null;
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
@@ -242,7 +242,7 @@ function GroupInviteButton(inProps) {
|
|
|
242
242
|
react_1.default.createElement(material_1.Icon, { fontSize: "medium" }, "arrow_back")),
|
|
243
243
|
react_1.default.createElement(material_1.Typography, { className: classes.dialogTitle },
|
|
244
244
|
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupInviteButton.dialog.title", defaultMessage: "ui.groupInviteButton.dialog.title" })),
|
|
245
|
-
react_1.default.createElement(lab_1.LoadingButton, { size: "small", color: "secondary", variant: "contained", onClick: handleSendInvitations, loading: isSending },
|
|
245
|
+
react_1.default.createElement(lab_1.LoadingButton, { size: "small", color: "secondary", variant: "contained", onClick: handleSendInvitations, loading: isSending, disabled: !invited.length },
|
|
246
246
|
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupInviteButton.dialog.button.end", defaultMessage: "ui.groupInviteButton.dialog.button.end" }))) },
|
|
247
247
|
react_1.default.createElement(material_1.Box, { className: classes.dialogContent },
|
|
248
248
|
react_1.default.createElement(Autocomplete_1.default, { className: classes.autocomplete, loading: loading, size: "small", multiple: true, freeSolo: true, disableClearable: true, options: suggested, onChange: handleChange, onInputChange: handleInputChange, inputValue: value, value: invited, getOptionLabel: (option) => (option ? option.username : '...'), isOptionEqualToValue: (option, value) => (option ? value.id === option.id : false), renderTags: () => null, renderOption: (props, option) => (react_1.default.createElement(material_1.Box, Object.assign({ component: "li" }, props),
|
|
@@ -43,6 +43,7 @@ const Root = (0, styles_1.styled)(lab_1.LoadingButton, {
|
|
|
43
43
|
* @param inProps
|
|
44
44
|
*/
|
|
45
45
|
function GroupSubscribeButton(inProps) {
|
|
46
|
+
var _a;
|
|
46
47
|
// PROPS
|
|
47
48
|
const props = (0, system_1.useThemeProps)({
|
|
48
49
|
props: inProps,
|
|
@@ -62,6 +63,7 @@ function GroupSubscribeButton(inProps) {
|
|
|
62
63
|
group,
|
|
63
64
|
cacheStrategy: authUserId ? utils_1.CacheStrategies.CACHE_FIRST : utils_1.CacheStrategies.STALE_WHILE_REVALIDATE
|
|
64
65
|
});
|
|
66
|
+
const canEdit = (0, react_1.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]);
|
|
65
67
|
(0, react_1.useEffect)(() => {
|
|
66
68
|
/**
|
|
67
69
|
* Call scGroupsManager.subscriptionStatus inside an effect
|
|
@@ -119,7 +121,7 @@ function GroupSubscribeButton(inProps) {
|
|
|
119
121
|
}
|
|
120
122
|
return _status;
|
|
121
123
|
};
|
|
122
|
-
if (!scGroup || (scGroup && !scGroup.subscription_status)) {
|
|
124
|
+
if (!scGroup || (scGroup && !scGroup.subscription_status) || canEdit) {
|
|
123
125
|
return null;
|
|
124
126
|
}
|
|
125
127
|
return (react_1.default.createElement(Root, Object.assign({ size: "small", variant: "outlined", onClick: handleSubscribeAction, loading: scUserContext.user ? scGroupsManager.isLoading(scGroup) : null, className: (0, classnames_1.default)(classes.root, className) }, rest), getStatus()));
|
|
@@ -1,31 +1,27 @@
|
|
|
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
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
endpoint: EndpointType;
|
|
9
|
-
/**
|
|
10
|
-
* Hides this component
|
|
11
|
-
* @default false
|
|
6
|
+
* Overrides or extends the styles applied to the component.
|
|
7
|
+
* @default null
|
|
12
8
|
*/
|
|
13
|
-
|
|
9
|
+
className?: string;
|
|
14
10
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @default false
|
|
11
|
+
* Endpoint to call
|
|
17
12
|
*/
|
|
18
|
-
|
|
13
|
+
endpoint: EndpointType;
|
|
19
14
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @default
|
|
15
|
+
* Props to spread to single group object
|
|
16
|
+
* @default {variant: 'outlined', ButtonBaseProps: {disableRipple: 'true'}}
|
|
22
17
|
*/
|
|
23
|
-
|
|
18
|
+
GroupComponentProps?: GroupProps;
|
|
24
19
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
20
|
+
* Prefetch groups. Useful for SSR.
|
|
21
|
+
* Use this to init the component with groups
|
|
22
|
+
* @default null
|
|
27
23
|
*/
|
|
28
|
-
|
|
24
|
+
prefetchedGroups?: SCGroupType[];
|
|
29
25
|
/**
|
|
30
26
|
* Other props
|
|
31
27
|
*/
|
|
@@ -7,7 +7,6 @@ const material_1 = require("@mui/material");
|
|
|
7
7
|
const api_services_1 = require("@selfcommunity/api-services");
|
|
8
8
|
const utils_1 = require("@selfcommunity/utils");
|
|
9
9
|
const react_core_1 = require("@selfcommunity/react-core");
|
|
10
|
-
const widget_1 = require("../../utils/widget");
|
|
11
10
|
const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
|
|
12
11
|
const react_intl_1 = require("react-intl");
|
|
13
12
|
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
@@ -65,117 +64,65 @@ function Groups(inProps) {
|
|
|
65
64
|
props: inProps,
|
|
66
65
|
name: constants_1.PREFIX
|
|
67
66
|
});
|
|
68
|
-
const { endpoint,
|
|
67
|
+
const { endpoint, className, GroupComponentProps = { variant: 'outlined', ButtonBaseProps: { disableRipple: true, component: material_1.Box } }, prefetchedGroups = [] } = props, rest = tslib_1.__rest(props, ["endpoint", "className", "GroupComponentProps", "prefetchedGroups"]);
|
|
69
68
|
// STATE
|
|
70
|
-
const [
|
|
71
|
-
|
|
72
|
-
next: null,
|
|
73
|
-
cacheKey: react_core_1.SCCache.getWidgetStateCacheKey(react_core_1.SCCache.GROUPS_LIST_TOOLS_STATE_CACHE_PREFIX_KEY),
|
|
74
|
-
cacheStrategy,
|
|
75
|
-
visibleItems: limit
|
|
76
|
-
}, widget_1.stateWidgetInitializer);
|
|
69
|
+
const [groups, setGroups] = (0, react_1.useState)([]);
|
|
70
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
77
71
|
// CONTEXT
|
|
78
72
|
const scUserContext = (0, react_core_1.useSCUser)();
|
|
79
73
|
const scPreferencesContext = (0, react_core_1.useSCPreferences)();
|
|
80
74
|
// MEMO
|
|
81
75
|
const contentAvailability = (0, react_1.useMemo)(() => react_core_1.SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY in scPreferencesContext.preferences &&
|
|
82
76
|
scPreferencesContext.preferences[react_core_1.SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value, [scPreferencesContext.preferences]);
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
//
|
|
77
|
+
// CONST
|
|
78
|
+
const authUserId = scUserContext.user ? scUserContext.user.id : null;
|
|
79
|
+
// REFS
|
|
80
|
+
const isMountedRef = (0, react_core_1.useIsComponentMountedRef)();
|
|
86
81
|
/**
|
|
87
|
-
*
|
|
88
|
-
* Fetch data only if the component is not initialized, and it is not loading data
|
|
82
|
+
* Fetches groups list
|
|
89
83
|
*/
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.then((payload) => {
|
|
99
|
-
dispatch({ type: widget_1.actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: Object.assign(Object.assign({}, payload.data), { initialized: true }) });
|
|
100
|
-
})
|
|
101
|
-
.catch((error) => {
|
|
102
|
-
dispatch({ type: widget_1.actionWidgetTypes.LOAD_NEXT_FAILURE, payload: { errorLoadNext: error } });
|
|
103
|
-
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}, [state.isLoadingNext, state.initialized, endpoint, limit, dispatch]);
|
|
107
|
-
// EFFECTS
|
|
108
|
-
(0, react_1.useEffect)(() => {
|
|
109
|
-
var _a;
|
|
110
|
-
let _t;
|
|
111
|
-
if ((contentAvailability || (!contentAvailability && ((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id))) && scUserContext.user !== undefined) {
|
|
112
|
-
_t = setTimeout(_initComponent);
|
|
113
|
-
return () => {
|
|
114
|
-
_t && clearTimeout(_t);
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}, [scUserContext.user, contentAvailability]);
|
|
118
|
-
(0, react_1.useEffect)(() => {
|
|
119
|
-
if (state.next && state.results.length === limit && state.initialized) {
|
|
120
|
-
dispatch({ type: widget_1.actionWidgetTypes.LOADING_NEXT });
|
|
121
|
-
api_services_1.http
|
|
122
|
-
.request({
|
|
123
|
-
url: endpoint.url({ offset: limit, limit: 10 }),
|
|
124
|
-
method: endpoint.method
|
|
125
|
-
})
|
|
126
|
-
.then((payload) => {
|
|
127
|
-
dispatch({ type: widget_1.actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: payload.data });
|
|
128
|
-
})
|
|
129
|
-
.catch((error) => {
|
|
130
|
-
dispatch({ type: widget_1.actionWidgetTypes.LOAD_NEXT_FAILURE, payload: { errorLoadNext: error } });
|
|
131
|
-
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}, [state.next, state.results.length, state.initialized, limit]);
|
|
84
|
+
const fetchGroups = (next = endpoint.url({})) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const response = yield api_services_1.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
|
+
});
|
|
135
92
|
/**
|
|
136
|
-
*
|
|
93
|
+
* On mount, fetches groups list
|
|
137
94
|
*/
|
|
138
95
|
(0, react_1.useEffect)(() => {
|
|
139
|
-
|
|
140
|
-
}, [state.results]);
|
|
141
|
-
(0, react_1.useEffect)(() => {
|
|
142
|
-
if (!endpoint || (!contentAvailability && !scUserContext.user)) {
|
|
96
|
+
if (!contentAvailability && !authUserId) {
|
|
143
97
|
return;
|
|
144
98
|
}
|
|
145
|
-
else if (
|
|
146
|
-
|
|
99
|
+
else if (prefetchedGroups.length) {
|
|
100
|
+
setGroups(prefetchedGroups);
|
|
101
|
+
setLoading(false);
|
|
147
102
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
103
|
+
else {
|
|
104
|
+
fetchGroups()
|
|
105
|
+
.then((data) => {
|
|
106
|
+
if (isMountedRef.current) {
|
|
107
|
+
setGroups(data);
|
|
108
|
+
setLoading(false);
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
.catch((error) => {
|
|
112
|
+
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error);
|
|
113
|
+
});
|
|
152
114
|
}
|
|
153
|
-
}, []);
|
|
154
|
-
// HANDLERS
|
|
155
|
-
const handleNext = (0, react_1.useMemo)(() => () => {
|
|
156
|
-
dispatch({ type: widget_1.actionWidgetTypes.LOADING_NEXT });
|
|
157
|
-
api_services_1.http
|
|
158
|
-
.request({
|
|
159
|
-
url: state.next,
|
|
160
|
-
method: endpoint.method
|
|
161
|
-
})
|
|
162
|
-
.then((res) => {
|
|
163
|
-
dispatch({ type: widget_1.actionWidgetTypes.LOAD_NEXT_SUCCESS, payload: res.data });
|
|
164
|
-
});
|
|
165
|
-
}, [dispatch, state.next, state.isLoadingNext, state.initialized, endpoint.method]);
|
|
115
|
+
}, [contentAvailability, authUserId, prefetchedGroups.length]);
|
|
166
116
|
// RENDER
|
|
167
|
-
if (
|
|
117
|
+
if (!contentAvailability && !scUserContext.user) {
|
|
168
118
|
return react_1.default.createElement(HiddenPlaceholder_1.default, null);
|
|
169
119
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
react_1.default.createElement(
|
|
176
|
-
react_1.default.createElement(Group_1.default, Object.assign({ group: group, groupId: group.id }, GroupProps)))))),
|
|
177
|
-
state.count > state.visibleItems && (react_1.default.createElement(material_1.Button, { className: classes.showMore, onClick: handleNext },
|
|
178
|
-
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groupRequestsWidget.button.showMore", defaultMessage: "ui.groupRequestsWidget.button.showMore" })))))));
|
|
120
|
+
const content = (react_1.default.createElement(react_1.default.Fragment, null, loading ? (react_1.default.createElement(Skeleton_1.default, null)) : (react_1.default.createElement(material_1.Grid, { container: true, spacing: { xs: 3 }, className: classes.groups }, !groups.length ? (react_1.default.createElement(material_1.Box, { className: classes.noResults },
|
|
121
|
+
react_1.default.createElement(material_1.Typography, { variant: "h4" },
|
|
122
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groups.noGroups.title", defaultMessage: "ui.groups.noGroups.title" })),
|
|
123
|
+
react_1.default.createElement(material_1.Typography, { variant: "body1" },
|
|
124
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "ui.groups.noGroups.subtitle", defaultMessage: "ui.groups.noGroups.subtitle" })))) : (react_1.default.createElement(react_1.default.Fragment, null, groups.map((group) => (react_1.default.createElement(material_1.Grid, { item: true, xs: 12, sm: 8, md: 6, key: group.id, className: classes.item },
|
|
125
|
+
react_1.default.createElement(Group_1.default, Object.assign({ group: group, groupId: group.id }, GroupComponentProps)))))))))));
|
|
179
126
|
return (react_1.default.createElement(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest), content));
|
|
180
127
|
}
|
|
181
128
|
exports.default = Groups;
|