From ce05cc3d18590fa7d04fc0925649bea96300a190 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 6 Feb 2021 23:09:46 -0800 Subject: [PATCH] Implement revert --- .../webapp/src/client/rest-client/index.ts | 28 +++++++++++-------- .../action-dispatcher/info-dialog/index.tsx | 5 +--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/webapp/src/client/rest-client/index.ts b/packages/webapp/src/client/rest-client/index.ts index 31929869..32b117ea 100644 --- a/packages/webapp/src/client/rest-client/index.ts +++ b/packages/webapp/src/client/rest-client/index.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import { useIntl } from 'react-intl'; import Client, { ErrorInfo, MapInfo, BasicMapInfo, NewUser, Label, ChangeHistory } from '..'; export default class RestClient implements Client { @@ -42,17 +41,26 @@ export default class RestClient implements Client { } return new Promise(handler); } - revertHistory(id: number, cid: number): Promise { - // '/c/restful/maps/${mindmapId}/history' - throw new Error('Method not implemented.'); + revertHistory(id: number, hid: number): Promise { + const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { + axios.post(this.baseUrl + `/maps/${id}/history/${hid}`, + null, + { headers: { 'Content-Type': 'text/pain' } } + ).then(() => { + success(); + }).catch(error => { + const errorInfo = this.parseResponseOnError(error.response); + reject(errorInfo); + }); + } + return new Promise(handler); } fetchHistory(id: number): Promise { throw new Error('Method not implemented.'); } - renameMap(id: number, basicInfo: BasicMapInfo): Promise { throw "Method not implemented yet"; } @@ -66,8 +74,7 @@ export default class RestClient implements Client { const mapId = response.headers.resourceid; success(mapId); }).catch(error => { - const response = error.response; - const errorInfo = this.parseResponseOnError(response); + const errorInfo = this.parseResponseOnError(error.response); reject(errorInfo); }); } @@ -137,8 +144,7 @@ export default class RestClient implements Client { ).then(response => { success(); }).catch(error => { - const response = error.response; - const errorInfo = this.parseResponseOnError(response); + const errorInfo = this.parseResponseOnError(error.response); reject(errorInfo); }); } @@ -238,8 +244,6 @@ export default class RestClient implements Client { } private parseResponseOnError = (response: any): ErrorInfo => { - const intl = useIntl(); - let result: ErrorInfo | undefined; if (response) { const status: number = response.status; @@ -250,7 +254,7 @@ export default class RestClient implements Client { case 401: case 302: this.sessionExpired(); - result = { msg: intl.formatMessage({ id: "expired.description", defaultMessage: "Your current session has expired. Please, sign in and try again." }) } + result = { msg: "Your current session has expired. Please, sign in and try again." }; break; default: if (data) { diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/info-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/info-dialog/index.tsx index 3400c5ba..b3cb618c 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/info-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/info-dialog/index.tsx @@ -1,12 +1,9 @@ import React from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; -import { useQueryClient } from 'react-query'; -import { useSelector } from 'react-redux'; import { Card, List, ListItem, Paper, Typography } from '@material-ui/core'; -import Client, { ErrorInfo } from '../../../../client'; -import { activeInstance } from '../../../../redux/clientSlice'; +import { ErrorInfo } from '../../../../client'; import BaseDialog from '../base-dialog'; import { fetchMapById, SimpleDialogProps } from '..'; import { useStyles } from './style';