mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
removed profile redux items
This commit is contained in:
parent
5b28313afd
commit
3c0571816c
55 changed files with 488 additions and 710 deletions
45
src/components/profile/ProfileAvatar/index.tsx
Normal file
45
src/components/profile/ProfileAvatar/index.tsx
Normal file
|
@ -0,0 +1,45 @@
|
|||
import React, { ChangeEvent, FC, useCallback } from 'react';
|
||||
import styles from './styles.module.scss';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { IFile } from '~/redux/types';
|
||||
|
||||
export interface ProfileAvatarProps {
|
||||
canEdit: boolean;
|
||||
photo?: IFile;
|
||||
onChangePhoto: (file: File) => void;
|
||||
}
|
||||
|
||||
const ProfileAvatar: FC<ProfileAvatarProps> = ({ photo, onChangePhoto, canEdit }) => {
|
||||
const onInputChange = useCallback(
|
||||
async (event: ChangeEvent<HTMLInputElement>) => {
|
||||
if (!event.target.files?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
onChangePhoto(event.target.files[0]);
|
||||
},
|
||||
[onChangePhoto]
|
||||
);
|
||||
|
||||
const backgroundImage = photo ? `url("${getURL(photo, PRESETS.avatar)}")` : undefined;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={styles.avatar}
|
||||
style={{
|
||||
backgroundImage,
|
||||
}}
|
||||
>
|
||||
{canEdit && <input type="file" onInput={onInputChange} />}
|
||||
{canEdit && (
|
||||
<div className={styles.can_edit}>
|
||||
<Icon icon="photo_add" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { ProfileAvatar };
|
Loading…
Add table
Add a link
Reference in a new issue