UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

73 lines (72 loc) 4.96 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { styled } from '@mui/material/styles'; import { Alert, Button, Icon, Typography } from '@mui/material'; import Box from '@mui/material/Box'; import { useThemeProps } from '@mui/system'; import classNames from 'classnames'; import { useEffect, useMemo, useState } from 'react'; import { PREFIX } from '../../constants'; import { FormattedMessage } from 'react-intl'; import { SCOnBoardingStepStatusType } from '@selfcommunity/types'; import ProgressBar from '../../../../shared/ProgressBar'; import { Player } from '@lottiefiles/react-lottie-player'; import animatedProgress from '../../../../assets/onBoarding/progress/content_progress.json'; const classes = { root: `${PREFIX}-content-root`, title: `${PREFIX}-content-title`, summary: `${PREFIX}-content-summary`, action: `${PREFIX}-content-action`, progress: `${PREFIX}-content-progress`, animationProgress: `${PREFIX}-content-animation-progress` }; const Root = styled(Box, { name: PREFIX, slot: 'ContentRoot' })(() => ({})); export default function Content(inProps) { // PROPS const props = useThemeProps({ props: inProps, name: PREFIX }); const { className, step, handleContentCreation } = props; // STATE const [hover, setHover] = useState(false); const [progress, setProgress] = useState(step.completion_percentage); useEffect(() => { if (step.status === SCOnBoardingStepStatusType.IN_PROGRESS) { const intervalId = setInterval(() => { setProgress((prev) => { if (prev < step.completion_percentage) { return prev + 1; } else { clearInterval(intervalId); return prev; } }); }, 1000); return () => clearInterval(intervalId); } }, [step.status, step.completion_percentage]); const getLoadingMessage = useMemo(() => { let message; if (progress <= 10) { message = _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.contents.loading.a", defaultMessage: "ui.onBoardingWidget.step.contents.loading.a" }); } else if (progress <= 20) { message = _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.contents.loading.b", defaultMessage: "ui.onBoardingWidget.step.contents.loading.b" }); } else if (progress <= 40) { message = _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.contents.loading.c", defaultMessage: "ui.onBoardingWidget.step.contents.loading.c" }); } else if (progress <= 60) { message = _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.contents.loading.d", defaultMessage: "ui.onBoardingWidget.step.contents.loading.d" }); } else { message = _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.contents.loading.e", defaultMessage: "ui.onBoardingWidget.step.contents.loading.e" }); } return message; }, [progress]); return (_jsxs(Root, Object.assign({ className: classNames(classes.root, className) }, { children: [_jsx(Typography, Object.assign({ variant: "h4", className: classes.title }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.contents", defaultMessage: "ui.onBoardingWidget.contents" }) })), _jsx(Typography, Object.assign({ className: classes.summary }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.content.summary", defaultMessage: "ui.onBoardingWidget.step.content.summary" }) })), _jsx(Box, Object.assign({ component: "span", className: classes.action }, { children: (step === null || step === void 0 ? void 0 : step.status) === SCOnBoardingStepStatusType.COMPLETED ? (_jsx(Alert, Object.assign({ severity: "success" }, { children: _jsx(FormattedMessage, { id: "ui.onBoardingWidget.step.contents.success", defaultMessage: "ui.onBoardingWidget.step.contents.success" }) }))) : (step === null || step === void 0 ? void 0 : step.status) === SCOnBoardingStepStatusType.IN_PROGRESS ? (_jsxs(Box, Object.assign({ className: classes.progress }, { children: [_jsx(Player, { autoplay: true, loop: true, src: animatedProgress, className: classes.animationProgress, controls: false }), _jsx(ProgressBar, { value: progress, hideBar: true, loadingMessage: _jsx(Typography, Object.assign({ variant: "h4" }, { children: getLoadingMessage })) })] }))) : (_jsx(Button, Object.assign({ size: "small", variant: "contained", color: "secondary", onClick: handleContentCreation, endIcon: _jsx(Icon, { children: hover ? 'ai_stars' : 'magic_wand' }), onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false) }, { children: _jsx(FormattedMessage, { defaultMessage: "ui.onBoardingWidget.step.content.button", id: "ui.onBoardingWidget.step.content.button" }) }))) }))] }))); }