ente/src/components/Sidebar.tsx

164 lines
5.4 KiB
TypeScript
Raw Normal View History

import React, { useEffect, useState } from 'react';
import { slide as Menu } from 'react-burger-menu';
import ConfirmLogout, { 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 { logoutUser } from 'services/userService';
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 MessageDialog from './MessageDialog';
import isElectron from 'is-electron';
interface Props {
files: file[];
}
export default function Sidebar(props: Props) {
const [logoutModalView, setLogoutModalView] = useState(false);
function showLogoutModal() {
setLogoutModalView(true);
}
function closeLogoutModal() {
setLogoutModalView(false);
}
const [usage, SetUsage] = useState<string>(null);
const subscription: Subscription = getData(LS_KEYS.SUBSCRIPTION);
const [isOpen, setIsOpen] = useState(false);
2021-03-27 13:52:53 +00:00
const [messageModalView, setMessageModalView] = useState(false);
useEffect(() => {
const main = async () => {
if (!isOpen) {
return;
}
const usage = await subscriptionService.getUsage();
SetUsage(usage);
};
main();
}, [isOpen]);
const logout = async () => {
2021-03-12 04:50:58 +00:00
setLogoutModalView(false);
setIsOpen(false);
2021-03-12 04:50:58 +00:00
logoutUser();
};
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.selectDirectory();
} else {
setMessageModalView(true);
}
}
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>
2021-03-27 13:52:53 +00:00
<>
<MessageDialog
show={messageModalView}
onHide={() => setMessageModalView(false)}
message={constants.ELECTRON_APP_REQUIRED}
/>
<h5
style={{ cursor: 'pointer', marginTop: '30px' }}
2021-03-29 05:15:01 +00:00
onClick={exportFiles}
2021-03-27 13:52:53 +00:00
>
{constants.EXPORT}
</h5>
</>
<>
<ConfirmLogout
show={logoutModalView}
onHide={closeLogoutModal}
callback={logout}
action={CONFIRM_ACTION.LOGOUT}
/>
2021-03-16 04:40:27 +00:00
<h5
style={{
cursor: 'pointer',
color: '#F96C6C',
marginTop: '30px',
}}
onClick={showLogoutModal}
>
logout
2021-03-14 07:41:50 +00:00
</h5>
</>
</Menu>
);
}