From 60fd57b0944ffc4cf0ab4d6faa8b060c8527122e Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 24 Dec 2020 17:39:06 -0800 Subject: [PATCH] Redux initial refactor --- packages/webapp/lang/en.json | 55 ++++++++- packages/webapp/package.json | 6 +- packages/webapp/src/app.tsx | 60 ++++----- packages/webapp/src/compiled-lang/en.json | 106 +++++++++++++++- .../components/forgot-password-page/index.tsx | 26 ++-- .../src/components/maps-page/ActionDialog.tsx | 115 +++++++++++------- .../webapp/src/components/maps-page/index.tsx | 38 ++---- .../components/registration-page/index.tsx | 27 ++-- packages/webapp/src/index.tsx | 34 +----- packages/webapp/src/reducers/mapsListSlice.ts | 113 +++++++++++++++++ packages/webapp/src/services/Service.ts | 14 ++- packages/webapp/src/store.ts | 12 ++ 12 files changed, 436 insertions(+), 170 deletions(-) create mode 100644 packages/webapp/src/reducers/mapsListSlice.ts create mode 100644 packages/webapp/src/store.ts diff --git a/packages/webapp/lang/en.json b/packages/webapp/lang/en.json index e37a1dd7..1e276f4b 100644 --- a/packages/webapp/lang/en.json +++ b/packages/webapp/lang/en.json @@ -1,4 +1,55 @@ { + "action.cancel-button": { + "defaultMessage": "Cancel" + }, + "action.delete": { + "defaultMessage": "Delete" + }, + "action.delete-button": { + "defaultMessage": "Delete" + }, + "action.delete-description": { + "defaultMessage": "Deleted mindmap can not be recovered. Do you want to continue ?." + }, + "action.delete-title": { + "defaultMessage": "Delete" + }, + "action.duplicate": { + "defaultMessage": "Duplicate" + }, + "action.export": { + "defaultMessage": "Export" + }, + "action.open": { + "defaultMessage": "Open" + }, + "action.print": { + "defaultMessage": "Print" + }, + "action.publish": { + "defaultMessage": "Publish" + }, + "action.rename": { + "defaultMessage": "Rename" + }, + "action.rename-button": { + "defaultMessage": "Rename" + }, + "action.rename-description": { + "defaultMessage": "Please, update the name and description for your mindmap." + }, + "action.rename-description-placeholder": { + "defaultMessage": "Description" + }, + "action.rename-name-placeholder": { + "defaultMessage": "Name" + }, + "action.rename-title": { + "defaultMessage": "Rename" + }, + "action.share": { + "defaultMessage": "Info" + }, "common.wait": { "defaultMessage": "Please wait ..." }, @@ -57,7 +108,7 @@ "defaultMessage": "Email" }, "login.error": { - "defaultMessage": "The login.email address or login.password you entered is not valid." + "defaultMessage": "The email address or password you entered is not valid." }, "login.forgotpwd": { "defaultMessage": "Forgot Password ?" @@ -82,7 +133,7 @@ "defaultMessage": "Welcome" }, "login.userinactive": { - "defaultMessage": "Sorry, your account has not been activated yet. You'll receive a notification login.email when it becomes active. Stay tuned!." + "defaultMessage": "Sorry, your account has not been activated yet. You'll receive a notification email when it becomes active. Stay tuned!." }, "registration.desc": { "defaultMessage": "Signing up is free and just take a moment" diff --git a/packages/webapp/package.json b/packages/webapp/package.json index 7166263a..7833a9c1 100644 --- a/packages/webapp/package.json +++ b/packages/webapp/package.json @@ -48,13 +48,15 @@ "@material-ui/core": "^4.11.2", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.57", + "@reduxjs/toolkit": "^1.5.0", + "@types/axios": "^0.14.0", "@types/react-google-recaptcha": "^2.1.0", - "axios": "^0.21.0", "react": "^17.0.1", "react-dom": "^17.0.1", "react-google-recaptcha": "^2.1.0", "react-intl": "^5.10.6", + "react-redux": "^7.2.2", "react-router-dom": "^5.2.0", "styled-components": "^5.2.1" } -} +} \ No newline at end of file diff --git a/packages/webapp/src/app.tsx b/packages/webapp/src/app.tsx index e057869f..5f0706ad 100644 --- a/packages/webapp/src/app.tsx +++ b/packages/webapp/src/app.tsx @@ -1,5 +1,4 @@ import React, { useEffect, useState } from 'react'; -import { Service, RestService } from './services/Service'; import { IntlProvider } from 'react-intl' import { GlobalStyle } from './theme/global-style'; @@ -7,7 +6,8 @@ import RegistrationSuccessPage from './components/registration-success-page'; import ForgotPasswordSuccessPage from './components/forgot-password-success-page'; import RegistationPage from './components/registration-page'; import LoginPage from './components/login-page'; -import MapsPage from './components/maps-page'; +import MapsPage from './components/maps-page'; +import store from "./store" import { Route, @@ -17,6 +17,7 @@ import { } from 'react-router-dom'; import { ForgotPasswordPage } from './components/forgot-password-page'; +import { Provider } from 'react-redux'; function loadLocaleData(language: string) { switch (language) { @@ -25,13 +26,13 @@ function loadLocaleData(language: string) { default: return require('./compiled-lang/en.json') } -} +} type AppProps = { baseRestUrl: string; } -const App = (props: AppProps) => { +const App = () => { const [messages, setMessages] = useState(undefined); // Boostrap i18n ... @@ -50,33 +51,32 @@ const App = (props: AppProps) => { fetchData(); }, []); - // Create Service object... - - const service: Service = new RestService(props.baseRestUrl, () => { console.log("401 error") }); - return messages ? ( - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + ) :
Loading ...
} diff --git a/packages/webapp/src/compiled-lang/en.json b/packages/webapp/src/compiled-lang/en.json index d51b6384..0cec10e1 100644 --- a/packages/webapp/src/compiled-lang/en.json +++ b/packages/webapp/src/compiled-lang/en.json @@ -1,4 +1,106 @@ { + "action.cancel-button": [ + { + "type": 0, + "value": "Cancel" + } + ], + "action.delete": [ + { + "type": 0, + "value": "Delete" + } + ], + "action.delete-button": [ + { + "type": 0, + "value": "Delete" + } + ], + "action.delete-description": [ + { + "type": 0, + "value": "Deleted mindmap can not be recovered. Do you want to continue ?." + } + ], + "action.delete-title": [ + { + "type": 0, + "value": "Delete" + } + ], + "action.duplicate": [ + { + "type": 0, + "value": "Duplicate" + } + ], + "action.export": [ + { + "type": 0, + "value": "Export" + } + ], + "action.open": [ + { + "type": 0, + "value": "Open" + } + ], + "action.print": [ + { + "type": 0, + "value": "Print" + } + ], + "action.publish": [ + { + "type": 0, + "value": "Publish" + } + ], + "action.rename": [ + { + "type": 0, + "value": "Rename" + } + ], + "action.rename-button": [ + { + "type": 0, + "value": "Rename" + } + ], + "action.rename-description": [ + { + "type": 0, + "value": "Please, update the name and description for your mindmap." + } + ], + "action.rename-description-placeholder": [ + { + "type": 0, + "value": "Description" + } + ], + "action.rename-name-placeholder": [ + { + "type": 0, + "value": "Name" + } + ], + "action.rename-title": [ + { + "type": 0, + "value": "Rename" + } + ], + "action.share": [ + { + "type": 0, + "value": "Info" + } + ], "common.wait": [ { "type": 0, @@ -116,7 +218,7 @@ "login.error": [ { "type": 0, - "value": "The login.email address or login.password you entered is not valid." + "value": "The email address or password you entered is not valid." } ], "login.forgotpwd": [ @@ -164,7 +266,7 @@ "login.userinactive": [ { "type": 0, - "value": "Sorry, your account has not been activated yet. You'll receive a notification login.email when it becomes active. Stay tuned!." + "value": "Sorry, your account has not been activated yet. You'll receive a notification email when it becomes active. Stay tuned!." } ], "registration.desc": [ diff --git a/packages/webapp/src/components/forgot-password-page/index.tsx b/packages/webapp/src/components/forgot-password-page/index.tsx index ddb6372c..112dc081 100644 --- a/packages/webapp/src/components/forgot-password-page/index.tsx +++ b/packages/webapp/src/components/forgot-password-page/index.tsx @@ -13,7 +13,7 @@ type ForgotPasswordProps = { email: string; } -const ForgotPassword = (props: ServiceProps) => { +const ForgotPassword = () => { const [email, setEmail] = useState(''); const [errorMsg, setErrorMsg] = useState(''); const [disableButton, setDisableButton] = useState(false); @@ -26,20 +26,20 @@ const ForgotPassword = (props: ServiceProps) => { setDisableButton(true); // Call Service ... - const service = props.service; - service.resetPassword(email) - .then(() => { - history.push("/c/forgot-password-success"); - }).catch((error: ErrorInfo) => { - setErrorMsg(error.msg ? error.msg : ''); - setDisableButton(false); - }); + // const service = props.service; + // service.resetPassword(email) + // .then(() => { + // history.push("/c/forgot-password-success"); + // }).catch((error: ErrorInfo) => { + // setErrorMsg(error.msg ? error.msg : ''); + // setDisableButton(false); + // }); } return ( -

-

+

+

setEmail(e.target.value)} placeholder={intl.formatMessage({ id: "forgot.email", defaultMessage: "Email" })} required={true} autoComplete="email" /> @@ -55,7 +55,7 @@ const ForgotPassword = (props: ServiceProps) => { type ServiceProps = { service: Service } -const ForgotPasswordPage = (props: ServiceProps) => { +const ForgotPasswordPage = () => { useEffect(() => { document.title = 'Reset Password | WiseMapping'; @@ -64,7 +64,7 @@ const ForgotPasswordPage = (props: ServiceProps) => { return (
- +
); diff --git a/packages/webapp/src/components/maps-page/ActionDialog.tsx b/packages/webapp/src/components/maps-page/ActionDialog.tsx index b3b72f4c..986a7cfd 100644 --- a/packages/webapp/src/components/maps-page/ActionDialog.tsx +++ b/packages/webapp/src/components/maps-page/ActionDialog.tsx @@ -6,26 +6,41 @@ import DialogContent from '@material-ui/core/DialogContent'; import DialogContentText from '@material-ui/core/DialogContentText'; import DialogTitle from '@material-ui/core/DialogTitle'; import { FormattedMessage, useIntl } from 'react-intl'; -import { BasicMapInfo, ErrorInfo, Service } from '../../services/Service'; +import { ErrorInfo, MapInfo, Service } from '../../services/Service'; import { FormControl, TextField } from '@material-ui/core'; import { Alert, AlertTitle } from '@material-ui/lab'; +import { useDispatch, useSelector } from 'react-redux'; +import { + allMaps, + remove, + rename +} from '../../reducers/mapsListSlice' +import { Description } from '@material-ui/icons'; + type DialogProps = { open: boolean, mapId: number, - onClose: (reload: boolean) => void, - service: Service + onClose: () => void } -function DeleteConfirmDialog(props: DialogProps) { +export type BasicMapInfo = { + name: string; + description: string | undefined; +} + +function DeleteDialog(props: DialogProps) { + const dispatch = useDispatch() + const mapId = props.mapId; + + const mapInfo: MapInfo | undefined = useSelector(allMaps). + find(m => m.id == mapId); const handleOnClose = (action: 'accept' | undefined): void => { - let result = false; - if (action == 'accept') { - props.service.deleteMap(props.mapId); - result = true; + if (action == 'accept' && mapInfo) { + dispatch(remove({ id: mapId })) } - props.onClose(result); + props.onClose(); }; return ( @@ -35,12 +50,10 @@ function DeleteConfirmDialog(props: DialogProps) { onClose={() => handleOnClose(undefined)} > - - - Map to be deleted - - - + + Delete '{mapInfo?.name}' + +