1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00
planka/client/src/components/UserSettingsModal/AccountPane/EditAvatarPopup.jsx

72 lines
1.7 KiB
React
Raw Normal View History

2020-04-08 21:12:58 +05:00
import React, { useCallback, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import { Button } from 'semantic-ui-react';
import { withPopup } from '../../../lib/popup';
2020-04-21 05:04:34 +05:00
import { FilePicker, Popup } from '../../../lib/custom-ui';
2020-04-08 21:12:58 +05:00
import styles from './EditAvatarPopup.module.scss';
2020-04-08 21:12:58 +05:00
2020-04-21 05:04:34 +05:00
const EditAvatarStep = React.memo(({ defaultValue, onUpdate, onDelete, onClose }) => {
2020-04-08 21:12:58 +05:00
const [t] = useTranslation();
const field = useRef(null);
2020-04-21 05:04:34 +05:00
const handleFileSelect = useCallback(
(file) => {
onUpdate({
file,
});
onClose();
2020-04-08 21:12:58 +05:00
},
2020-04-21 05:04:34 +05:00
[onUpdate, onClose],
2020-04-08 21:12:58 +05:00
);
const handleDeleteClick = useCallback(() => {
onDelete();
onClose();
}, [onDelete, onClose]);
useEffect(() => {
field.current.focus();
}, []);
return (
<>
<Popup.Header>
{t('common.editAvatar', {
context: 'title',
})}
</Popup.Header>
<Popup.Content>
2020-04-21 05:04:34 +05:00
<div className={styles.action}>
<FilePicker accept="image/*" onSelect={handleFileSelect}>
<Button
ref={field}
content={t('action.uploadNewAvatar')}
className={styles.actionButton}
/>
</FilePicker>
2020-04-08 21:12:58 +05:00
</div>
{defaultValue && (
<Button negative content={t('action.deleteAvatar')} onClick={handleDeleteClick} />
)}
</Popup.Content>
</>
);
});
EditAvatarStep.propTypes = {
defaultValue: PropTypes.string,
2020-04-21 05:04:34 +05:00
onUpdate: PropTypes.func.isRequired,
2020-04-08 21:12:58 +05:00
onDelete: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
};
EditAvatarStep.defaultProps = {
defaultValue: undefined,
};
export default withPopup(EditAvatarStep);