From 714a06ec7de7ff991a0e36216750a9e4bd700e2a Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Sat, 18 Mar 2023 17:09:32 +0000 Subject: [PATCH] Update user name --- src/components/Modal/Profile/ProfileModal.tsx | 93 ++++++++++--------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/src/components/Modal/Profile/ProfileModal.tsx b/src/components/Modal/Profile/ProfileModal.tsx index 7445a4e..00d61da 100644 --- a/src/components/Modal/Profile/ProfileModal.tsx +++ b/src/components/Modal/Profile/ProfileModal.tsx @@ -16,6 +16,7 @@ import { Image, Icon, Stack, + Input, } from "@chakra-ui/react"; import { MdAccountCircle } from "react-icons/md"; import { User } from "@firebase/auth"; @@ -44,6 +45,7 @@ const ProfileModal: React.FC = ({ open, handleClose }) => { const [uploadingImage, setUploadingImage] = useState(false); const [deleteImage, setDeleteImage] = useState(false); const showToast = useCustomToast(); + const [userName, setUserName] = useState(""); const closeModal = () => { setSelectedFile(""); @@ -115,6 +117,29 @@ const ProfileModal: React.FC = ({ open, handleClose }) => { } }; + const onUpdateUserName = async () => { + try { + const success = await updateProfile({ + displayName: userName, + }); + + if (!success) { + throw new Error("Failed to update profile name"); + } + } catch (error) { + console.error("Error: onUpdateUserName: ", error); + showToast({ + title: "Name not Updated", + description: "Failed to update profile name", + status: "error", + }); + } + }; + + const handleNameChange = (event: React.ChangeEvent) => { + setUserName(event.target.value); + }; + const handleSaveButtonClick = () => { if (selectedFile) { onUpdateImage(); @@ -122,6 +147,9 @@ const ProfileModal: React.FC = ({ open, handleClose }) => { if (deleteImage) { onDeleteImage(); } + if (userName) { + onUpdateUserName(); + } closeModal(); }; @@ -197,7 +225,27 @@ const ProfileModal: React.FC = ({ open, handleClose }) => { {/* */} {/* */} - + + {/* name */} + + + {`Email: ${user?.email}`} + + + {`Name: ${user?.displayName}`} + + + User Name + + + + {/* */} @@ -215,46 +263,3 @@ const ProfileModal: React.FC = ({ open, handleClose }) => { ); }; export default ProfileModal; - -type ProfileModalPictureProps = { - user: User | null | undefined; -}; - -const ProfileModalPicture: React.FC = ({ user }) => { - return ( - - {user?.photoURL ? ( - User Profile Photo - ) : ( - - )} - - ); -}; - -interface ProfileModalUserDetailsProps { - user: User | null | undefined; -} - -const ProfileModalUserDetails: React.FC = ({ - user, -}) => { - return ( - - - Display Name: - {user?.displayName ? user.displayName : "No Name"} - - - Email: - {user?.email} - - - ); -};