fix(auth): clear stale password update success message on login, logout, and navigation #113
45
src/App.tsx
45
src/App.tsx
|
|
@ -75,6 +75,16 @@ export default function App() {
|
|||
const [changePasswordError, setChangePasswordError] = useState<string | null>(null);
|
||||
const [changePasswordSuccess, setChangePasswordSuccess] = useState<boolean>(false);
|
||||
|
||||
// Auto-clear change password success banner after 4 seconds
|
||||
useEffect(() => {
|
||||
if (changePasswordSuccess) {
|
||||
const timer = setTimeout(() => {
|
||||
setChangePasswordSuccess(false);
|
||||
}, 4000);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [changePasswordSuccess]);
|
||||
|
||||
// Auth Form State
|
||||
const [authEmail, setAuthEmail] = useState('');
|
||||
const [authPassword, setAuthPassword] = useState('');
|
||||
|
|
@ -393,6 +403,16 @@ export default function App() {
|
|||
}
|
||||
};
|
||||
|
||||
const handleCloseProfileDrawer = () => {
|
||||
setShowProfileDrawer(false);
|
||||
setShowPasswordChange(false);
|
||||
setChangePasswordError(null);
|
||||
setChangePasswordSuccess(false);
|
||||
setChangeOldPassword('');
|
||||
setChangeNewPassword('');
|
||||
setChangeConfirmPassword('');
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('access_token');
|
||||
setUserToken(null);
|
||||
|
|
@ -401,7 +421,7 @@ export default function App() {
|
|||
setAppliedCoupon(null);
|
||||
setCouponCode('');
|
||||
setPricingCalc(null);
|
||||
setShowProfileDrawer(false);
|
||||
handleCloseProfileDrawer();
|
||||
setProfileDisplayName('');
|
||||
setProfilePhone('');
|
||||
setProfileCountry('India');
|
||||
|
|
@ -560,6 +580,12 @@ export default function App() {
|
|||
if (activeTab === 'logged-out') {
|
||||
switchTab('storefront');
|
||||
}
|
||||
setShowPasswordChange(false);
|
||||
setChangeOldPassword('');
|
||||
setChangeNewPassword('');
|
||||
setChangeConfirmPassword('');
|
||||
setChangePasswordError(null);
|
||||
setChangePasswordSuccess(false);
|
||||
} catch (err: any) {
|
||||
setAuthError(err.response?.data?.detail || 'Authentication failed. Please check credentials.');
|
||||
} finally {
|
||||
|
|
@ -616,7 +642,8 @@ export default function App() {
|
|||
setChangeNewPassword('');
|
||||
setChangeConfirmPassword('');
|
||||
setShowPasswordChange(false);
|
||||
setChangePasswordSuccess(true);
|
||||
setChangePasswordSuccess(false);
|
||||
setChangePasswordError(null);
|
||||
setPasswordUpdatedPopup(true);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
|
|
@ -1065,7 +1092,11 @@ export default function App() {
|
|||
activeTab={activeTab}
|
||||
onSwitchTab={switchTab}
|
||||
loggedInUser={loggedInUser}
|
||||
onOpenProfile={() => setShowProfileDrawer(true)}
|
||||
onOpenProfile={() => {
|
||||
setChangePasswordSuccess(false);
|
||||
setChangePasswordError(null);
|
||||
setShowProfileDrawer(true);
|
||||
}}
|
||||
onOpenAuth={(mode) => {
|
||||
setAuthMode(mode);
|
||||
setShowAuthModal(true);
|
||||
|
|
@ -1198,7 +1229,7 @@ export default function App() {
|
|||
{/* 🧭 Profile Drawer */}
|
||||
<ProfileDrawer
|
||||
isOpen={showProfileDrawer}
|
||||
onClose={() => setShowProfileDrawer(false)}
|
||||
onClose={handleCloseProfileDrawer}
|
||||
loggedInUser={loggedInUser}
|
||||
profileDisplayName={profileDisplayName}
|
||||
setProfileDisplayName={setProfileDisplayName}
|
||||
|
|
@ -1221,15 +1252,17 @@ export default function App() {
|
|||
setChangeConfirmPassword={setChangeConfirmPassword}
|
||||
changePasswordLoading={changePasswordLoading}
|
||||
changePasswordError={changePasswordError}
|
||||
setChangePasswordError={setChangePasswordError}
|
||||
changePasswordSuccess={changePasswordSuccess}
|
||||
setChangePasswordSuccess={setChangePasswordSuccess}
|
||||
onChangePassword={handleChangePassword}
|
||||
onLogout={handleLogout}
|
||||
onBrowseStorefront={() => {
|
||||
setShowProfileDrawer(false);
|
||||
handleCloseProfileDrawer();
|
||||
switchTab('storefront');
|
||||
}}
|
||||
onViewSubscriptions={() => {
|
||||
setShowProfileDrawer(false);
|
||||
handleCloseProfileDrawer();
|
||||
switchTab('subscriptions');
|
||||
}}
|
||||
curriculumModules={curriculumModules}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ interface ProfileDrawerProps {
|
|||
setChangeConfirmPassword: (pwd: string) => void;
|
||||
changePasswordLoading: boolean;
|
||||
changePasswordError: string | null;
|
||||
setChangePasswordError?: (err: string | null) => void;
|
||||
changePasswordSuccess: boolean;
|
||||
setChangePasswordSuccess?: (success: boolean) => void;
|
||||
onChangePassword: (e: React.FormEvent) => Promise<void>;
|
||||
onLogout: () => void;
|
||||
onBrowseStorefront: () => void;
|
||||
|
|
@ -68,7 +70,9 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
|
|||
setChangeConfirmPassword,
|
||||
changePasswordLoading,
|
||||
changePasswordError,
|
||||
setChangePasswordError,
|
||||
changePasswordSuccess,
|
||||
setChangePasswordSuccess,
|
||||
onChangePassword,
|
||||
onLogout,
|
||||
onBrowseStorefront,
|
||||
|
|
@ -89,8 +93,11 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
|
|||
const p = parsePhoneNumber(profilePhone, profileCountry);
|
||||
setDialCode(p.dialCode);
|
||||
setLocalPhone(p.localDigits);
|
||||
} else {
|
||||
if (setChangePasswordSuccess) setChangePasswordSuccess(false);
|
||||
if (setChangePasswordError) setChangePasswordError(null);
|
||||
}
|
||||
}, [isOpen]);
|
||||
}, [isOpen, setChangePasswordSuccess, setChangePasswordError]);
|
||||
|
||||
const handleLocalPhoneChange = (newLocal: string) => {
|
||||
setLocalPhone(newLocal);
|
||||
|
|
@ -239,6 +246,8 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
|
|||
type="button"
|
||||
onClick={() => {
|
||||
setShowPasswordChange(!showPasswordChange);
|
||||
if (setChangePasswordSuccess) setChangePasswordSuccess(false);
|
||||
if (setChangePasswordError) setChangePasswordError(null);
|
||||
}}
|
||||
className="text-xs text-indigo-600 hover:text-indigo-700 font-bold"
|
||||
>
|
||||
|
|
|
|||
Loading…
Reference in New Issue