@selfcommunity/react-ui 0.8.0-alpha.14 → 0.8.0-alpha.16

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.
@@ -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;
@@ -27,6 +27,7 @@ const notistack_1 = require("notistack");
27
27
  const constants_2 = require("../PlatformWidget/constants");
28
28
  const header_1 = tslib_1.__importDefault(require("../../assets/onBoarding/header"));
29
29
  const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"));
30
+ const onBoarding_1 = require("../../utils/onBoarding");
30
31
  const classes = {
31
32
  root: `${constants_1.PREFIX}-root`,
32
33
  content: `${constants_1.PREFIX}-content`,
@@ -53,7 +54,7 @@ const OnBoardingWidget = (inProps) => {
53
54
  props: inProps,
54
55
  name: constants_1.PREFIX
55
56
  });
56
- const { className, GenerateContentsParams = {}, onGeneratedContent = null, onHeightChange } = props, rest = tslib_1.__rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange"]);
57
+ const { className, GenerateContentsParams = {}, onGeneratedContent = null, onHeightChange, onStateChange, forceExpanded = false, initialStep } = props, rest = tslib_1.__rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange", "onStateChange", "forceExpanded", "initialStep"]);
57
58
  // STATE
58
59
  const [loading, setLoading] = (0, react_1.useState)(true);
59
60
  const [initialized, setInitialized] = (0, react_1.useState)(false);
