WIP: Implement rest fetch list.

This commit is contained in:
Paulo Gustavo Veiga 2021-02-19 19:03:54 -08:00
parent 7a18f19203
commit 95379f7b4f
2 changed files with 30 additions and 3 deletions

View File

@ -20,7 +20,30 @@ export default class RestClient implements Client {
} }
fetchMapPermissions(id: number): Promise<Permission[]> { fetchMapPermissions(id: number): Promise<Permission[]> {
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<void> { deleteAccount(): Promise<void> {

View File

@ -100,6 +100,10 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement
return client.fetchMapPermissions(mapId); return client.fetchMapPermissions(mapId);
}); });
const formatName = (perm: Permission): string => {
return perm.name ? `${perm.name}<${perm.email}>` : perm.email;
}
return ( return (
<div> <div>
<BaseDialog <BaseDialog
@ -151,7 +155,7 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement
variant="contained" variant="contained"
disableElevation={true} disableElevation={true}
onClick={handleOnAddClick}> onClick={handleOnAddClick}>
<FormattedMessage id="share.add-button" defaultMessage="Add " /> <FormattedMessage id="share.add-button" defaultMessage="Add" />
</Button> </Button>
{showMessage && {showMessage &&
@ -175,7 +179,7 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement
{permissions && permissions.map((permission) => { {permissions && permissions.map((permission) => {
return ( return (
<ListItem key={permission.email} role={undefined} dense button> <ListItem key={permission.email} role={undefined} dense button>
<ListItemText id={permission.email} primary={`${permission.name}<${permission.email}>`} /> <ListItemText id={permission.email} primary={formatName(permission)} />
<RoleIcon role={permission.role} /> <RoleIcon role={permission.role} />
< ListItemSecondaryAction > < ListItemSecondaryAction >