Skip to content

Commit

Permalink
Added update profile loading animation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivaBhattacharjee committed Nov 8, 2023
1 parent 0ec7d01 commit a31471d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/app/edit-profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import AvatarModal from "@/components/shared/AvatarModal";
import { useProfile } from "@/context/ProfileUpdateContext";
import { Error } from "@/types/ErrorTypes";
import Toast from "@/utils/toast";
import { ClipLoader } from "react-spinners";

const Page = () => {
const token = getCookie("token");
Expand All @@ -20,6 +21,7 @@ const Page = () => {
const [userDescription, setUserDescription] = useState("");
const { isProfileUpdated, setIsProfileUpdated } = useProfile();
const [openAvatarModal, setOpenAvatarModal] = useState(false);
const [editLoading, setEditLoading] = useState(false);
const getUserData = async () => {
try {
const userResponse = await fetch("/api/get-users");
Expand Down Expand Up @@ -50,6 +52,7 @@ const Page = () => {

try {
if (isProfileUpdated) {
setEditLoading(true);
const res = await axios.put("/api/get-users", userData);
setIsProfileUpdated(false);
if (res) {
Expand All @@ -61,9 +64,12 @@ const Page = () => {
Toast.ErrorShowToast("Nothing to update");
}
} catch (error: unknown) {
setEditLoading(false);
const ErrorMsg = error as Error;
Toast.ErrorShowToast(ErrorMsg?.response?.data?.error || "Something went wrong");
console.log(error);
} finally {
setEditLoading(false);
}
};
const handleSelectProfilePicture = (url: string) => {
Expand Down Expand Up @@ -120,9 +126,9 @@ const Page = () => {
setIsProfileUpdated(true);
}}
/>
<button className={`flex justify-center items-center gap-4 ${isProfileUpdated ? "bg-white text-black" : "bg-white/40 "} p-4 rounded-lg font-semibold w-full mt-5 lg:w-56`} disabled={!isProfileUpdated}>
<Check />
Update Profile
<button className={`flex justify-center items-center gap-4 ${isProfileUpdated ? "bg-white text-black" : "bg-white/40 "} p-4 rounded-lg font-semibold w-full mt-5 lg:w-56`} disabled={!isProfileUpdated || editLoading}>
{editLoading ? <ClipLoader size={20} color="#000" /> : <Check size={20} />}
{editLoading ? "Updating..." : "Update"}
</button>
</div>
</div>
Expand Down

0 comments on commit a31471d

Please sign in to comment.