2021-03-12 03:31:19 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
import { slide as Menu } from 'react-burger-menu';
|
2021-04-04 13:59:13 +00:00
|
|
|
import { CONFIRM_ACTION } from 'components/ConfirmDialog';
|
2021-03-12 03:31:19 +00:00
|
|
|
import Spinner from 'react-bootstrap/Spinner';
|
2021-03-18 15:22:34 +00:00
|
|
|
import billingService, { Subscription } from 'services/billingService';
|
2021-03-12 03:31:19 +00:00
|
|
|
import constants from 'utils/strings/constants';
|
2021-03-12 04:50:58 +00:00
|
|
|
import { getData, LS_KEYS } from 'utils/storage/localStorage';
|
2021-03-12 05:33:33 +00:00
|
|
|
import { getToken } from 'utils/common/key';
|
2021-03-14 07:41:50 +00:00
|
|
|
import { getEndpoint } from 'utils/common/apiUtil';
|
2021-03-16 09:01:04 +00:00
|
|
|
import { Button } from 'react-bootstrap';
|
2021-03-17 07:27:26 +00:00
|
|
|
import {
|
2021-04-17 13:48:25 +00:00
|
|
|
isSubscriptionActive,
|
2021-03-17 07:27:26 +00:00
|
|
|
convertBytesToGBs,
|
|
|
|
getUserSubscription,
|
2021-03-17 10:44:29 +00:00
|
|
|
isOnFreePlan,
|
2021-03-18 15:26:43 +00:00
|
|
|
isSubscriptionCancelled,
|
|
|
|
isSubscribed,
|
2021-03-17 07:27:26 +00:00
|
|
|
} from 'utils/billingUtil';
|
2021-03-12 03:31:19 +00:00
|
|
|
|
2021-03-27 13:52:53 +00:00
|
|
|
import exportService from 'services/exportService';
|
|
|
|
import { file } from 'services/fileService';
|
|
|
|
import isElectron from 'is-electron';
|
2021-03-31 05:53:21 +00:00
|
|
|
import { collection } from 'services/collectionService';
|
2021-04-05 05:12:37 +00:00
|
|
|
import { useRouter } from 'next/router';
|
2021-04-05 07:41:48 +00:00
|
|
|
import RecoveryKeyModal from './RecoveryKeyModal';
|
2021-04-05 15:37:56 +00:00
|
|
|
import { justSignedUp } from 'utils/storage';
|
2021-04-07 07:18:45 +00:00
|
|
|
|
2021-03-12 04:50:58 +00:00
|
|
|
interface Props {
|
2021-03-27 13:52:53 +00:00
|
|
|
files: file[];
|
2021-03-31 05:53:21 +00:00
|
|
|
collections: collection[];
|
2021-04-04 13:59:13 +00:00
|
|
|
setConfirmAction: any;
|
2021-04-05 13:18:41 +00:00
|
|
|
somethingWentWrong: any;
|
2021-03-16 21:07:07 +00:00
|
|
|
setPlanModalView;
|
2021-03-17 12:07:20 +00:00
|
|
|
setBannerMessage;
|
2021-03-12 04:50:58 +00:00
|
|
|
}
|
|
|
|
export default function Sidebar(props: Props) {
|
2021-03-12 03:31:19 +00:00
|
|
|
const [usage, SetUsage] = useState<string>(null);
|
2021-03-17 07:27:26 +00:00
|
|
|
const [user, setUser] = useState(null);
|
|
|
|
const [subscription, setSubscription] = useState<Subscription>(null);
|
|
|
|
useEffect(() => {
|
|
|
|
setUser(getData(LS_KEYS.USER));
|
|
|
|
setSubscription(getUserSubscription());
|
|
|
|
}, []);
|
2021-03-12 04:24:01 +00:00
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
2021-04-05 15:37:56 +00:00
|
|
|
const [modalView, setModalView] = useState(justSignedUp());
|
2021-03-12 03:31:19 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const main = async () => {
|
2021-03-13 05:31:46 +00:00
|
|
|
if (!isOpen) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-18 15:22:34 +00:00
|
|
|
const usage = await billingService.getUsage();
|
2021-03-12 03:31:19 +00:00
|
|
|
|
|
|
|
SetUsage(usage);
|
2021-03-17 07:27:26 +00:00
|
|
|
setSubscription(getUserSubscription());
|
2021-03-12 03:31:19 +00:00
|
|
|
};
|
|
|
|
main();
|
2021-03-13 05:31:46 +00:00
|
|
|
}, [isOpen]);
|
2021-03-12 03:31:19 +00:00
|
|
|
|
2021-03-14 07:41:50 +00:00
|
|
|
function openFeedbackURL() {
|
2021-03-16 04:40:27 +00:00
|
|
|
const feedbackURL: string =
|
|
|
|
getEndpoint() + '/users/feedback?token=' + getToken();
|
2021-03-14 07:41:50 +00:00
|
|
|
var win = window.open(feedbackURL, '_blank');
|
|
|
|
win.focus();
|
|
|
|
}
|
2021-03-29 05:15:01 +00:00
|
|
|
function exportFiles() {
|
|
|
|
if (isElectron()) {
|
2021-03-31 05:53:21 +00:00
|
|
|
exportService.exportFiles(props.files, props.collections);
|
2021-03-29 05:15:01 +00:00
|
|
|
} else {
|
2021-04-04 13:59:13 +00:00
|
|
|
props.setConfirmAction(CONFIRM_ACTION.DOWNLOAD_APP);
|
2021-03-29 05:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-08 05:08:15 +00:00
|
|
|
async function onManageClick(event) {
|
|
|
|
try {
|
|
|
|
event.preventDefault();
|
|
|
|
await billingService.redirectToCustomerPortal();
|
|
|
|
} catch (error) {
|
|
|
|
props.somethingWentWrong();
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 05:12:37 +00:00
|
|
|
const router = useRouter();
|
2021-03-14 07:41:50 +00:00
|
|
|
|
2021-03-12 03:31:19 +00:00
|
|
|
return (
|
2021-03-12 05:33:33 +00:00
|
|
|
<Menu
|
|
|
|
isOpen={isOpen}
|
|
|
|
onStateChange={(state) => setIsOpen(state.isOpen)}
|
|
|
|
itemListElement="div"
|
|
|
|
>
|
2021-03-16 21:07:07 +00:00
|
|
|
<div style={{ marginBottom: '12px', outline: 'none' }}>
|
|
|
|
Hi {user?.email} !!
|
|
|
|
</div>
|
2021-03-12 04:24:01 +00:00
|
|
|
<div style={{ outline: 'none' }}>
|
2021-03-16 04:40:27 +00:00
|
|
|
<h5 style={{ marginBottom: '12px' }}>
|
|
|
|
{constants.SUBSCRIPTION_PLAN}
|
|
|
|
</h5>
|
2021-03-14 07:19:41 +00:00
|
|
|
<div style={{ color: '#959595' }}>
|
2021-04-17 13:48:25 +00:00
|
|
|
{isSubscriptionActive(subscription) ? (
|
2021-03-17 10:44:29 +00:00
|
|
|
isOnFreePlan(subscription) ? (
|
2021-03-16 12:52:57 +00:00
|
|
|
constants.FREE_SUBSCRIPTION_INFO(
|
|
|
|
subscription?.expiryTime
|
|
|
|
)
|
2021-03-18 15:26:43 +00:00
|
|
|
) : isSubscriptionCancelled(subscription) ? (
|
2021-03-18 15:15:13 +00:00
|
|
|
constants.RENEWAL_CANCELLED_SUBSCRIPTION_INFO(
|
|
|
|
subscription?.expiryTime
|
|
|
|
)
|
2021-03-16 12:52:57 +00:00
|
|
|
) : (
|
2021-03-18 15:15:13 +00:00
|
|
|
constants.RENEWAL_ACTIVE_SUBSCRIPTION_INFO(
|
2021-03-16 12:52:57 +00:00
|
|
|
subscription?.expiryTime
|
|
|
|
)
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<p>{constants.SUBSCRIPTION_EXPIRED}</p>
|
|
|
|
)}
|
2021-03-14 07:19:41 +00:00
|
|
|
</div>
|
2021-04-08 05:08:15 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
}}
|
|
|
|
>
|
2021-03-18 15:26:43 +00:00
|
|
|
{isSubscribed(subscription) ? (
|
2021-03-18 15:15:13 +00:00
|
|
|
<>
|
2021-04-08 05:52:16 +00:00
|
|
|
<div style={{ marginBottom: '10px' }}>
|
2021-04-08 05:08:15 +00:00
|
|
|
<Button
|
|
|
|
variant="success"
|
|
|
|
size="sm"
|
|
|
|
onClick={() => {
|
|
|
|
setIsOpen(false);
|
|
|
|
props.setPlanModalView(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{constants.CHANGE}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
variant="danger"
|
|
|
|
size="sm"
|
|
|
|
onClick={() => {
|
2021-04-18 07:28:49 +00:00
|
|
|
setIsOpen(false);
|
2021-04-08 05:08:15 +00:00
|
|
|
props.setConfirmAction(
|
|
|
|
CONFIRM_ACTION.CANCEL_SUBSCRIPTION
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
style={{ marginLeft: '10px' }}
|
|
|
|
>
|
|
|
|
{constants.CANCEL_SUBSCRIPTION}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2021-03-18 15:15:13 +00:00
|
|
|
<Button
|
2021-04-08 05:08:15 +00:00
|
|
|
variant="secondary"
|
2021-03-18 15:15:13 +00:00
|
|
|
size="sm"
|
2021-04-08 05:08:15 +00:00
|
|
|
onClick={onManageClick}
|
|
|
|
style={{ width: '88%' }}
|
2021-03-18 15:15:13 +00:00
|
|
|
>
|
2021-04-08 05:08:15 +00:00
|
|
|
{constants.MANAGEMENT_PORTAL}
|
2021-03-18 15:15:13 +00:00
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<Button
|
|
|
|
variant="success"
|
|
|
|
size="sm"
|
|
|
|
onClick={() => {
|
|
|
|
setIsOpen(false);
|
|
|
|
props.setPlanModalView(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{constants.SUBSCRIBE}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-03-12 03:31:19 +00:00
|
|
|
</div>
|
2021-03-18 15:15:13 +00:00
|
|
|
<div style={{ outline: 'none', marginTop: '30px' }}></div>
|
|
|
|
<div>
|
2021-03-16 04:40:27 +00:00
|
|
|
<h5 style={{ marginBottom: '12px' }}>
|
|
|
|
{constants.USAGE_DETAILS}
|
|
|
|
</h5>
|
2021-03-14 07:19:41 +00:00
|
|
|
<div style={{ color: '#959595' }}>
|
2021-03-12 03:31:19 +00:00
|
|
|
{usage ? (
|
|
|
|
constants.USAGE_INFO(
|
|
|
|
usage,
|
2021-03-13 05:31:46 +00:00
|
|
|
Math.ceil(
|
2021-03-17 07:27:26 +00:00
|
|
|
Number(convertBytesToGBs(subscription?.storage))
|
2021-03-12 03:31:19 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
<Spinner animation="border" />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-16 04:40:27 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
height: '1px',
|
|
|
|
marginTop: '40px',
|
|
|
|
background: '#242424',
|
|
|
|
width: '100%',
|
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<h5
|
|
|
|
style={{ cursor: 'pointer', marginTop: '40px' }}
|
|
|
|
onClick={openFeedbackURL}
|
|
|
|
>
|
2021-03-14 07:41:50 +00:00
|
|
|
request feature
|
|
|
|
</h5>
|
2021-03-14 07:46:22 +00:00
|
|
|
<h5 style={{ cursor: 'pointer', marginTop: '30px' }}>
|
2021-03-16 04:40:27 +00:00
|
|
|
<a
|
|
|
|
href="mailto:contact@ente.io"
|
|
|
|
style={{ textDecoration: 'inherit', color: 'inherit' }}
|
2021-03-20 15:18:17 +00:00
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer noopener"
|
2021-03-16 04:40:27 +00:00
|
|
|
>
|
2021-03-14 07:46:22 +00:00
|
|
|
support
|
|
|
|
</a>
|
|
|
|
</h5>
|
2021-04-07 07:18:45 +00:00
|
|
|
|
|
|
|
<RecoveryKeyModal
|
|
|
|
show={modalView}
|
|
|
|
onHide={() => setModalView(false)}
|
|
|
|
somethingWentWrong={props.somethingWentWrong}
|
|
|
|
/>
|
|
|
|
<h5
|
|
|
|
style={{ cursor: 'pointer', marginTop: '30px' }}
|
|
|
|
onClick={() => setModalView(true)}
|
|
|
|
>
|
|
|
|
{constants.DOWNLOAD_RECOVERY_KEY}
|
|
|
|
</h5>
|
2021-04-05 14:48:57 +00:00
|
|
|
<h5
|
|
|
|
style={{ cursor: 'pointer', marginTop: '30px' }}
|
|
|
|
onClick={() => router.push('changePassword')}
|
|
|
|
>
|
|
|
|
{constants.CHANGE_PASSWORD}
|
|
|
|
</h5>
|
|
|
|
<h5
|
|
|
|
style={{ cursor: 'pointer', marginTop: '30px' }}
|
|
|
|
onClick={exportFiles}
|
|
|
|
>
|
|
|
|
{constants.EXPORT}
|
|
|
|
</h5>
|
2021-04-05 13:55:41 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
height: '1px',
|
|
|
|
marginTop: '40px',
|
|
|
|
background: '#242424',
|
|
|
|
width: '100%',
|
|
|
|
}}
|
|
|
|
></div>
|
2021-04-04 13:59:13 +00:00
|
|
|
<h5
|
|
|
|
style={{
|
|
|
|
cursor: 'pointer',
|
|
|
|
color: '#F96C6C',
|
2021-04-11 05:13:36 +00:00
|
|
|
margin: '30px 0',
|
2021-04-04 13:59:13 +00:00
|
|
|
}}
|
|
|
|
onClick={() => props.setConfirmAction(CONFIRM_ACTION.LOGOUT)}
|
|
|
|
>
|
|
|
|
logout
|
|
|
|
</h5>
|
2021-03-12 03:31:19 +00:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
}
|