From 4908bcc993e86ad0315933e7d233f6752e9b3076 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 19 Feb 2021 19:03:54 -0800 Subject: [PATCH] WIP: Implement rest fetch list. --- .../src/classes/client/rest-client/index.ts | 25 ++++++++++++++++++- .../action-dispatcher/share-dialog/index.tsx | 8 ++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/webapp/src/classes/client/rest-client/index.ts b/packages/webapp/src/classes/client/rest-client/index.ts index cd4d812d..8288e974 100644 --- a/packages/webapp/src/classes/client/rest-client/index.ts +++ b/packages/webapp/src/classes/client/rest-client/index.ts @@ -20,7 +20,30 @@ export default class RestClient implements Client { } fetchMapPermissions(id: number): Promise { - throw new Error('Method not implemented.' + id); + const handler = (success: (labels: Permission[]) => void, reject: (error: ErrorInfo) => void) => { + axios.get( + this.baseUrl + `/c/restful/maps/${id}/collabs`, + { + headers: { 'Content-Type': 'text/plain' } + } + ).then(response => { + const data = response.data; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const perms: Permission[] = (data.collaborations as any[]).map(p => { + return { + id: p.id, + email: p.email, + name: p.name, + role: p.role + } + }) + success(perms); + }).catch(error => { + const errorInfo = this.parseResponseOnError(error.response); + reject(errorInfo); + }); + } + return new Promise(handler); } deleteAccount(): Promise { diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx index 604620cf..169be7f4 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx @@ -100,6 +100,10 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement return client.fetchMapPermissions(mapId); }); + const formatName = (perm: Permission): string => { + return perm.name ? `${perm.name}<${perm.email}>` : perm.email; + } + return (
- + {showMessage && @@ -175,7 +179,7 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement {permissions && permissions.map((permission) => { return ( - `} /> + < ListItemSecondaryAction >