mattermost-mobile/app/components/profile_picture_button.js
Miguel Alatzar 2d81b497cf [MM-23520] Port mattermost-redux (#4088)
* Remove mattermost-redux

* Move mm-redux files into app/redux

* Add @redux path to tsconfig.json

* Fix imports

* Install missing dependencies

* Fix tsc errors

* Fix i18n_utils test

* Fix more imports

* Remove redux websocket

* Fix tests

* Rename @redux

* Apply changes from mattermost-redux PR 1103

* Remove mattermost-redux mention in template

* Add missing imports

* Rename app/redux/ to app/mm-redux/

* Remove test file

* Fix fetching Sidebar GM profiles

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-17 21:12:09 -07:00

80 lines
2.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Client4} from '@mm-redux/client';
import {t} from 'app/utils/i18n';
import AttachmentButton from 'app/components/attachment_button';
export default class ProfilePictureButton extends PureComponent {
static propTypes = {
currentUser: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
removeProfileImage: PropTypes.func,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
};
constructor(props) {
super(props);
this.state = {
extraOptions: [this.getRemoveProfileImageOption()],
};
}
getRemoveProfileImageOption = () => {
let action = null;
const {removeProfileImage} = this.props;
const {id, last_picture_update: lastPictureUpdate} = this.props.currentUser;
const profileImageUrl = Client4.getProfilePictureUrl(id, lastPictureUpdate);
if (removeProfileImage !== null) {
action = removeProfileImage;
}
// Check if image url includes query string for timestamp.
// If so, it means the image has been updated from the default
// i.e. '.../image?_=1544159746868'
if (profileImageUrl.includes('?')) {
return {
action,
text: {
id: t('mobile.edit_profile.remove_profile_photo'),
defaultMessage: 'Remove Photo',
},
textStyle: {
color: '#CC3239',
},
icon: 'trash',
iconStyle: {
color: '#CC3239',
},
};
}
return null;
};
render() {
const {children, ...props} = this.props;
const {extraOptions} = this.state;
// Avoid passing unneeded props
Reflect.deleteProperty(props, 'currentUser');
return (
<AttachmentButton
{...props}
extraOptions={extraOptions}
>
{children}
</AttachmentButton>
);
}
}