|
| 1 | +// Copyright (C) 2023 CVAT.ai Corporation |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import React, { useCallback, useEffect, useState } from 'react'; |
| 6 | +import { useSelector } from 'react-redux'; |
| 7 | +import { CombinedState } from 'reducers'; |
| 8 | +import Typography from 'antd/es/typography'; |
| 9 | +import Modal from 'antd/lib/modal'; |
| 10 | +import { Col, Row } from 'antd/lib/grid'; |
| 11 | +import Switch from 'antd/lib/switch'; |
| 12 | +import Button from 'antd/lib/button'; |
| 13 | +import Space from 'antd/lib/space'; |
| 14 | +import { getCore } from 'cvat-core-wrapper'; |
| 15 | +import PaidFeaturesPreviewImage from 'assets/paid-features-preview.png'; |
| 16 | +import moment from 'moment'; |
| 17 | +import config from 'config'; |
| 18 | +import './styles.scss'; |
| 19 | + |
| 20 | +const core = getCore(); |
| 21 | +const { CVAT_BILLING_URL } = config; |
| 22 | + |
| 23 | +export default function PremiumFeaturesModal(): JSX.Element { |
| 24 | + const [isModalOpen, setIsModalOpen] = useState(false); |
| 25 | + const [dontShowAgainToday, setDontShowAgainToday] = useState(localStorage.getItem('paidNotificationShown') === moment().format('YYYY-MM-DD')); |
| 26 | + const organization = useSelector((state: CombinedState) => state.organizations.current); |
| 27 | + const user = useSelector((state: CombinedState) => state.auth.user); |
| 28 | + |
| 29 | + const closeModal = useCallback((): void => { |
| 30 | + if (dontShowAgainToday) { |
| 31 | + const now = moment().format('YYYY-MM-DD'); |
| 32 | + localStorage.setItem('paidNotificationShown', now); |
| 33 | + } |
| 34 | + setIsModalOpen(false); |
| 35 | + }, [dontShowAgainToday]); |
| 36 | + |
| 37 | + const openBillingPage = useCallback((): void => { |
| 38 | + const params = organization?.id ? `/?type=organization&orgId=${organization.id}` : '/?type=personal'; |
| 39 | + const billingURL = `${CVAT_BILLING_URL}${params}`; |
| 40 | + window.open(billingURL, '_self'); |
| 41 | + }, []); |
| 42 | + |
| 43 | + useEffect(() => { |
| 44 | + if (!dontShowAgainToday) { |
| 45 | + core.server.hasLimits(user.id, organization?.id).then((hasLimits: boolean) => { |
| 46 | + if (!hasLimits && !user.isSuperuser && !user.isStaff) { |
| 47 | + setIsModalOpen(true); |
| 48 | + } |
| 49 | + }); |
| 50 | + } |
| 51 | + }, [user, organization]); |
| 52 | + |
| 53 | + return ( |
| 54 | + <> |
| 55 | + <Modal |
| 56 | + className='cvat-paid-features-notification' |
| 57 | + visible={isModalOpen} |
| 58 | + onCancel={closeModal} |
| 59 | + closable={false} |
| 60 | + width={725} |
| 61 | + footer={( |
| 62 | + <Row justify='space-between'> |
| 63 | + <Col className='cvat-paid-features-notification-dont-show'> |
| 64 | + <Switch onChange={(checked: boolean) => setDontShowAgainToday(checked)} /> |
| 65 | + <Typography.Text>Don't show again today</Typography.Text> |
| 66 | + </Col> |
| 67 | + <Col> |
| 68 | + <Button onClick={closeModal}> |
| 69 | + Close |
| 70 | + </Button> |
| 71 | + <Button |
| 72 | + type='primary' |
| 73 | + onClick={openBillingPage} |
| 74 | + > |
| 75 | + Check premium features |
| 76 | + </Button> |
| 77 | + </Col> |
| 78 | + </Row> |
| 79 | + )} |
| 80 | + > |
| 81 | + <img src={PaidFeaturesPreviewImage} alt='paid-features-preview' /> |
| 82 | + <Row className='cvat-paid-features-notification-description' justify='space-between'> |
| 83 | + <Col className='cvat-paid-features-notification-description-title' span={8}> |
| 84 | + <Typography.Title level={3}>Enhance your experience with premium features</Typography.Title> |
| 85 | + </Col> |
| 86 | + <Col className='cvat-paid-features-notification-description-details' span={14}> |
| 87 | + <Space direction='vertical' size='small'> |
| 88 | + <Typography.Text> |
| 89 | + We've added premium features designed to enhance your experience and productivity. |
| 90 | + These features include advanced analytics and reporting, automated annotation, |
| 91 | + better user management, and increased storage capacity. |
| 92 | + </Typography.Text> |
| 93 | + <Typography.Text> |
| 94 | + In order to access these features, you need to subscribe to our paid plan. |
| 95 | + </Typography.Text> |
| 96 | + </Space> |
| 97 | + </Col> |
| 98 | + </Row> |
| 99 | + <Row /> |
| 100 | + </Modal> |
| 101 | + </> |
| 102 | + ); |
| 103 | +} |
0 commit comments