Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated profile-card doc and made the code cleaner #726

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ function EditMode({
const [isLoading, setIsLoading] = React.useState(false);
const { toast, dismiss } = useToast();

async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
const isUnchanged = name === displayName && bio === biography;

const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
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;
Expand All @@ -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"
Expand Down Expand Up @@ -132,7 +134,7 @@ function EditMode({
changeMode();
setIsLoading(false);
}
}
};

return (
<form onSubmit={handleSubmit} className="w-full flex flex-col gap-4">
Expand All @@ -155,13 +157,13 @@ function EditMode({
disabled={isLoading}
className="mt-1"
/>
{!name ? (
{!name && (
<p className="text-destructive text-sm mt-1">Name cannot be empty.</p>
) : null}
)}
</div>
<div className="w-full">
<div className="w-full relative">
<Label htmlFor="biography-input">Biography*</Label>
<Label htmlFor="biography-input">Biography</Label>
<div className="absolute right-1 top-1 text-sm">
{biography?.length} / 128
</div>
Expand Down