diff --git a/packages/webapp/src/client/rest-client/index.ts b/packages/webapp/src/client/rest-client/index.ts index eab70a92..4cdaf034 100644 --- a/packages/webapp/src/client/rest-client/index.ts +++ b/packages/webapp/src/client/rest-client/index.ts @@ -19,7 +19,7 @@ export default class RestClient extends MockClient { const status: number = response.status; const data = response.data; console.log(data); - + switch (status) { case 401: // this.authFailed(); @@ -32,7 +32,7 @@ export default class RestClient extends MockClient { if (globalErrors && globalErrors.length > 0) { result.msg = globalErrors[0]; } - + // Set field errors ... if (data.fieldErrors && Object.keys(data.fieldErrors).length > 0) { result.fields = data.fieldErrors; @@ -41,23 +41,23 @@ export default class RestClient extends MockClient { result.msg = data.fieldErrors[key]; } } - + } else { result = { msg: response.statusText }; } } } - + // Network related problem ... if (!result) { result = { msg: 'Unexpected error. Please, try latter' }; } - + return result; } - + createMap(model: BasicMapInfo): Promise { - const handler = (success: (mapId:number) => void, reject: (error: ErrorInfo) => void) => { + const handler = (success: (mapId: number) => void, reject: (error: ErrorInfo) => void) => { axios.post(this.baseUrl + `/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`, null, { headers: { 'Content-Type': 'application/json' } } @@ -160,5 +160,23 @@ export default class RestClient extends MockClient { } return new Promise(handler); } + + duplicateMap(id: number, basicInfo: BasicMapInfo): Promise { + + const handler = (success: (mapId: number) => void, reject: (error: ErrorInfo) => void) => { + axios.post(this.baseUrl + `/c/restful/maps/${id}`, + JSON.stringify(basicInfo), + { headers: { 'Content-Type': 'application/json' } } + ).then(response => { + const mapId = response.headers.resourceid; + success(mapId); + }).catch(error => { + const response = error.response; + const errorInfo = this.parseResponseOnError(response); + reject(errorInfo); + }); + } + return new Promise(handler); + } } diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/duplicate/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/duplicate/index.tsx index 06cbda3b..4e51d059 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/duplicate/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/duplicate/index.tsx @@ -31,8 +31,8 @@ const DuplicateDialog = (props: DialogProps) => { return service.duplicateMap(id, rest); }, { - onSuccess: () => { - handleOnMutationSuccess(props.onClose, queryClient); + onSuccess: (mapId) => { + window.location.href = `/c/maps/${mapId}/edit`; }, onError: (error) => { setError(error);