From 63c869c88c6a041202540fe9c6d80398c6f82e13 Mon Sep 17 00:00:00 2001 From: Cosmin29 <73159321+Cosmin29@users.noreply.github.com> Date: Thu, 12 Oct 2023 19:41:55 +0300 Subject: [PATCH] updated profile-card doc and made the code cleaner --- .../(user-profile)/(components)/profile-card.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/app/src/app/users/(user-profile)/(components)/profile-card.tsx b/packages/app/src/app/users/(user-profile)/(components)/profile-card.tsx index 9140ad8f..c3a3d607 100644 --- a/packages/app/src/app/users/(user-profile)/(components)/profile-card.tsx +++ b/packages/app/src/app/users/(user-profile)/(components)/profile-card.tsx @@ -89,13 +89,15 @@ function EditMode({ const [isLoading, setIsLoading] = React.useState(false); const { toast, dismiss } = useToast(); - async function handleSubmit(e: React.FormEvent) { + const isUnchanged = name === displayName && bio === biography; + + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); // if the user clicks save but all information is the same, // just return. - if (name === displayName && bio === biography) { + if (isUnchanged) { changeMode(); setIsLoading(false); return; @@ -104,7 +106,7 @@ function EditMode({ toast( { title: "Updating Information", - description: "Your information is being updated..", + description: "Your information is being updated...", variant: "default", }, "loading-toast" @@ -132,7 +134,7 @@ function EditMode({ changeMode(); setIsLoading(false); } - } + }; return (
@@ -155,13 +157,13 @@ function EditMode({ disabled={isLoading} className="mt-1" /> - {!name ? ( + {!name && (

Name cannot be empty.

- ) : null} + )}
- +
{biography?.length} / 128