import React, { Fragment, useEffect, useState } from 'react'; import { useHistory } from 'react-router'; import PropTypes from 'prop-types'; import { Button, Card, CardBody, CardTitle, Col, Row } from 'reactstrap'; import reduxConnect from '../../../../redux/utils/connect'; import { planRoutes } from './UserPlans'; import { allMediaTypes } from '../../../../redux/modules/appState/searchByFilters'; import { capitalize } from 'lodash'; import { convertUTCtoLocal, setDocumentData } from '../../../../common/helper'; import { translate } from 'react-i18next'; import CancellationFeedback from './CancellationFeedback'; function CurrentPlan({ actions, user, t }) { const [cancelModal, setCancelModal] = useState(false); const { restrictions } = user; const { push } = useHistory(); useEffect(() => { setDocumentData('title', 'Active Plan Details'); return () => setDocumentData('title'); // default }, []); function changePlan() { push(`/app/plans/${planRoutes.update}`); } function toggleCancelModal() { setCancelModal((prev) => !prev); } const { plans, limits, isPlanCancelled, subStartDate, subEndDate } = restrictions; const selectedMedias = []; const notSelectedMedias = []; allMediaTypes.map((v) => { if (plans[v]) { selectedMedias.push(t(`searchTab.sourceTypes.${v}`, capitalize(v))); } else { notSelectedMedias.push(t(`searchTab.sourceTypes.${v}`, capitalize(v))); } }); const isRTL = document.documentElement.dir === 'rtl'; return (
{t('plans.currentPlan.subHeading')}
{plans.price === 0 ? t('plans.currentPlan.freePlan') : `$${plans.price}`}
{plans.price === 0 ? (   ) : subStartDate && subEndDate ? ( `${convertUTCtoLocal( subStartDate, 'MMM D, YYYY' )} - ${convertUTCtoLocal(subEndDate, 'MMM D, YYYY')}` ) : ( t('plans.currentPlan.perMonth') )}
{t('plans.currentPlan.currentPlanDetails')}

{t('plans.currentPlan.selectedMediaTypes')}

{selectedMedias.length > 0 ? selectedMedias.join(', ') : t('plans.currentPlan.none')} {notSelectedMedias.length > 0 ? ( ({t('plans.currentPlan.upgradeToGet')}:{' '} {notSelectedMedias.join(', ')}) ) : ( '' )}

{t('plans.currentPlan.selectedLicenses')}

{!isRTL ? (
{limits.savedFeeds.current}/{limits.savedFeeds.limit}
) : (
{limits.savedFeeds.limit}/{limits.savedFeeds.current}
)}
{t('plans.currentPlan.feedsLicenses')}
{!isRTL ? (
{limits.searchesPerDay.current}/ {limits.searchesPerDay.limit}
) : (
{limits.searchesPerDay.limit}/ {limits.searchesPerDay.current}
)}
{t('plans.currentPlan.searchLicenses')}
{!isRTL ? (
{limits.webFeeds.current}/{limits.webFeeds.limit}
) : (
{limits.webFeeds.limit}/{limits.webFeeds.current}
)}
{t('plans.currentPlan.webfeedLicenses')}
{!isRTL ? (
{limits.alerts.current}/{limits.alerts.limit}
) : (
{limits.alerts.limit}/{limits.alerts.current}
)}
{t('plans.currentPlan.alertLicenses')}
{!isRTL ? (
{limits.subscriberAccounts.current}/ {limits.subscriberAccounts.limit}
) : (
{limits.subscriberAccounts.limit}/ {limits.subscriberAccounts.current}
)}
{t('plans.currentPlan.userAccounts')}

{t('plans.currentPlan.features')}

{plans.analytics ? ( t('plans.currentPlan.analytics') ) : ( {t('plans.currentPlan.none')} ({t('plans.currentPlan.upgradeToGet')}:{' '} {t('plans.currentPlan.analytics')}) )}

{plans.price > 0 && (
{!isPlanCancelled ? (

{t('plans.currentPlan.cancelWarning')}

) : (

{t('plans.currentPlan.alreadyCancelled')}

)}
)} ); } CurrentPlan.propTypes = { t: PropTypes.func.isRequired, actions: PropTypes.object, user: PropTypes.object }; export default reduxConnect('user', ['common', 'auth', 'user'])( translate(['tabsContent'], { wait: true })(CurrentPlan) );