ente/src/components/Sidebar.tsx

159 lines
5.3 KiB
TypeScript
Raw Normal View History

import React, { useEffect, useState } from 'react';
import { slide as Menu } from 'react-burger-menu';
import { CONFIRM_ACTION } from 'components/ConfirmDialog';
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';
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';
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-03-27 13:52:53 +00:00
interface Props {
files: file[];
collections: collection[];
setConfirmAction: any;
2021-03-27 13:52:53 +00:00
}
export default function Sidebar(props: Props) {
const [usage, SetUsage] = useState<string>(null);
const subscription: Subscription = getData(LS_KEYS.SUBSCRIPTION);
const [isOpen, setIsOpen] = useState(false);
2021-04-05 07:41:48 +00:00
const [modalView, setModalView] = useState(false);
useEffect(() => {
const main = async () => {
if (!isOpen) {
return;
}
const usage = await subscriptionService.getUsage();
SetUsage(usage);
};
main();
}, [isOpen]);
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()) {
exportService.exportFiles(props.files, props.collections);
2021-03-29 05:15:01 +00:00
} else {
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
return (
<Menu
isOpen={isOpen}
onStateChange={(state) => setIsOpen(state.isOpen)}
itemListElement="div"
>
<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(
subscription?.expiryTime
)
: constants.PAID_SUBSCRIPTION_INFO(
subscription?.expiryTime
)}
2021-03-14 07:19:41 +00:00
</div>
</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' }}>
{usage ? (
constants.USAGE_INFO(
usage,
Math.ceil(
Number(
subscriptionService.convertBytesToGBs(
subscription?.storage
)
)
)
)
) : (
<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>
<h5
style={{ cursor: 'pointer', marginTop: '30px' }}
onClick={exportFiles}
>
{constants.EXPORT}
</h5>
2021-04-05 05:12:37 +00:00
<h5
style={{ cursor: 'pointer', marginTop: '30px' }}
onClick={() => router.push('changePassword')}
>
{constants.CHANGE_PASSWORD}
</h5>
2021-04-05 07:41:48 +00:00
<>
<RecoveryKeyModal
show={modalView}
onHide={() => setModalView(false)}
/>
<h5
style={{ cursor: 'pointer', marginTop: '30px' }}
onClick={() => setModalView(true)}
>
{constants.DOWNLOAD_RECOVERY_KEY}
</h5>
</>
<h5
style={{
cursor: 'pointer',
color: '#F96C6C',
marginTop: '30px',
}}
onClick={() => props.setConfirmAction(CONFIRM_ACTION.LOGOUT)}
>
logout
</h5>
</Menu>
);
}