import React, { useState } from 'react'; import { Box, Flex, HStack, Input, Menu, MenuButton, MenuList, Text, useColorModeValue, VStack, } from '@chakra-ui/react'; import { titleStyles, CustomizeProfileCard, Label, } from '../../../utils/CustomizeProfileStyles'; import defaultProfile from '../../../assets/images/default_profile.webp'; import { FaRegEdit } from 'react-icons/fa'; import CustomMenuItem from '../../../utils/CustomMenuItem'; import { checkUsername } from '../../../helper/checkUsername'; const User = ({ nameRef, emailRef, usernameRef, profileData, authenticatedUsernames, previewImgRef, removeProfileImgHandler, }) => { const [previewImg, setPreviewImg] = useState(''); const [isValid, setIsValid] = useState('valid'); const imagePreviewHandler = (e) => { const image = e.target.files[0]; const reader = new FileReader(); reader.addEventListener( 'load', () => { setPreviewImg(reader.result); }, false ); if (image) { reader.readAsDataURL(image); } }; const clickEdit = () => { document.getElementById('edit').click(); }; // if no profile image , i want user to go to file directly without showing option. const isValidUsername = (username) => { const status = checkUsername(username, authenticatedUsernames); setIsValid(status); }; return ( User Profile Image Edit removeProfileImgHandler(profileData.profile) } > Remove photo isValidUsername(target.value)} /> {isValid === 'valid' ? '' : isValid} ); }; export default User;