Skip to content

Commit

Permalink
Resolved error message and verification error state logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetDOD committed Jun 4, 2024
1 parent 296f502 commit 7b547c8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions frontend/src/pages/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import toast from "react-hot-toast";
const Profile = () => {
const [user, setUser] = useState<IUser | null>(null);
const [loading, setLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState("");
const [otpSent, setOtpSent] = useState(false);
const [otp, setOtp] = useState("");
const [verificationError, setVerificationError] = useState("");
Expand All @@ -30,7 +31,7 @@ const Profile = () => {
setUser(response.data.user);
setLoading(false);
} catch (error) {
console.log('Failed to fetch user details');
setErrorMessage('Failed to fetch user details');
setLoading(false);
}
};
Expand All @@ -47,9 +48,10 @@ const Profile = () => {
});
setOtpSent(true);
toast.success(response.data.message);
setVerificationError("");
} catch (error) {
setVerificationError("OTP sent to your mail");
} catch (error:any) {
toast.error('Failed to generate OTP');
setVerificationError(error.response.data.error.message||'Failed to generate OTP');
}
};

Expand All @@ -71,15 +73,20 @@ const Profile = () => {
setOtp("");
setVerificationError("");
toast.success('OTP verified successfully');
} catch (error) {
} catch (error:any) {
toast.error('Failed to verify OTP');
setVerificationError(error.response.data.error.message||'Failed to generate OTP');
}
};

if (loading) {
return <Loader />;
}

if (errorMessage) {
return <div className='text-red-500 font-semibold text-lg text-center'>{errorMessage}</div>;
}

return (
<>
<div className="max-w-screen-xl mx-auto p-4 text-white flex flex-col items-center">
Expand Down

0 comments on commit 7b547c8

Please sign in to comment.