@@ -65,7 +66,7 @@ const OnBoardingWidget = (inProps) => {
65
66
  const allStepsDone = (0, react_1.useMemo)(() => {
66
67
  return steps === null || steps === void 0 ? void 0 : steps.every((step) => step.status === types_1.SCOnBoardingStepStatusType.COMPLETED);
67
68
  }, [steps]);
68
- const [expanded, setExpanded] = (0, react_1.useState)(!allStepsDone);
69
+ const [expanded, setExpanded] = (0, react_1.useState)(!allStepsDone || forceExpanded);
69
70
  const [_step, setStep] = (0, react_1.useState)(nextStep);
70
71
  const currentContentsStep = steps === null || steps === void 0 ? void 0 : steps.find((s) => s.step === types_1.SCOnBoardingStepType.CONTENTS);
71
72
  const prevContentsStep = (0, react_core_1.usePreviousValue)(currentContentsStep);
@@ -86,6 +87,15 @@ const OnBoardingWidget = (inProps) => {
86
87
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
87
88
  const { categories, isLoading } = (0, react_core_1.useSCFetchCategories)();
88
89
  // HANDLERS
90
+ /**
91
+ * Notify changes to Feed if the Widget is contained
92
+ */
93
+ const notifyLayoutChanges = (0, react_1.useMemo)(() => (state) => {
94
+ if (onStateChange && state) {
95
+ onStateChange(state);
96
+ }
97
+ onHeightChange && onHeightChange();
98
+ }, [onStateChange, onHeightChange]);
89
99
  const completeStep = (s) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
90
100
  if (s.status !== types_1.SCOnBoardingStepStatusType.COMPLETED) {
91
101
  yield api_services_1.OnBoardingService.completeAStep(s.id)
@@ -116,7 +126,7 @@ const OnBoardingWidget = (inProps) => {
116
126
  .then((res) => {
117
127
  const contentStep = res.results.find((step) => step.step === types_1.SCOnBoardingStepType.CONTENTS);
118
128
  setIsGenerating(res.results.some((step) => step.status === 'in_progress'));
119
- setSteps(res.results);
129
+ setSteps((0, onBoarding_1.forceStepPosition)(res.results, initialStep));
120
130
  setLoading(false);
121
131
  if (contentStep.status === types_1.SCOnBoardingStepStatusType.IN_PROGRESS && contentStep.results.length !== 0 && onGeneratedContent) {
122
132
  onGeneratedContent(contentStep.results);
@@ -131,8 +141,9 @@ const OnBoardingWidget = (inProps) => {
131
141
  setStep(newStep);
132
142
  };
133
143
  const handleExpand = () => {
134
- setExpanded(!expanded);
135
- onHeightChange && onHeightChange();
144
+ const _expanded = !expanded;
145
+ setExpanded(_expanded);
146
+ notifyLayoutChanges({ forceExpanded: _expanded });
136
147
  };
137
148
  const generateContent = (stepId) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
138
149
  if (!isLoading && !categories.length) {
@@ -178,11 +189,13 @@ const OnBoardingWidget = (inProps) => {
178
189
  if (!initialized && nextStep) {
179
190
  setStep(nextStep);
180
191
  setInitialized(true);
192
+ notifyLayoutChanges({ forceExpanded: expanded });
181
193
  }
182
194
  }, [initialized, nextStep]);
183
195
  (0, react_1.useEffect)(() => {
184
- setExpanded(!allStepsDone);
185
- onHeightChange && onHeightChange();
196
+ const _expanded = !allStepsDone;
197
+ setExpanded(_expanded);
198
+ notifyLayoutChanges({ forceExpanded: _expanded });
186
199
  }, [allStepsDone]);
187
200
  (0, react_1.useEffect)(() => {
188
201
  if (isAdmin) {
@@ -242,6 +255,7 @@ const OnBoardingWidget = (inProps) => {
242
255
  b: (chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks }),
243
256
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
244
257
  // @ts-ignore
258
+ // eslint-disable-next-line prettier/prettier
245
259
  icon: (...chunks) => (0, jsx_runtime_1.jsx)(material_1.Icon, Object.assign({ color: "secondary", fontSize: "medium" }, { children: chunks }))
246
260
  } }) }))) }) })), (0, jsx_runtime_1.jsx)(material_1.AccordionDetails, { children: (0, jsx_runtime_1.jsx)(Widget_1.default, Object.assign({ className: classes.content, elevation: 0 }, { children: loading ? ((0, jsx_runtime_1.jsx)(Skeleton_1.default, {})) : ((0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.List, Object.assign({ className: isMobile ? classes.stepsMobile : classes.steps }, { children: steps === null || steps === void 0 ? void 0 : steps.map((step) => ((0, jsx_runtime_1.jsx)(material_1.ListItem, { children: isMobile ? ((0, jsx_runtime_1.jsx)(material_1.Chip, { size: "small", label: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.onBoardingWidget.${step.step}`, defaultMessage: `ui.onBoardingWidget.${step.step}` }), ' ', step.status === types_1.SCOnBoardingStepStatusType.COMPLETED && ((0, jsx_runtime_1.jsx)(material_1.Icon, Object.assign({ color: (step === null || step === void 0 ? void 0 : step.status) === types_1.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 === types_1.SCOnBoardingStepStatusType.COMPLETED ? 'success' : 'default' })) : ((0, jsx_runtime_1.jsxs)(material_1.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: [(0, jsx_runtime_1.jsx)(material_1.ListItemIcon, { children: (0, jsx_runtime_1.jsx)(material_1.Checkbox, { edge: "start", checked: step.status === types_1.SCOnBoardingStepStatusType.COMPLETED, tabIndex: -1, disableRipple: true, inputProps: { 'aria-labelledby': step.step }, size: 'small' }) }), (0, jsx_runtime_1.jsx)(material_1.ListItemText, { primary: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.onBoardingWidget.${step.step}`, defaultMessage: `ui.onBoardingWidget.${step.step}` }) })] }))) }, step.id))) })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: classes.stepContent }, { children: [(0, jsx_runtime_1.jsx)(material_1.Fade, Object.assign({ in: true, timeout: 2400 }, { children: (0, jsx_runtime_1.jsx)(material_1.Box, { children: getStepContent() }) })), showCategoriesModal && ((0, jsx_runtime_1.jsx)(BaseDialog_1.default, Object.assign({ title: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.onBoardingWidget.ai.no.categories", defaultMessage: "ui.onBoardingWidget.ai.no.categories" }), DialogContentProps: { dividers: false }, open: showCategoriesModal, onClose: () => setShowCategoriesModal(false), actions: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ color: "secondary", onClick: () => setShowCategoriesModal(false) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.onBoardingWidget.ai.no.categories.cancel", defaultMessage: "ui.onBoardingWidget.ai.no.categories.cancel" }) })) }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ color: "primary", href: isStage ? constants_2.CONSOLE_STAGE : constants_2.CONSOLE_PROD, onClick: () => setShowCategoriesModal(false), target: "_blank", startIcon: (0, jsx_runtime_1.jsx)(material_1.Icon, Object.assign({ fontSize: "small" }, { children: "edit" })) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.onBoardingWidget.ai.no.categories.link", defaultMessage: "ui.onBoardingWidget.ai.no.categories.link" }) })) })))] }))] })) })) })] })) })));
