Hide settings items for non admins

Update image uploader for use with team logo
Fix can't cancel cropping modal
This commit is contained in:
Tom Moor
2018-05-31 12:52:03 -07:00
parent 10a0ffe472
commit 0b3feef47a
3 changed files with 48 additions and 27 deletions

View File

@ -29,8 +29,8 @@ class SettingsSidebar extends React.Component<Props> {
}; };
render() { render() {
const { team } = this.props.auth; const { team, user } = this.props.auth;
if (!team) return; if (!team || !user) return;
return ( return (
<Sidebar> <Sidebar>
@ -54,21 +54,25 @@ class SettingsSidebar extends React.Component<Props> {
</Section> </Section>
<Section> <Section>
<Header>Team</Header> <Header>Team</Header>
<SidebarLink to="/settings/details" icon={<SettingsIcon />}> {user.isAdmin && (
Details <SidebarLink to="/settings/details" icon={<SettingsIcon />}>
</SidebarLink> Details
</SidebarLink>
)}
<SidebarLink to="/settings/members" icon={<UserIcon />}> <SidebarLink to="/settings/members" icon={<UserIcon />}>
Members Members
</SidebarLink> </SidebarLink>
<SidebarLink to="/settings/shares" icon={<LinkIcon />}> <SidebarLink to="/settings/shares" icon={<LinkIcon />}>
Share Links Share Links
</SidebarLink> </SidebarLink>
<SidebarLink {user.isAdmin && (
to="/settings/integrations/slack" <SidebarLink
icon={<SettingsIcon />} to="/settings/integrations/slack"
> icon={<SettingsIcon />}
Integrations >
</SidebarLink> Integrations
</SidebarLink>
)}
</Section> </Section>
</Scrollable> </Scrollable>
</Flex> </Flex>

View File

@ -78,6 +78,8 @@ class Details extends React.Component<Props> {
<ImageUpload <ImageUpload
onSuccess={this.handleAvatarUpload} onSuccess={this.handleAvatarUpload}
onError={this.handleAvatarError} onError={this.handleAvatarError}
submitText="Crop logo"
borderRadius={0}
> >
<Avatar src={avatarUrl} /> <Avatar src={avatarUrl} />
<Flex auto align="center" justify="center"> <Flex auto align="center" justify="center">

View File

@ -16,6 +16,8 @@ type Props = {
children?: React.Node, children?: React.Node,
onSuccess: string => *, onSuccess: string => *,
onError: string => *, onError: string => *,
submitText: string,
borderRadius: number,
}; };
@observer @observer
@ -26,6 +28,11 @@ class DropToImport extends React.Component<Props> {
file: File; file: File;
avatarEditorRef: AvatarEditor; avatarEditorRef: AvatarEditor;
static defaultProps = {
submitText: 'Crop Picture',
borderRadius: 150,
};
onDropAccepted = async (files: File[]) => { onDropAccepted = async (files: File[]) => {
this.isCropping = true; this.isCropping = true;
this.file = files[0]; this.file = files[0];
@ -38,13 +45,18 @@ class DropToImport extends React.Component<Props> {
const asset = await uploadFile(imageBlob, { name: this.file.name }); const asset = await uploadFile(imageBlob, { name: this.file.name });
this.props.onSuccess(asset.url); this.props.onSuccess(asset.url);
} catch (err) { } catch (err) {
this.props.onError('Unable to upload image'); this.props.onError(err);
} finally { } finally {
this.isUploading = false; this.isUploading = false;
this.isCropping = false; this.isCropping = false;
} }
}; };
handleClose = () => {
this.isUploading = false;
this.isCropping = false;
};
handleZoom = (event: SyntheticDragEvent<*>) => { handleZoom = (event: SyntheticDragEvent<*>) => {
let target = event.target; let target = event.target;
if (target instanceof HTMLInputElement) { if (target instanceof HTMLInputElement) {
@ -53,8 +65,10 @@ class DropToImport extends React.Component<Props> {
}; };
renderCropping() { renderCropping() {
const { submitText } = this.props;
return ( return (
<Modal isOpen title=""> <Modal isOpen onRequestClose={this.handleClose} title="">
<Flex auto column align="center" justify="center"> <Flex auto column align="center" justify="center">
<AvatarEditorContainer> <AvatarEditorContainer>
<AvatarEditor <AvatarEditor
@ -63,7 +77,7 @@ class DropToImport extends React.Component<Props> {
width={250} width={250}
height={250} height={250}
border={25} border={25}
borderRadius={150} borderRadius={this.props.borderRadius}
color={[255, 255, 255, 0.6]} // RGBA color={[255, 255, 255, 0.6]} // RGBA
scale={this.zoom} scale={this.zoom}
rotate={0} rotate={0}
@ -79,7 +93,7 @@ class DropToImport extends React.Component<Props> {
/> />
{this.isUploading && <LoadingIndicator />} {this.isUploading && <LoadingIndicator />}
<CropButton onClick={this.handleCrop} disabled={this.isUploading}> <CropButton onClick={this.handleCrop} disabled={this.isUploading}>
Crop avatar {submitText}
</CropButton> </CropButton>
</Flex> </Flex>
</Modal> </Modal>
@ -89,19 +103,20 @@ class DropToImport extends React.Component<Props> {
render() { render() {
if (this.isCropping) { if (this.isCropping) {
return this.renderCropping(); return this.renderCropping();
} else {
return (
<Dropzone
accept="image/png, image/jpeg"
onDropAccepted={this.onDropAccepted}
style={{}}
disablePreview
{...this.props}
>
{this.props.children}
</Dropzone>
);
} }
return (
<Dropzone
accept="image/png, image/jpeg"
onDropAccepted={this.onDropAccepted}
style={{}}
disablePreview
onSuccess={this.props.onSuccess}
onError={this.props.onError}
>
{this.props.children}
</Dropzone>
);
} }
} }