/* eslint-disable react/no-unescaped-entities */
import './WorkspaceLocked.styles.scss';
import type { TabsProps } from 'antd';
import {
Alert,
Button,
Col,
Collapse,
Flex,
List,
Modal,
Row,
Skeleton,
Space,
Tabs,
Typography,
} from 'antd';
import updateCreditCardApi from 'api/billing/checkout';
import logEvent from 'api/common/logEvent';
import ROUTES from 'constants/routes';
import { useNotifications } from 'hooks/useNotifications';
import history from 'lib/history';
import { CircleArrowRight } from 'lucide-react';
import { useAppContext } from 'providers/App/App';
import { useCallback, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useMutation } from 'react-query';
import { LicensePlatform } from 'types/api/licensesV3/getActive';
import { getFormattedDate } from 'utils/timeUtils';
import CustomerStoryCard from './CustomerStoryCard';
import InfoBlocks from './InfoBlocks';
import {
customerStoriesData,
enterpriseGradeValuesData,
faqData,
infoData,
} from './workspaceLocked.data';
export default function WorkspaceBlocked(): JSX.Element {
const {
user,
isFetchingActiveLicenseV3,
trialInfo,
activeLicenseV3,
} = useAppContext();
const isAdmin = user.role === 'ADMIN';
const { notifications } = useNotifications();
const { t } = useTranslation(['workspaceLocked']);
useEffect((): void => {
logEvent('Workspace Blocked: Screen Viewed', {});
}, []);
const handleContactUsClick = (): void => {
logEvent('Workspace Blocked: Contact Us Clicked', {});
};
const handleTabClick = (key: string): void => {
logEvent('Workspace Blocked: Screen Tabs Clicked', { tabKey: key });
};
const handleCollapseChange = (key: string | string[]): void => {
const lastKey = Array.isArray(key) ? key.slice(-1)[0] : key;
logEvent('Workspace Blocked: Screen Tab FAQ Item Clicked', {
panelKey: lastKey,
});
};
useEffect(() => {
if (!isFetchingActiveLicenseV3) {
const shouldBlockWorkspace = trialInfo?.workSpaceBlock;
if (
!shouldBlockWorkspace ||
activeLicenseV3?.platform === LicensePlatform.SELF_HOSTED
) {
history.push(ROUTES.APPLICATION);
}
}
}, [
isFetchingActiveLicenseV3,
trialInfo?.workSpaceBlock,
activeLicenseV3?.platform,
]);
const { mutate: updateCreditCard, isLoading } = useMutation(
updateCreditCardApi,
{
onSuccess: (data) => {
if (data.payload?.redirectURL) {
const newTab = document.createElement('a');
newTab.href = data.payload.redirectURL;
newTab.target = '_blank';
newTab.rel = 'noopener noreferrer';
newTab.click();
}
},
onError: () =>
notifications.error({
message: t('somethingWentWrong'),
}),
},
);
const handleUpdateCreditCard = useCallback(async () => {
logEvent('Workspace Blocked: User Clicked Update Credit Card', {});
updateCreditCard({
url: window.location.href,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [updateCreditCard]);
const handleExtendTrial = (): void => {
logEvent('Workspace Blocked: User Clicked Extend Trial', {});
notifications.info({
message: t('extendTrial'),
duration: 0,
description: (
(