Merge pull request 'fix(auth): clear stale password update success message on login, logout, and navigation' (#113) from fix/stale-password-success-message into main

Reviewed-on: https://git.zedobject.local/AcuPedia/acupedia-store-ui/pulls/113
Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
Amit Salunke 2026-11-23 04:54:09 +00:00
commit 1f11874755
2 changed files with 49 additions and 7 deletions

View File

@ -93,6 +93,16 @@ export default function App() {
const [changePasswordError, setChangePasswordError] = useState<string | null>(null); const [changePasswordError, setChangePasswordError] = useState<string | null>(null);
const [changePasswordSuccess, setChangePasswordSuccess] = useState<boolean>(false); 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 // Auth Form State
const [authEmail, setAuthEmail] = useState(''); const [authEmail, setAuthEmail] = useState('');
const [authPassword, setAuthPassword] = useState(''); const [authPassword, setAuthPassword] = useState('');
@ -411,6 +421,16 @@ export default function App() {
} }
}; };
const handleCloseProfileDrawer = () => {
setShowProfileDrawer(false);
setShowPasswordChange(false);
setChangePasswordError(null);
setChangePasswordSuccess(false);
setChangeOldPassword('');
setChangeNewPassword('');
setChangeConfirmPassword('');
};
const handleLogout = () => { const handleLogout = () => {
localStorage.removeItem('access_token'); localStorage.removeItem('access_token');
setUserToken(null); setUserToken(null);
@ -419,7 +439,7 @@ export default function App() {
setAppliedCoupon(null); setAppliedCoupon(null);
setCouponCode(''); setCouponCode('');
setPricingCalc(null); setPricingCalc(null);
setShowProfileDrawer(false); handleCloseProfileDrawer();
setProfileDisplayName(''); setProfileDisplayName('');
setProfilePhone(''); setProfilePhone('');
setProfileCountry(initialRegion.country); setProfileCountry(initialRegion.country);
@ -579,6 +599,12 @@ export default function App() {
if (activeTab === 'logged-out') { if (activeTab === 'logged-out') {
switchTab('storefront'); switchTab('storefront');
} }
setShowPasswordChange(false);
setChangeOldPassword('');
setChangeNewPassword('');
setChangeConfirmPassword('');
setChangePasswordError(null);
setChangePasswordSuccess(false);
} catch (err: any) { } catch (err: any) {
setAuthError(err.response?.data?.detail || 'Authentication failed. Please check credentials.'); setAuthError(err.response?.data?.detail || 'Authentication failed. Please check credentials.');
} finally { } finally {
@ -635,7 +661,8 @@ export default function App() {
setChangeNewPassword(''); setChangeNewPassword('');
setChangeConfirmPassword(''); setChangeConfirmPassword('');
setShowPasswordChange(false); setShowPasswordChange(false);
setChangePasswordSuccess(true); setChangePasswordSuccess(false);
setChangePasswordError(null);
setPasswordUpdatedPopup(true); setPasswordUpdatedPopup(true);
} catch (err: any) { } catch (err: any) {
console.error(err); console.error(err);
@ -1086,7 +1113,11 @@ export default function App() {
activeTab={activeTab} activeTab={activeTab}
onSwitchTab={switchTab} onSwitchTab={switchTab}
loggedInUser={loggedInUser} loggedInUser={loggedInUser}
onOpenProfile={() => setShowProfileDrawer(true)} onOpenProfile={() => {
setChangePasswordSuccess(false);
setChangePasswordError(null);
setShowProfileDrawer(true);
}}
onOpenAuth={(mode) => { onOpenAuth={(mode) => {
setAuthMode(mode); setAuthMode(mode);
setShowAuthModal(true); setShowAuthModal(true);
@ -1218,7 +1249,7 @@ export default function App() {
{/* 🧭 Profile Drawer */} {/* 🧭 Profile Drawer */}
<ProfileDrawer <ProfileDrawer
isOpen={showProfileDrawer} isOpen={showProfileDrawer}
onClose={() => setShowProfileDrawer(false)} onClose={handleCloseProfileDrawer}
loggedInUser={loggedInUser} loggedInUser={loggedInUser}
profileDisplayName={profileDisplayName} profileDisplayName={profileDisplayName}
setProfileDisplayName={setProfileDisplayName} setProfileDisplayName={setProfileDisplayName}
@ -1241,15 +1272,17 @@ export default function App() {
setChangeConfirmPassword={setChangeConfirmPassword} setChangeConfirmPassword={setChangeConfirmPassword}
changePasswordLoading={changePasswordLoading} changePasswordLoading={changePasswordLoading}
changePasswordError={changePasswordError} changePasswordError={changePasswordError}
setChangePasswordError={setChangePasswordError}
changePasswordSuccess={changePasswordSuccess} changePasswordSuccess={changePasswordSuccess}
setChangePasswordSuccess={setChangePasswordSuccess}
onChangePassword={handleChangePassword} onChangePassword={handleChangePassword}
onLogout={handleLogout} onLogout={handleLogout}
onBrowseStorefront={() => { onBrowseStorefront={() => {
setShowProfileDrawer(false); handleCloseProfileDrawer();
switchTab('storefront'); switchTab('storefront');
}} }}
onViewSubscriptions={() => { onViewSubscriptions={() => {
setShowProfileDrawer(false); handleCloseProfileDrawer();
switchTab('subscriptions'); switchTab('subscriptions');
}} }}
curriculumModules={curriculumModules} curriculumModules={curriculumModules}

View File

@ -34,7 +34,9 @@ interface ProfileDrawerProps {
setChangeConfirmPassword: (pwd: string) => void; setChangeConfirmPassword: (pwd: string) => void;
changePasswordLoading: boolean; changePasswordLoading: boolean;
changePasswordError: string | null; changePasswordError: string | null;
setChangePasswordError?: (err: string | null) => void;
changePasswordSuccess: boolean; changePasswordSuccess: boolean;
setChangePasswordSuccess?: (success: boolean) => void;
onChangePassword: (e: React.FormEvent) => Promise<void>; onChangePassword: (e: React.FormEvent) => Promise<void>;
onLogout: () => void; onLogout: () => void;
onBrowseStorefront: () => void; onBrowseStorefront: () => void;
@ -68,7 +70,9 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
setChangeConfirmPassword, setChangeConfirmPassword,
changePasswordLoading, changePasswordLoading,
changePasswordError, changePasswordError,
setChangePasswordError,
changePasswordSuccess, changePasswordSuccess,
setChangePasswordSuccess,
onChangePassword, onChangePassword,
onLogout, onLogout,
onBrowseStorefront, onBrowseStorefront,
@ -89,8 +93,11 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
const p = parsePhoneNumber(profilePhone, profileCountry); const p = parsePhoneNumber(profilePhone, profileCountry);
setDialCode(p.dialCode); setDialCode(p.dialCode);
setLocalPhone(p.localDigits); setLocalPhone(p.localDigits);
} else {
if (setChangePasswordSuccess) setChangePasswordSuccess(false);
if (setChangePasswordError) setChangePasswordError(null);
} }
}, [isOpen]); }, [isOpen, setChangePasswordSuccess, setChangePasswordError]);
const handleLocalPhoneChange = (newLocal: string) => { const handleLocalPhoneChange = (newLocal: string) => {
setLocalPhone(newLocal); setLocalPhone(newLocal);
@ -239,6 +246,8 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
type="button" type="button"
onClick={() => { onClick={() => {
setShowPasswordChange(!showPasswordChange); setShowPasswordChange(!showPasswordChange);
if (setChangePasswordSuccess) setChangePasswordSuccess(false);
if (setChangePasswordError) setChangePasswordError(null);
}} }}
className="text-xs text-indigo-600 hover:text-indigo-700 font-bold" className="text-xs text-indigo-600 hover:text-indigo-700 font-bold"
> >