Implement revert

This commit is contained in:
Paulo Gustavo Veiga 2021-02-06 23:09:46 -08:00
parent 7df6f3744b
commit ce05cc3d18
2 changed files with 17 additions and 16 deletions

View File

@ -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<void> {
// '/c/restful/maps/${mindmapId}/history'
throw new Error('Method not implemented.');
revertHistory(id: number, hid: number): Promise<void> {
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<ChangeHistory[]> {
throw new Error('Method not implemented.');
}
renameMap(id: number, basicInfo: BasicMapInfo): Promise<void> {
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) {

View File

@ -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';