From b25bc9b56a2e4b1df0b039f1bc5bc4dead5335b1 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 7 Jun 2020 14:21:17 +0800 Subject: feat(front): Fix #74 . --- Timeline/ClientApp/src/settings/Settings.tsx | 76 +++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 12 deletions(-) (limited to 'Timeline/ClientApp/src/settings') 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 = (props) => { ); }; +const ConfirmLogoutDialog: React.FC<{ + toggle: () => void; + onConfirm: () => void; +}> = ({ toggle, onConfirm }) => { + const { t } = useTranslation(); + + return ( + + + {t('settings.dialogConfirmLogout.title')} + + {t('settings.dialogConfirmLogout.prompt')} + + + + + + ); +}; + const Settings: React.FC = (_) => { const { i18n, t } = useTranslation(); const user = useUser(); const history = useHistory(); - const [dialog, setDialog] = useState(null); + const [dialog, setDialog] = useState( + null + ); const language = i18n.language.slice(0, 2); @@ -157,8 +193,7 @@ const Settings: React.FC = (_) => {
{ - userLogout(); - history.push('/'); + setDialog('logout'); }} > {t('settings.logout')} @@ -185,14 +220,31 @@ const Settings: React.FC = (_) => { - {dialog === 'changepassword' ? ( - { - setDialog(null); - }} - /> - ) : null} + {(() => { + switch (dialog) { + case 'changepassword': + return ( + { + setDialog(null); + }} + /> + ); + case 'logout': + return ( + setDialog(null)} + onConfirm={() => { + userLogout(); + history.push('/'); + }} + /> + ); + default: + return null; + } + })()} ); -- cgit v1.2.3