|
| 1 | +import { |
| 2 | + useTheme, |
| 3 | + LicensingErrorCodes, |
| 4 | + Button, |
| 5 | + ButtonVariantType, |
| 6 | + DevtronLicenseCard, |
| 7 | + DevtronProgressing, |
| 8 | + ENTERPRISE_SUPPORT_LINK, |
| 9 | + ErrorScreenManager, |
| 10 | + Icon, |
| 11 | + InfoBlock, |
| 12 | + LoginBanner, |
| 13 | + URLS, |
| 14 | + useAsync, |
| 15 | + getHandleOpenURL, |
| 16 | + CONTACT_SUPPORT_LINK, |
| 17 | + ActivateLicenseDialog, |
| 18 | + ICDevtronWithBorder, |
| 19 | + API_STATUS_CODES, |
| 20 | +} from '@devtron-labs/devtron-fe-common-lib' |
| 21 | +import { useEffect, useState } from 'react' |
| 22 | +import { useHistory } from 'react-router-dom' |
| 23 | +import { getDevtronLicenseInfo } from './service' |
| 24 | + |
| 25 | +const ActivateLicense = () => { |
| 26 | + const history = useHistory() |
| 27 | + const [isLoading, licenseData, licenseDataError, reloadLicenseData] = useAsync(getDevtronLicenseInfo, []) |
| 28 | + const [showActivateDialog, setShowActivateDialog] = useState<boolean>(false) |
| 29 | + const { appTheme } = useTheme() |
| 30 | + |
| 31 | + const redirectToLogin = () => { |
| 32 | + history.replace(URLS.LOGIN_SSO) |
| 33 | + } |
| 34 | + |
| 35 | + useEffect(() => { |
| 36 | + if (isLoading) { |
| 37 | + return |
| 38 | + } |
| 39 | + |
| 40 | + // licenseDataError.code === 404 means, oss and licensing does not exist |
| 41 | + // In case licenseStatusError is null, license is valid |
| 42 | + if (licenseDataError?.code === API_STATUS_CODES.NOT_FOUND || !licenseData.licenseStatusError) { |
| 43 | + redirectToLogin() |
| 44 | + return |
| 45 | + } |
| 46 | + |
| 47 | + if (licenseData.licenseStatusError.code === LicensingErrorCodes.LicKeyNotFound) { |
| 48 | + setShowActivateDialog(true) |
| 49 | + } |
| 50 | + }, [isLoading, licenseData]) |
| 51 | + |
| 52 | + if (isLoading) { |
| 53 | + return <DevtronProgressing parentClasses="bg__primary flex full-height-width" classes="icon-dim-80" /> |
| 54 | + } |
| 55 | + |
| 56 | + if (licenseDataError) { |
| 57 | + return ( |
| 58 | + <div className="full-height-width bg__tertiary"> |
| 59 | + <ErrorScreenManager code={licenseDataError?.code} reload={reloadLicenseData} /> |
| 60 | + </div> |
| 61 | + ) |
| 62 | + } |
| 63 | + |
| 64 | + const handleChangeLicense = () => { |
| 65 | + setShowActivateDialog(true) |
| 66 | + } |
| 67 | + |
| 68 | + const renderInvalidLicenseDialog = () => ( |
| 69 | + <div className="flexbox-col p-36 dc__gap-32 w-400 border__primary br-12"> |
| 70 | + <div className="flexbox-col dc__gap-20"> |
| 71 | + <ICDevtronWithBorder /> |
| 72 | + <div className="flexbox-col dc__gap-4"> |
| 73 | + <div className="fs-20 lh-1-5 fw-7 cn-9 font-merriweather dc__truncate"> |
| 74 | + {licenseData.enterpriseName} |
| 75 | + </div> |
| 76 | + <div className="fs-16 lh-1-5 cr-5 fw-4">Your license key is no longer valid</div> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + {licenseData.licenseStatusError && |
| 80 | + licenseData.licenseStatusError.code !== LicensingErrorCodes.LicenseExpired ? ( |
| 81 | + <InfoBlock |
| 82 | + heading="Need help?" |
| 83 | + description={ |
| 84 | + <span> |
| 85 | + For further details mail us at |
| 86 | + <a href={`mailto:${ENTERPRISE_SUPPORT_LINK}`}>{ENTERPRISE_SUPPORT_LINK}</a> or contact |
| 87 | + Devtron Support |
| 88 | + </span> |
| 89 | + } |
| 90 | + variant="help" |
| 91 | + buttonProps={{ |
| 92 | + text: 'Contact Support', |
| 93 | + variant: ButtonVariantType.text, |
| 94 | + onClick: getHandleOpenURL(CONTACT_SUPPORT_LINK), |
| 95 | + dataTestId: 'contact-support', |
| 96 | + startIcon: <Icon name="ic-chat-circle-dots" color="B500" size={16} />, |
| 97 | + }} |
| 98 | + layout="column" |
| 99 | + /> |
| 100 | + ) : ( |
| 101 | + <DevtronLicenseCard |
| 102 | + enterpriseName={licenseData.enterpriseName} |
| 103 | + expiryDate={licenseData.expiryDate} |
| 104 | + ttl={licenseData.ttl} |
| 105 | + licenseStatus={licenseData.licenseStatus} |
| 106 | + isTrial={licenseData.isTrial} |
| 107 | + licenseSuffix={licenseData.licenseSuffix} |
| 108 | + appTheme={appTheme} |
| 109 | + /> |
| 110 | + )} |
| 111 | + <div className="flex dc__content-space"> |
| 112 | + <span>Have another license key?</span> |
| 113 | + <Button |
| 114 | + dataTestId="change-license" |
| 115 | + text="Change license" |
| 116 | + variant={ButtonVariantType.text} |
| 117 | + onClick={handleChangeLicense} |
| 118 | + /> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + ) |
| 122 | + |
| 123 | + return ( |
| 124 | + <div className="full-height-width bg__secondary dc__grid-half"> |
| 125 | + <div className="flexbox p-16"> |
| 126 | + <LoginBanner /> |
| 127 | + </div> |
| 128 | + <div className="flex"> |
| 129 | + {showActivateDialog ? ( |
| 130 | + <ActivateLicenseDialog |
| 131 | + fingerprint={licenseData.fingerprint || ''} |
| 132 | + enterpriseName={licenseData.enterpriseName} |
| 133 | + handleLicenseActivateSuccess={redirectToLogin} |
| 134 | + /> |
| 135 | + ) : ( |
| 136 | + renderInvalidLicenseDialog() |
| 137 | + )} |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + ) |
| 141 | +} |
| 142 | + |
| 143 | +export default ActivateLicense |
0 commit comments