@selfcommunity/react-ui 0.8.0-alpha.15 → 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
  /**
@@ -23,6 +23,10 @@ export interface OnBoardingWidgetProps extends VirtualScrollerItemProps {
23
23
  * @default false
24
24
  */
25
25
  forceExpanded?: boolean;
26
+ /**
27
+ * The initial step to display
28
+ */
29
+ initialStep?: SCOnBoardingStepType;
26
30
  }
27
31
  declare const OnBoardingWidget: (inProps: OnBoardingWidgetProps) => JSX.Element;
28
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, onStateChange, forceExpanded = false } = props, rest = tslib_1.__rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange", "onStateChange", "forceExpanded"]);
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);
@@ -125,7 +126,7 @@ const OnBoardingWidget = (inProps) => {
125
126
  .then((res) => {
126
127
  const contentStep = res.results.find((step) => step.step === types_1.SCOnBoardingStepType.CONTENTS);
127
128
  setIsGenerating(res.results.some((step) => step.status === 'in_progress'));
128
- setSteps(res.results);
129
+ setSteps((0, onBoarding_1.forceStepPosition)(res.results, initialStep));
129
130
  setLoading(false);
130
131
  if (contentStep.status === types_1.SCOnBoardingStepStatusType.IN_PROGRESS && contentStep.results.length !== 0 && onGeneratedContent) {
131
132
  onGeneratedContent(contentStep.results);
@@ -254,7 +255,8 @@ const OnBoardingWidget = (inProps) => {
254
255
  b: (chunks) => (0, jsx_runtime_1.jsx)("strong", { children: chunks }),
255
256
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
256
257
  // @ts-ignore
257
- icon: (...chunks) => ((0, jsx_runtime_1.jsx)(material_1.Icon, Object.assign({ color: "secondary", fontSize: "medium" }, { children: chunks })))
258
+ // eslint-disable-next-line prettier/prettier
259
+ icon: (...chunks) => (0, jsx_runtime_1.jsx)(material_1.Icon, Object.assign({ color: "secondary", fontSize: "medium" }, { children: chunks }))
258
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" }) })) })))] }))] })) })) })] })) })));
259
261
  };
260
262
  exports.default = OnBoardingWidget;
@@ -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
  /**
@@ -23,6 +23,10 @@ export interface OnBoardingWidgetProps extends VirtualScrollerItemProps {
23
23
  * @default false
24
24
  */
25
25
  forceExpanded?: boolean;
26
+ /**
27
+ * The initial step to display
28
+ */
29
+ initialStep?: SCOnBoardingStepType;
26
30
  }
27
31
  declare const OnBoardingWidget: (inProps: OnBoardingWidgetProps) => JSX.Element;
28
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, onStateChange, forceExpanded = false } = props, rest = __rest(props, ["className", "GenerateContentsParams", "onGeneratedContent", "onHeightChange", "onStateChange", "forceExpanded"]);
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);
@@ -123,7 +124,7 @@ const OnBoardingWidget = (inProps) => {
123
124
  .then((res) => {
124
125
  const contentStep = res.results.find((step) => step.step === SCOnBoardingStepType.CONTENTS);
125
126
  setIsGenerating(res.results.some((step) => step.status === 'in_progress'));
126
- setSteps(res.results);
127
+ setSteps(forceStepPosition(res.results, initialStep));
127
128
  setLoading(false);
128
129
  if (contentStep.status === SCOnBoardingStepStatusType.IN_PROGRESS && contentStep.results.length !== 0 && onGeneratedContent) {
129
130
  onGeneratedContent(contentStep.results);
@@ -252,7 +253,8 @@ const OnBoardingWidget = (inProps) => {
252
253
  b: (chunks) => _jsx("strong", { children: chunks }),
253
254
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
254
255
  // @ts-ignore
255
- icon: (...chunks) => (_jsx(Icon, Object.assign({ color: "secondary", fontSize: "medium" }, { children: chunks })))
256
+ // eslint-disable-next-line prettier/prettier
257
+ icon: (...chunks) => _jsx(Icon, Object.assign({ color: "secondary", fontSize: "medium" }, { children: chunks }))
256
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" }) })) })))] }))] })) })) })] })) })));
257
259
  };
258
260
  export default OnBoardingWidget;
@@ -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
+ }