From 0b3feef47a70e793bc94e817a322abad3a988bcb Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 31 May 2018 12:52:03 -0700 Subject: [PATCH] Hide settings items for non admins Update image uploader for use with team logo Fix can't cancel cropping modal --- app/components/Sidebar/Settings.js | 26 +++++----- app/scenes/Settings/Details.js | 2 + app/scenes/Settings/components/ImageUpload.js | 47 ++++++++++++------- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/app/components/Sidebar/Settings.js b/app/components/Sidebar/Settings.js index 1ba89eae..20d4aed1 100644 --- a/app/components/Sidebar/Settings.js +++ b/app/components/Sidebar/Settings.js @@ -29,8 +29,8 @@ class SettingsSidebar extends React.Component { }; render() { - const { team } = this.props.auth; - if (!team) return; + const { team, user } = this.props.auth; + if (!team || !user) return; return ( @@ -54,21 +54,25 @@ class SettingsSidebar extends React.Component {
Team
- }> - Details - + {user.isAdmin && ( + }> + Details + + )} }> Members }> Share Links - } - > - Integrations - + {user.isAdmin && ( + } + > + Integrations + + )}
diff --git a/app/scenes/Settings/Details.js b/app/scenes/Settings/Details.js index 4aa0b283..48bb52f1 100644 --- a/app/scenes/Settings/Details.js +++ b/app/scenes/Settings/Details.js @@ -78,6 +78,8 @@ class Details extends React.Component { diff --git a/app/scenes/Settings/components/ImageUpload.js b/app/scenes/Settings/components/ImageUpload.js index b3ca7a81..6c452271 100644 --- a/app/scenes/Settings/components/ImageUpload.js +++ b/app/scenes/Settings/components/ImageUpload.js @@ -16,6 +16,8 @@ type Props = { children?: React.Node, onSuccess: string => *, onError: string => *, + submitText: string, + borderRadius: number, }; @observer @@ -26,6 +28,11 @@ class DropToImport extends React.Component { file: File; avatarEditorRef: AvatarEditor; + static defaultProps = { + submitText: 'Crop Picture', + borderRadius: 150, + }; + onDropAccepted = async (files: File[]) => { this.isCropping = true; this.file = files[0]; @@ -38,13 +45,18 @@ class DropToImport extends React.Component { const asset = await uploadFile(imageBlob, { name: this.file.name }); this.props.onSuccess(asset.url); } catch (err) { - this.props.onError('Unable to upload image'); + this.props.onError(err); } finally { this.isUploading = false; this.isCropping = false; } }; + handleClose = () => { + this.isUploading = false; + this.isCropping = false; + }; + handleZoom = (event: SyntheticDragEvent<*>) => { let target = event.target; if (target instanceof HTMLInputElement) { @@ -53,8 +65,10 @@ class DropToImport extends React.Component { }; renderCropping() { + const { submitText } = this.props; + return ( - + { width={250} height={250} border={25} - borderRadius={150} + borderRadius={this.props.borderRadius} color={[255, 255, 255, 0.6]} // RGBA scale={this.zoom} rotate={0} @@ -79,7 +93,7 @@ class DropToImport extends React.Component { /> {this.isUploading && } - Crop avatar + {submitText} @@ -89,19 +103,20 @@ class DropToImport extends React.Component { render() { if (this.isCropping) { return this.renderCropping(); - } else { - return ( - - {this.props.children} - - ); } + + return ( + + {this.props.children} + + ); } }