|
| 1 | +import { |
| 2 | + Button, |
| 3 | + FlexBox, |
| 4 | + ObjectStatus, |
| 5 | + Popover, |
| 6 | + ShellBarItem, |
| 7 | + Text, |
| 8 | + Title, |
| 9 | +} from '@ui5/webcomponents-react'; |
| 10 | +import { useFeature } from 'hooks/useFeature'; |
| 11 | +import { useState, useEffect } from 'react'; |
| 12 | +import { createPortal } from 'react-dom'; |
| 13 | +import { useTranslation } from 'react-i18next'; |
| 14 | +import { configFeaturesNames } from 'state/types'; |
| 15 | +import './FeedbackPopover.scss'; |
| 16 | + |
| 17 | +const FEEDBACK_VIEWED_STORAGE_KEY = 'feedback-new-indicators-viewed'; |
| 18 | + |
| 19 | +export default function FeedbackPopover() { |
| 20 | + const { isEnabled: isFeedbackEnabled, link: kymaFeedbackLink } = useFeature( |
| 21 | + configFeaturesNames.FEEDBACK, |
| 22 | + ); |
| 23 | + const { |
| 24 | + isEnabled: isKymaCompanionEnabled, |
| 25 | + config: { feedbackLink: companionFeedbackLink } = {}, |
| 26 | + } = useFeature(configFeaturesNames.KYMA_COMPANION); |
| 27 | + |
| 28 | + const { t } = useTranslation(); |
| 29 | + const [feedbackOpen, setFeedbackOpen] = useState(false); |
| 30 | + const [showNewIndicators, setShowNewIndicators] = useState(false); |
| 31 | + |
| 32 | + useEffect(() => { |
| 33 | + const hasViewed = localStorage.getItem(FEEDBACK_VIEWED_STORAGE_KEY); |
| 34 | + if (hasViewed !== 'true') { |
| 35 | + setShowNewIndicators(true); |
| 36 | + } |
| 37 | + }, []); |
| 38 | + |
| 39 | + const handleNewFeedbackViewed = () => { |
| 40 | + if (showNewIndicators) { |
| 41 | + localStorage.setItem(FEEDBACK_VIEWED_STORAGE_KEY, 'true'); |
| 42 | + setShowNewIndicators(false); |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + if (!isFeedbackEnabled) { |
| 47 | + return null; |
| 48 | + } |
| 49 | + |
| 50 | + return ( |
| 51 | + <> |
| 52 | + <ShellBarItem |
| 53 | + id="feedbackOpener" |
| 54 | + onClick={() => setFeedbackOpen(true)} |
| 55 | + icon="feedback" |
| 56 | + text={t('feedback.feedback')} |
| 57 | + title={t('feedback.give-feedback')} |
| 58 | + count={ |
| 59 | + isKymaCompanionEnabled && companionFeedbackLink && showNewIndicators |
| 60 | + ? '1' |
| 61 | + : undefined |
| 62 | + } |
| 63 | + /> |
| 64 | + {createPortal( |
| 65 | + <Popover |
| 66 | + opener="feedbackOpener" |
| 67 | + open={feedbackOpen} |
| 68 | + onClose={() => setFeedbackOpen(false)} |
| 69 | + horizontalAlign="End" |
| 70 | + placement="Bottom" |
| 71 | + verticalAlign="Center" |
| 72 | + className="feedbackPopover" |
| 73 | + > |
| 74 | + <FlexBox |
| 75 | + alignItems="Start" |
| 76 | + direction="Column" |
| 77 | + justifyContent="Start" |
| 78 | + gap={4} |
| 79 | + className="sap-margin-bottom-medium" |
| 80 | + > |
| 81 | + <Title level="H5" size="H5"> |
| 82 | + {t('feedback.intro.title')} |
| 83 | + </Title> |
| 84 | + <Text className="info-text">{t('feedback.intro.info')}</Text> |
| 85 | + </FlexBox> |
| 86 | + {isKymaCompanionEnabled && companionFeedbackLink && ( |
| 87 | + <FlexBox |
| 88 | + alignItems="Start" |
| 89 | + direction="Column" |
| 90 | + justifyContent="Start" |
| 91 | + gap={16} |
| 92 | + className="sap-margin-bottom-medium" |
| 93 | + > |
| 94 | + <FlexBox |
| 95 | + direction="Row" |
| 96 | + alignItems="Center" |
| 97 | + justifyContent="Start" |
| 98 | + gap={12} |
| 99 | + > |
| 100 | + <Title level="H6" size="H6"> |
| 101 | + {t('feedback.joule.title')} |
| 102 | + </Title> |
| 103 | + {showNewIndicators && ( |
| 104 | + <ObjectStatus state="Information" inverted> |
| 105 | + {t('feedback.new')} |
| 106 | + </ObjectStatus> |
| 107 | + )} |
| 108 | + </FlexBox> |
| 109 | + <Text className="info-text">{t('feedback.joule.info')}</Text> |
| 110 | + <Button |
| 111 | + design="Emphasized" |
| 112 | + endIcon="inspect" |
| 113 | + onClick={() => { |
| 114 | + handleNewFeedbackViewed(); |
| 115 | + window.open(companionFeedbackLink, '_blank'); |
| 116 | + }} |
| 117 | + > |
| 118 | + {t('feedback.give-feedback')} |
| 119 | + </Button> |
| 120 | + </FlexBox> |
| 121 | + )} |
| 122 | + <FlexBox |
| 123 | + alignItems="Start" |
| 124 | + direction="Column" |
| 125 | + justifyContent="Start" |
| 126 | + gap={16} |
| 127 | + > |
| 128 | + <Title level="H6" size="H6"> |
| 129 | + {t('feedback.kyma.title')} |
| 130 | + </Title> |
| 131 | + <Text className="info-text">{t('feedback.kyma.info')}</Text> |
| 132 | + <Button |
| 133 | + endIcon="inspect" |
| 134 | + design={ |
| 135 | + !isKymaCompanionEnabled || !companionFeedbackLink |
| 136 | + ? 'Emphasized' |
| 137 | + : 'Default' |
| 138 | + } |
| 139 | + onClick={() => window.open(kymaFeedbackLink, '_blank')} |
| 140 | + > |
| 141 | + {t('feedback.give-feedback')} |
| 142 | + </Button> |
| 143 | + </FlexBox> |
| 144 | + </Popover>, |
| 145 | + document.body, |
| 146 | + )} |
| 147 | + </> |
| 148 | + ); |
| 149 | +} |
0 commit comments