From 4ffc0da2a65eb8f44ad9a3f99fdde39b721d06bd Mon Sep 17 00:00:00 2001 From: Jeff Huang <82061589+solderq35@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:29:04 -0700 Subject: [PATCH] Add Profile Pic Removal Button (#340) * remove pfp button poc * switch to modal * remove dialog comment * fix modal content text * changed back to dialog, minor wording update * remove unused styles * commit what's working so far before removing unused styling etc * remove some unused stuff * remove unused fragment * remove more console logs and unused code * slight improvement * nit --------- Co-authored-by: Frankreed --- app/content/profile/index.js | 346 +++++++++++++++++++------------ components/bottomSheetWrapper.js | 16 +- 2 files changed, 231 insertions(+), 131 deletions(-) diff --git a/app/content/profile/index.js b/app/content/profile/index.js index e69ba85b..fe6ab7b4 100644 --- a/app/content/profile/index.js +++ b/app/content/profile/index.js @@ -41,6 +41,7 @@ import { useEmailInfo } from "~/dbOperations/hooks/useEmailInfo"; import { useUserInfo } from "~/dbOperations/hooks/useUserInfo"; import { handleImageUpload } from "~/dbOperations/imageUpload"; import { invalidateMultipleKeys } from "~/dbOperations/invalidateMultipleKeys"; +import removePfp from "~/dbOperations/removePfp"; import { db } from "~/firebaseConfig"; function Index() { @@ -79,17 +80,17 @@ function Index() { ["userEmail", { userId }], ["drillInfo"], ]; + const [editPicFlag, setEditPicFlag] = useState(false); const [newName, setNewName] = useState(""); const [email, setEmail] = useState(""); const [currentPassword, setCurrentPassword] = useState(""); const [newPassword, setNewPassword] = useState(""); const [newPasswordCheck, setNewPasswordCheck] = useState(""); const [passwordInputVisible, setPasswordInputVisible] = useState(false); - + const [uploadLoading, setUploadLoading] = useState(false); + const [removeLoading, setRemoveLoading] = useState(false); const [imageUploading, setImageUploading] = useState(false); - const [updateLoading, setUpdateLoading] = useState(false); - const profilePicSize = 120; useEffect(() => { @@ -272,11 +273,6 @@ function Index() { marginBottom: 20, alignSelf: "center", }, - saveChangesButtonText: { - color: "#FFF", - fontWeight: "bold", - alignSelf: "center", - }, changePasswordButton: { color: "black", fontSize: 16, @@ -291,6 +287,32 @@ function Index() { height: "100%", borderRadius: 60, }, + uploadButtonText: { + fontSize: 16, + }, + removeButtonText: { + fontSize: 16, + color: userData.pfp ? themeColors.accent : "#808080", + textAlign: "center", + }, + editModal: { + flex: 1, + justifyContent: "center", + alignItems: "center", + padding: 20, + marginBottom: 30, + }, + editButtons: { + marginBottom: 10, + }, + editModalTitleText: { + fontSize: 24, + fontWeight: "bold", + marginBottom: 20, + }, + editModalContentText: { + marginBottom: 20, + }, }); const profileHeader = ( @@ -307,7 +329,10 @@ function Index() { bottomSheetModalRef.current?.present()} + onPress={() => { + bottomSheetModalRef.current?.present(); + setEditPicFlag(false); + }} style={{ marginRight: 7 }} /> } @@ -315,10 +340,16 @@ function Index() { { - resetForm(); - setNewName(userData.name); - setPasswordInputVisible(false); + if (editPicFlag) { + setEditPicFlag(false); + } else { + resetForm(); + setNewName(userData.name); + setPasswordInputVisible(false); + } }} + closeButtonText={editPicFlag ? "< Back" : "Close"} + preventDefaultClose={editPicFlag} > {/* Profile Picture */} { - try { - await handleImageUpload( - setImageUploading, - showSnackBar, - getPfpName(currentTeamId, userId), - userRef, - profilePicSize, - profilePicSize, - ); - await invalidateMultipleKeys(queryClient, [["userInfo"]]); - } catch (e) { - console.log(e); - showDialog("Error", getErrorString(e)); - } + onPress={() => { + setEditPicFlag(!editPicFlag); }} > @@ -359,117 +377,189 @@ function Index() { style={styles.profilePicture} /> )} - - - + {!editPicFlag && ( + + + + )} - {/* Display Name */} - - {userData.name} - - - {/* Display Email */} - - {email} - + {editPicFlag && ( + <> + + Edit Profile Picture + + {`Do you want to ${userData.pfp ? "Change the current" : "Upload a new"} Profile Picture or Remove the current Profile Picture?`} + + + + )} - {/* Name Update input field */} - - - Update your name - - - setNewName(text)} - placeholder="Update your name" - /> + {!editPicFlag && ( + <> + {/* Display Name */} + + {userData.name} + - {/* Change Password Button */} - - - Change Password - - { - resetForm(); - setPasswordInputVisible(newValue); - }} - theme={{ - colors: { - primary: themeColors.accent, - }, - }} - /> - + {/* Display Email */} + + {email} + - {/* Password Input Field */} - {passwordInputVisible && ( - <> - - + {/* Name Update input field */} + + + Update your name + + setNewName(text)} + placeholder="Update your name" /> - - )} - {/* Save Button */} - + {/* Change Password Button */} + + + Change Password + + { + resetForm(); + setPasswordInputVisible(newValue); + }} + theme={{ + colors: { + primary: themeColors.accent, + }, + }} + /> + + + {/* Password Input Field */} + {passwordInputVisible && ( + <> + + + + + )} - {/* Sign Out Button */} - - Sign Out - + {/* Save Button */} + + + {/* Sign Out Button */} + + Sign Out + + + )} diff --git a/components/bottomSheetWrapper.js b/components/bottomSheetWrapper.js index f36cc084..e3d81f6f 100644 --- a/components/bottomSheetWrapper.js +++ b/components/bottomSheetWrapper.js @@ -5,7 +5,15 @@ import { SafeAreaInsetsContext } from "react-native-safe-area-context"; import { themeColors } from "~/Constants"; const BottomSheetWrapper = forwardRef( - ({ children, closeFn = () => {} }, ref) => { + ( + { + children, + closeFn = () => {}, + closeButtonText = "Close", + preventDefaultClose = false, + }, + ref, + ) => { const insets = useContext(SafeAreaInsetsContext); return ( { - ref.current.close(); + if (!preventDefaultClose) { + ref.current.close(); + } closeFn(); }} > @@ -40,7 +50,7 @@ const BottomSheetWrapper = forwardRef( marginLeft: 10, }} > - Close + {closeButtonText} {children}