diff --git a/packages/webapp/package.json b/packages/webapp/package.json
index dacadade..7166263a 100644
--- a/packages/webapp/package.json
+++ b/packages/webapp/package.json
@@ -47,6 +47,7 @@
"dependencies": {
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
+ "@material-ui/lab": "^4.0.0-alpha.57",
"@types/react-google-recaptcha": "^2.1.0",
"axios": "^0.21.0",
"react": "^17.0.1",
diff --git a/packages/webapp/src/components/maps-page/ActionDialog.tsx b/packages/webapp/src/components/maps-page/ActionDialog.tsx
index 599da245..b3b72f4c 100644
--- a/packages/webapp/src/components/maps-page/ActionDialog.tsx
+++ b/packages/webapp/src/components/maps-page/ActionDialog.tsx
@@ -6,8 +6,9 @@ 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, Service } from '../../services/Service';
+import { BasicMapInfo, ErrorInfo, Service } from '../../services/Service';
import { FormControl, TextField } from '@material-ui/core';
+import { Alert, AlertTitle } from '@material-ui/lab';
type DialogProps = {
open: boolean,
@@ -35,14 +36,17 @@ function DeleteConfirmDialog(props: DialogProps) {
-
+
+ Map to be deleted
+
+
-
@@ -52,9 +56,11 @@ function DeleteConfirmDialog(props: DialogProps) {
}
function RenameDialog(props: DialogProps) {
- const [model, setModel] = React.useState({ name: '', description: '' });
+ const defaultModel: BasicMapInfo = { name: '', description: '' };
+ const [model, setModel] = React.useState(defaultModel);
+ const [errorInfo, setErroInfo] = React.useState();
+
const intl = useIntl();
- const [nameErrorMsg, setNameErrorMsg] = React.useState(undefined);
useEffect(() => {
props.service.loadMapInfo(props.mapId)
@@ -64,6 +70,10 @@ function RenameDialog(props: DialogProps) {
}, []);
const handleOnClose = (): void => {
+ // Clean Up ...
+ setModel(defaultModel);
+ setErroInfo(undefined);
+
props.onClose(false);
};
@@ -73,12 +83,11 @@ function RenameDialog(props: DialogProps) {
// Fire rest call ...
const mapId = props.mapId;
- props.service.remameMap(mapId, model).
- then(e => {
- // Close the dialog ...
+ props.service.renameMap(mapId, model).
+ then(() => {
props.onClose(true);
- }).catch(e => {
- setNameErrorMsg("Error ....")
+ }).catch((errorInfo: ErrorInfo) => {
+ setErroInfo(errorInfo)
});
};
@@ -103,24 +112,27 @@ function RenameDialog(props: DialogProps) {
-
+
+ {Boolean(errorInfo?.msg) ? {errorInfo?.msg} : null}
-
+
-
+
-
-
-
+
+
-
+
diff --git a/packages/webapp/src/services/Service.ts b/packages/webapp/src/services/Service.ts
index f0d9432d..fa9d9d20 100644
--- a/packages/webapp/src/services/Service.ts
+++ b/packages/webapp/src/services/Service.ts
@@ -29,7 +29,7 @@ export type FieldError = {
export type ErrorInfo = {
msg?: string;
- fields?: FieldError[];
+ fields?: Map;
}
interface Service {
@@ -38,7 +38,7 @@ interface Service {
fetchAllMaps(): Promise;
deleteMap(id: number): Promise;
- remameMap(id: number, basicInfo: BasicMapInfo): Promise;
+ renameMap(id: number, basicInfo: BasicMapInfo): Promise;
loadMapInfo(id: number): Promise;
}
@@ -51,11 +51,17 @@ class RestService implements Service {
}
loadMapInfo(id: number): Promise {
- return Promise.resolve({ name: 'My Map', description: 'My Descition' });
+ return Promise.resolve({ name: 'My Map', description: 'My Description' });
}
- async remameMap(id: number, basicInfo: BasicMapInfo) {
- return Promise.resolve();
+ renameMap(id: number, basicInfo: BasicMapInfo): Promise {
+ const fieldErrors: Map = new Map();
+ fieldErrors.set('name', 'name already exists ')
+
+ return Promise.reject({
+ msg: 'Map already exists ...' + basicInfo.name,
+ fields: fieldErrors
+ });
}
async deleteMap(id: number): Promise {
@@ -95,7 +101,6 @@ class RestService implements Service {
createMapInfo(1, true, "El Mapa", [""], "Paulo", 67,),
createMapInfo(2, false, "El Mapa2", [""], "Paulo2", 67),
createMapInfo(3, false, "El Mapa3", [""], "Paulo3", 67)
-
];
return Promise.resolve(maps);
@@ -148,6 +153,7 @@ class RestService implements Service {
if (data.fieldErrors) {
// @Todo: Fix this ...
result = { msg: data.fieldErrors };
+ result.fields = new Map();
}
} else {
diff --git a/yarn.lock b/yarn.lock
index ff039cc4..60bb06f1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1764,6 +1764,17 @@
dependencies:
"@babel/runtime" "^7.4.4"
+"@material-ui/lab@^4.0.0-alpha.57":
+ version "4.0.0-alpha.57"
+ resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-4.0.0-alpha.57.tgz#e8961bcf6449e8a8dabe84f2700daacfcafbf83a"
+ integrity sha512-qo/IuIQOmEKtzmRD2E4Aa6DB4A87kmY6h0uYhjUmrrgmEAgbbw9etXpWPVXuRK6AGIQCjFzV6WO2i21m1R4FCw==
+ dependencies:
+ "@babel/runtime" "^7.4.4"
+ "@material-ui/utils" "^4.11.2"
+ clsx "^1.0.4"
+ prop-types "^15.7.2"
+ react-is "^16.8.0 || ^17.0.0"
+
"@material-ui/styles@^4.11.2":
version "4.11.2"
resolved "https://registry.yarnpkg.com/@material-ui/styles/-/styles-4.11.2.tgz#e70558be3f41719e8c0d63c7a3c9ae163fdc84cb"