247
261
  };
@@ -1,2 +1,3 @@
1
1
  export declare function formatColorLabel(obj: any): any;
2
2
  export declare function formatLogoLabel(obj: any): any;
3
+ export declare function forceStepPosition(steps: any, initialStep: any): any;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatLogoLabel = exports.formatColorLabel = void 0;
3
+ exports.forceStepPosition = exports.formatLogoLabel = exports.formatColorLabel = void 0;
4
4
  function formatColorLabel(obj) {
5
5
  let { name } = obj;
6
6
  const colorIndex = name.toLowerCase().indexOf('color');
@@ -18,3 +18,12 @@ function formatLogoLabel(obj) {
18
18
  .join(' ');
19
19
  }
20
20
  exports.formatLogoLabel = formatLogoLabel;
21
+ function forceStepPosition(steps, initialStep) {
22
+ const index = steps.findIndex((el) => el.step === initialStep);
23
+ if (index !== -1) {
24
+ const [element] = steps.splice(index, 1);
25
+ steps.unshift(element);
26
+ }
27
+ return steps;
28
+ }
29
+ exports.forceStepPosition = forceStepPosition;
@@ -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;
@@ -25,6 +25,7 @@ import { closeSnackbar, useSnackbar } from 'notistack';
25
25
  import { CONSOLE_PROD, CONSOLE_STAGE } from '../PlatformWidget/constants';
26
26
  import HeaderPlaceholder from '../../assets/onBoarding/header';
27
27
  import BaseDialog from '../../shared/BaseDialog';
28
+ import { forceStepPosition } from '../../utils/onBoarding';
28
29
  const classes = {
29
30
  root: `${PREFIX}-root`,
30
31
  content: `${PREFIX}-content`,
@@ -51,7 +52,7 @@ const OnBoardingWidget = (inProps) => {
51
52
  props: inProps,
52
53
  name: PREFIX
53
54
  });
54
- const { className, GenerateContentsParams = {}, onGeneratedContent = null, onHeightChange } = props, rest = __rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange"]);
55
+ const { className, GenerateContentsParams = {}, onGeneratedContent = null, onHeightChange, onStateChange, forceExpanded = false, initialStep } = props, rest = __rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange", "onStateChange", "forceExpanded", "initialStep"]);
55
56
  // STATE
56
57
  const [loading, setLoading] = useState(true);
57
58
  const [initialized, setInitialized] = useState(false);
@@ -63,7 +64,7 @@ const OnBoardingWidget = (inProps) => {
63
64
  const allStepsDone = useMemo(() => {
64
65
  return steps === null || steps === void 0 ? void 0 : steps.every((step) => step.status === SCOnBoardingStepStatusType.COMPLETED);
65
66
  }, [steps]);
66
- const [expanded, setExpanded] = useState(!allStepsDone);
67
+ const [expanded, setExpanded] = useState(!allStepsDone || forceExpanded);
67
68
  const [_step, setStep] = useState(nextStep);
68
69
  const currentContentsStep = steps === null || steps === void 0 ? void 0 : steps.find((s) => s.step === SCOnBoardingStepType.CONTENTS);
69
70
  const prevContentsStep = usePreviousValue(currentContentsStep);
@@ -84,6 +85,15 @@ const OnBoardingWidget = (inProps) => {
84
85
  const isMobile = useMediaQuery(theme.breakpoints.down('md'));
85
86
  const { categories, isLoading } = useSCFetchCategories();
86
87
  // HANDLERS
88
+ /**
89
+ * Notify changes to Feed if the Widget is contained
90
+ */
91
+ const notifyLayoutChanges = useMemo(() => (state) => {
92
+ if (onStateChange && state) {
93
+ onStateChange(state);
94
+ }
95
+ onHeightChange && onHeightChange();
96
+ }, [onStateChange, onHeightChange]);
87
97
  const completeStep = (s) => __awaiter(void 0, void 0, void 0, function* () {
88
98
  if (s.status !== SCOnBoardingStepStatusType.COMPLETED) {
89
99
  yield OnBoardingService.completeAStep(s.id)
@@ -114,7 +124,7 @@ const OnBoardingWidget = (inProps) => {
114
124
  .then((res) => {
115
125
  const contentStep = res.results.find((step) => step.step === SCOnBoardingStepType.CONTENTS);
116
126
  setIsGenerating(res.results.some((step) => step.status === 'in_progress'));
117
- setSteps(res.results);
127
+ setSteps(forceStepPosition(res.results, initialStep));
118
128
  setLoading(false);
119
129
  if (contentStep.status === SCOnBoardingStepStatusType.IN_PROGRESS && contentStep.results.length !== 0 && onGeneratedContent) {
120
130
  onGeneratedContent(contentStep.results);
@@ -129,8 +139,9 @@ const OnBoardingWidget = (inProps) => {
129
139
  setStep(newStep);
130
140
  };
131
141
  const handleExpand = () => {
132
- setExpanded(!expanded);
133
- onHeightChange && onHeightChange();
142
+ const _expanded = !expanded;
143
+ setExpanded(_expanded);
144
+ notifyLayoutChanges({ forceExpanded: _expanded });
134
145
  };
135
146
  const generateContent = (stepId) => __awaiter(void 0, void 0, void 0, function* () {
136
147
  if (!isLoading && !categories.length) {
@@ -176,11 +187,13 @@ const OnBoardingWidget = (inProps) => {
176
187
  if (!initialized && nextStep) {
177
188
  setStep(nextStep);
178
189
  setInitialized(true);
190
+ notifyLayoutChanges({ forceExpanded: expanded });
179
191
  }
180
192
  }, [initialized, nextStep]);
181
193
  useEffect(() => {
182
- setExpanded(!allStepsDone);
183
- onHeightChange && onHeightChange();
194
+ const _expanded = !allStepsDone;
195
+ setExpanded(_expanded);
196
+ notifyLayoutChanges({ forceExpanded: _expanded });
184
197
  }, [allStepsDone]);
185
198
  useEffect(() => {
186
199
  if (isAdmin) {
@@ -240,6 +253,7 @@ const OnBoardingWidget = (inProps) => {
240
253
  b: (chunks) => _jsx("strong", { children: chunks }),
241
254
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
242
255
  // @ts-ignore
256
+ // eslint-disable-next-line prettier/prettier
243
257
  icon: (...chunks) => _jsx(Icon, Object.assign({ color: "secondary", fontSize: "medium" }, { children: chunks }))
244
258
  } }) }))) }) })), _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", href: isStage ? CONSOLE_STAGE : CONSOLE_PROD, onClick: () => setShowCategoriesModal(false), target: "_blank", 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" }) })) })))] }))] })) })) })] })) })));
245
259
  };
@@ -1,2 +1,3 @@
1
1
  export declare function formatColorLabel(obj: any): any;
2
2
  export declare function formatLogoLabel(obj: any): any;
3
+ export declare function forceStepPosition(steps: any, initialStep: any): any;
@@ -13,3 +13,11 @@ export function formatLogoLabel(obj) {
13
13
  .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
14
14
  .join(' ');
15
15
  }
16
+ export function forceStepPosition(steps, initialStep) {
17
+ const index = steps.findIndex((el) => el.step === initialStep);
18
+ if (index !== -1) {
19
+ const [element] = steps.splice(index, 1);
20
+ steps.unshift(element);
21
+ }
22
+ return steps;
23
+ }