aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/settings/Settings.tsx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-06-07 14:21:17 +0800
committercrupest <crupest@outlook.com>2020-06-07 14:21:17 +0800
commitb25bc9b56a2e4b1df0b039f1bc5bc4dead5335b1 (patch)
tree011606b690b9c15b7d71c556166baac5c847c242 /Timeline/ClientApp/src/settings/Settings.tsx
parentab9fc5fad1fc0971d1dfab7944b983df59e3389a (diff)
downloadtimeline-b25bc9b56a2e4b1df0b039f1bc5bc4dead5335b1.tar.gz
timeline-b25bc9b56a2e4b1df0b039f1bc5bc4dead5335b1.tar.bz2
timeline-b25bc9b56a2e4b1df0b039f1bc5bc4dead5335b1.zip
feat(front): Fix #74 .
Diffstat (limited to 'Timeline/ClientApp/src/settings/Settings.tsx')
-rw-r--r--Timeline/ClientApp/src/settings/Settings.tsx76
1 files changed, 64 insertions, 12 deletions
diff --git a/Timeline/ClientApp/src/settings/Settings.tsx b/Timeline/ClientApp/src/settings/Settings.tsx
index cd4db9c9..bf7ee4ef 100644
--- a/Timeline/ClientApp/src/settings/Settings.tsx
+++ b/Timeline/ClientApp/src/settings/Settings.tsx
@@ -2,7 +2,17 @@ import React, { useState } from 'react';
import { useHistory } from 'react-router';
import { useTranslation } from 'react-i18next';
import axios, { AxiosError } from 'axios';
-import { Container, Row, Col, Input } from 'reactstrap';
+import {
+ Container,
+ Row,
+ Col,
+ Input,
+ Modal,
+ ModalHeader,
+ ModalBody,
+ ModalFooter,
+ Button,
+} from 'reactstrap';
import { apiBaseUrl } from '../config';
@@ -116,12 +126,38 @@ const ChangePasswordDialog: React.FC<ChangePasswordDialogProps> = (props) => {
);
};
+const ConfirmLogoutDialog: React.FC<{
+ toggle: () => void;
+ onConfirm: () => void;
+}> = ({ toggle, onConfirm }) => {
+ const { t } = useTranslation();
+
+ return (
+ <Modal isOpen centered>
+ <ModalHeader className="text-danger">
+ {t('settings.dialogConfirmLogout.title')}
+ </ModalHeader>
+ <ModalBody>{t('settings.dialogConfirmLogout.prompt')}</ModalBody>
+ <ModalFooter>
+ <Button color="secondary" onClick={toggle}>
+ {t('operationDialog.cancel')}
+ </Button>
+ <Button color="danger" onClick={onConfirm}>
+ {t('operationDialog.confirm')}
+ </Button>
+ </ModalFooter>
+ </Modal>
+ );
+};
+
const Settings: React.FC = (_) => {
const { i18n, t } = useTranslation();
const user = useUser();
const history = useHistory();
- const [dialog, setDialog] = useState<null | 'changepassword'>(null);
+ const [dialog, setDialog] = useState<null | 'changepassword' | 'logout'>(
+ null
+ );
const language = i18n.language.slice(0, 2);
@@ -157,8 +193,7 @@ const Settings: React.FC = (_) => {
<h5
className="text-danger"
onClick={() => {
- userLogout();
- history.push('/');
+ setDialog('logout');
}}
>
{t('settings.logout')}
@@ -185,14 +220,31 @@ const Settings: React.FC = (_) => {
</Input>
</Col>
</Row>
- {dialog === 'changepassword' ? (
- <ChangePasswordDialog
- open
- close={() => {
- setDialog(null);
- }}
- />
- ) : null}
+ {(() => {
+ switch (dialog) {
+ case 'changepassword':
+ return (
+ <ChangePasswordDialog
+ open
+ close={() => {
+ setDialog(null);
+ }}
+ />
+ );
+ case 'logout':
+ return (
+ <ConfirmLogoutDialog
+ toggle={() => setDialog(null)}
+ onConfirm={() => {
+ userLogout();
+ history.push('/');
+ }}
+ />
+ );
+ default:
+ return null;
+ }
+ })()}
</Container>
</>
);