2021-03-12 03:31:19 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
import { slide as Menu } from 'react-burger-menu';
|
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-05-07 06:56:32 +00:00
|
|
|
import { getData, LS_KEYS, setData } 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';
|
2021-04-27 09:17:38 +00:00
|
|
|
import { File } from 'services/fileService';
|
2021-03-27 13:52:53 +00:00
|
|
|
import isElectron from 'is-electron';
|
2021-04-23 07:12:56 +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-18 13:01:40 +00:00
|
|
|
import EnteSpinner from './EnteSpinner';
|
2021-04-19 08:29:12 +00:00
|
|
|
import LinkButton from 'pages/gallery/components/LinkButton';
|
2021-04-22 12:56:06 +00:00
|
|
|
import { downloadApp } from 'utils/common';
|
|
|
|
import { logoutUser } from 'services/userService';
|
2021-04-28 06:38:52 +00:00
|
|
|
import { SetDialogMessage } from './MessageDialog';
|
2021-04-07 07:18:45 +00:00
|
|
|
|
2021-03-12 04:50:58 +00:00
|
|
|
interface Props {
|
2021-04-27 09:17:38 +00:00
|
|
|
files: File[];
|
2021-04-23 07:12:56 +00:00
|
|
|
collections: Collection[];
|
2021-04-20 11:09:03 +00:00
|
|
|
setDialogMessage: SetDialogMessage;
|
2021-05-11 04:48:47 +00:00
|
|
|
showPlanSelectorModal: () => void;
|
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-22 14:30:07 +00:00
|
|
|
const [recoverModalView, setRecoveryModalView] = useState(false);
|
2021-05-11 04:48:47 +00:00
|
|
|
const [accountDeleteModalView, setAccountDeleteModalView] = useState(false);
|
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-04-19 08:29:12 +00:00
|
|
|
function openSupportMail() {
|
|
|
|
var a = document.createElement('a');
|
|
|
|
a.href = 'mailto:contact@ente.io';
|
|
|
|
a.target = '_blank';
|
|
|
|
a.rel = 'noreferrer noopener';
|
|
|
|
a.click();
|
|
|
|
}
|
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-25 15:16:58 +00:00
|
|
|
props.setDialogMessage({
|
|
|
|
title: constants.DOWNLOAD_APP,
|
|
|
|
content: constants.DOWNLOAD_APP_MESSAGE(),
|
|
|
|
staticBackdrop: true,
|
|
|
|
proceed: {
|
|
|
|
text: constants.DOWNLOAD,
|
|
|
|
action: downloadApp,
|
|
|
|
variant: 'success',
|
|
|
|
},
|
|
|
|
close: {
|
|
|
|
text: constants.CLOSE,
|
|
|
|
},
|
2021-04-22 12:56:06 +00:00
|
|
|
});
|
2021-03-29 05:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-19 08:29:12 +00:00
|
|
|
|
2021-04-05 05:12:37 +00:00
|
|
|
const router = useRouter();
|
2021-04-22 05:22:42 +00:00
|
|
|
function onManageClick() {
|
2021-04-23 05:19:45 +00:00
|
|
|
setIsOpen(false);
|
2021-05-11 04:48:47 +00:00
|
|
|
props.showPlanSelectorModal();
|
2021-04-22 05:22:42 +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-04-25 15:16:58 +00:00
|
|
|
<div
|
|
|
|
style={{
|
2021-05-23 05:49:53 +00:00
|
|
|
marginBottom: '8px',
|
2021-04-25 15:16:58 +00:00
|
|
|
outline: 'none',
|
|
|
|
color: 'rgb(45, 194, 98)',
|
|
|
|
fontSize: '16px',
|
|
|
|
}}
|
|
|
|
>
|
2021-04-20 11:27:27 +00:00
|
|
|
{user?.email}
|
2021-03-16 21:07:07 +00:00
|
|
|
</div>
|
2021-05-23 05:49:53 +00:00
|
|
|
<div style={{ flex: 1 }}>
|
|
|
|
<div style={{ outline: 'none' }}>
|
|
|
|
<div style={{ display: 'flex' }}>
|
|
|
|
<h5 style={{ margin: '4px 0 12px 2px' }}>
|
|
|
|
{constants.SUBSCRIPTION_PLAN}
|
|
|
|
</h5>
|
2021-04-20 11:27:27 +00:00
|
|
|
</div>
|
2021-05-23 05:49:53 +00:00
|
|
|
<div style={{ color: '#959595' }}>
|
|
|
|
{isSubscriptionActive(subscription) ? (
|
|
|
|
isOnFreePlan(subscription) ? (
|
|
|
|
constants.FREE_SUBSCRIPTION_INFO(
|
|
|
|
subscription?.expiryTime
|
|
|
|
)
|
|
|
|
) : isSubscriptionCancelled(subscription) ? (
|
|
|
|
constants.RENEWAL_CANCELLED_SUBSCRIPTION_INFO(
|
|
|
|
subscription?.expiryTime
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
constants.RENEWAL_ACTIVE_SUBSCRIPTION_INFO(
|
|
|
|
subscription?.expiryTime
|
|
|
|
)
|
2021-03-18 15:15:13 +00:00
|
|
|
)
|
2021-03-16 12:52:57 +00:00
|
|
|
) : (
|
2021-05-23 05:49:53 +00:00
|
|
|
<p>{constants.SUBSCRIPTION_EXPIRED}</p>
|
|
|
|
)}
|
|
|
|
<Button
|
|
|
|
variant="link"
|
|
|
|
size="sm"
|
|
|
|
onClick={onManageClick}
|
|
|
|
style={{ paddingLeft: 0, color: '#2dc262' }}
|
|
|
|
>
|
|
|
|
{isSubscribed(subscription)
|
|
|
|
? constants.MANAGE
|
|
|
|
: constants.SUBSCRIBE}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2021-03-14 07:19:41 +00:00
|
|
|
</div>
|
2021-05-23 05:49:53 +00:00
|
|
|
<div style={{ outline: 'none', marginTop: '30px' }}></div>
|
|
|
|
<div>
|
|
|
|
<h5 style={{ marginBottom: '12px' }}>
|
|
|
|
{constants.USAGE_DETAILS}
|
|
|
|
</h5>
|
|
|
|
<div style={{ color: '#959595' }}>
|
|
|
|
{usage ? (
|
|
|
|
constants.USAGE_INFO(
|
|
|
|
usage,
|
|
|
|
Math.ceil(
|
|
|
|
Number(convertBytesToGBs(subscription?.storage))
|
|
|
|
)
|
2021-03-12 03:31:19 +00:00
|
|
|
)
|
2021-05-23 05:49:53 +00:00
|
|
|
) : (
|
|
|
|
<div style={{ textAlign: 'center' }}>
|
|
|
|
<EnteSpinner
|
|
|
|
style={{
|
|
|
|
borderWidth: '2px',
|
|
|
|
width: '20px',
|
|
|
|
height: '20px',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-03-12 03:31:19 +00:00
|
|
|
</div>
|
2021-05-23 05:49:53 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
height: '1px',
|
|
|
|
marginTop: '40px',
|
|
|
|
background: '#242424',
|
|
|
|
width: '100%',
|
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<LinkButton style={{ marginTop: '30px' }} onClick={openFeedbackURL}>
|
|
|
|
{constants.REQUEST_FEATURE}
|
|
|
|
</LinkButton>
|
|
|
|
<LinkButton style={{ marginTop: '30px' }} onClick={openSupportMail}>
|
|
|
|
{constants.SUPPORT}
|
|
|
|
</LinkButton>
|
|
|
|
<>
|
|
|
|
<RecoveryKeyModal
|
|
|
|
show={recoverModalView}
|
|
|
|
onHide={() => setRecoveryModalView(false)}
|
|
|
|
somethingWentWrong={() =>
|
|
|
|
props.setDialogMessage({
|
|
|
|
title: constants.RECOVER_KEY_GENERATION_FAILED,
|
|
|
|
close: { variant: 'danger' },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<LinkButton
|
|
|
|
style={{ marginTop: '30px' }}
|
|
|
|
onClick={() => setRecoveryModalView(true)}
|
|
|
|
>
|
|
|
|
{constants.DOWNLOAD_RECOVERY_KEY}
|
|
|
|
</LinkButton>
|
|
|
|
</>
|
|
|
|
<LinkButton
|
|
|
|
style={{ marginTop: '30px' }}
|
|
|
|
onClick={() => {
|
|
|
|
setData(LS_KEYS.SHOW_BACK_BUTTON, { value: true });
|
|
|
|
router.push('changePassword');
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{constants.CHANGE_PASSWORD}
|
|
|
|
</LinkButton>
|
|
|
|
<LinkButton style={{ marginTop: '30px' }} onClick={exportFiles}>
|
|
|
|
{constants.EXPORT}
|
|
|
|
</LinkButton>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
height: '1px',
|
|
|
|
marginTop: '40px',
|
|
|
|
background: '#242424',
|
|
|
|
width: '100%',
|
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<LinkButton
|
|
|
|
variant="danger"
|
|
|
|
style={{ marginTop: '30px' }}
|
|
|
|
onClick={() =>
|
2021-04-20 11:09:03 +00:00
|
|
|
props.setDialogMessage({
|
2021-05-23 05:49:53 +00:00
|
|
|
title: `${constants.CONFIRM} ${constants.LOGOUT}`,
|
|
|
|
content: constants.LOGOUT_MESSAGE,
|
|
|
|
staticBackdrop: true,
|
|
|
|
proceed: {
|
|
|
|
text: constants.LOGOUT,
|
|
|
|
action: logoutUser,
|
|
|
|
variant: 'danger',
|
|
|
|
},
|
|
|
|
close: { text: constants.CANCEL },
|
2021-04-20 11:09:03 +00:00
|
|
|
})
|
|
|
|
}
|
2021-04-28 06:09:56 +00:00
|
|
|
>
|
2021-05-23 05:49:53 +00:00
|
|
|
logout
|
2021-04-19 08:29:12 +00:00
|
|
|
</LinkButton>
|
2021-05-23 05:49:53 +00:00
|
|
|
</div>
|
2021-03-12 03:31:19 +00:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
}
|