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';
|
|
|
|
import subscriptionService, {
|
|
|
|
Subscription,
|
|
|
|
} from 'services/subscriptionService';
|
|
|
|
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-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-03-27 13:52:53 +00:00
|
|
|
interface Props {
|
|
|
|
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-27 13:52:53 +00:00
|
|
|
}
|
|
|
|
export default function Sidebar(props: Props) {
|
2021-03-12 03:31:19 +00:00
|
|
|
const [usage, SetUsage] = useState<string>(null);
|
|
|
|
const subscription: Subscription = getData(LS_KEYS.SUBSCRIPTION);
|
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;
|
|
|
|
}
|
|
|
|
const usage = await subscriptionService.getUsage();
|
2021-03-12 03:31:19 +00:00
|
|
|
|
|
|
|
SetUsage(usage);
|
|
|
|
};
|
|
|
|
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-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-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-03-16 04:40:27 +00:00
|
|
|
{subscription?.productID == 'free'
|
|
|
|
? constants.FREE_SUBSCRIPTION_INFO(
|
2021-04-05 15:37:56 +00:00
|
|
|
subscription?.expiryTime
|
|
|
|
)
|
2021-03-16 04:40:27 +00:00
|
|
|
: constants.PAID_SUBSCRIPTION_INFO(
|
2021-04-05 15:37:56 +00:00
|
|
|
subscription?.expiryTime
|
|
|
|
)}
|
2021-03-14 07:19:41 +00:00
|
|
|
</div>
|
2021-03-12 03:31:19 +00:00
|
|
|
</div>
|
2021-03-14 07:41:50 +00:00
|
|
|
<div style={{ outline: 'none', marginTop: '30px' }}>
|
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(
|
|
|
|
Number(
|
|
|
|
subscriptionService.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-05 13:55:41 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
height: '1px',
|
|
|
|
marginTop: '40px',
|
|
|
|
background: '#242424',
|
|
|
|
width: '100%',
|
|
|
|
}}
|
|
|
|
></div>
|
2021-04-05 07:41:48 +00:00
|
|
|
<>
|
|
|
|
<RecoveryKeyModal
|
|
|
|
show={modalView}
|
|
|
|
onHide={() => setModalView(false)}
|
2021-04-05 13:18:41 +00:00
|
|
|
somethingWentWrong={props.somethingWentWrong}
|
2021-04-05 07:41:48 +00:00
|
|
|
/>
|
|
|
|
<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',
|
|
|
|
marginTop: '30px',
|
|
|
|
}}
|
|
|
|
onClick={() => props.setConfirmAction(CONFIRM_ACTION.LOGOUT)}
|
|
|
|
>
|
|
|
|
logout
|
|
|
|
</h5>
|
2021-03-12 03:31:19 +00:00
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
}
|