mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-10 17:33:24 +01:00
Complete duplicate action for rest.
This commit is contained in:
parent
86d78935f0
commit
0d7cf3e5b1
@ -19,7 +19,7 @@ export default class RestClient extends MockClient {
|
|||||||
const status: number = response.status;
|
const status: number = response.status;
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 401:
|
case 401:
|
||||||
// this.authFailed();
|
// this.authFailed();
|
||||||
@ -32,7 +32,7 @@ export default class RestClient extends MockClient {
|
|||||||
if (globalErrors && globalErrors.length > 0) {
|
if (globalErrors && globalErrors.length > 0) {
|
||||||
result.msg = globalErrors[0];
|
result.msg = globalErrors[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set field errors ...
|
// Set field errors ...
|
||||||
if (data.fieldErrors && Object.keys(data.fieldErrors).length > 0) {
|
if (data.fieldErrors && Object.keys(data.fieldErrors).length > 0) {
|
||||||
result.fields = data.fieldErrors;
|
result.fields = data.fieldErrors;
|
||||||
@ -41,23 +41,23 @@ export default class RestClient extends MockClient {
|
|||||||
result.msg = data.fieldErrors[key];
|
result.msg = data.fieldErrors[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = { msg: response.statusText };
|
result = { msg: response.statusText };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network related problem ...
|
// Network related problem ...
|
||||||
if (!result) {
|
if (!result) {
|
||||||
result = { msg: 'Unexpected error. Please, try latter' };
|
result = { msg: 'Unexpected error. Please, try latter' };
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
createMap(model: BasicMapInfo): Promise<number> {
|
createMap(model: BasicMapInfo): Promise<number> {
|
||||||
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 : ''}`,
|
axios.post(this.baseUrl + `/c/restful/maps?title=${model.title}&description=${model.description ? model.description : ''}`,
|
||||||
null,
|
null,
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
{ headers: { 'Content-Type': 'application/json' } }
|
||||||
@ -160,5 +160,23 @@ export default class RestClient extends MockClient {
|
|||||||
}
|
}
|
||||||
return new Promise(handler);
|
return new Promise(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duplicateMap(id: number, basicInfo: BasicMapInfo): Promise<number> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ const DuplicateDialog = (props: DialogProps) => {
|
|||||||
return service.duplicateMap(id, rest);
|
return service.duplicateMap(id, rest);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: (mapId) => {
|
||||||
handleOnMutationSuccess(props.onClose, queryClient);
|
window.location.href = `/c/maps/${mapId}/edit`;
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
setError(error);
|
setError(error);
|
||||||
|
Loading…
Reference in New Issue
Block a user