Enhance order ID handling and navigation in ProfilePage and OrdersTab: Updated hash processing to validate order IDs, improved tab navigation, and added console logging for better debugging. Adjusted navigation to ensure correct hash updates when switching tabs and viewing orders.
This commit is contained in:
@@ -94,30 +94,46 @@ const ProfilePage = (props) => {
|
||||
|
||||
useEffect(() => {
|
||||
const hash = location.hash;
|
||||
console.log('ProfilePage: Processing hash:', hash);
|
||||
|
||||
switch (hash) {
|
||||
case '#cart':
|
||||
console.log('ProfilePage: Switching to cart tab');
|
||||
setTabValue(0);
|
||||
setOrderIdFromHash(null);
|
||||
break;
|
||||
case '#orders':
|
||||
console.log('ProfilePage: Switching to orders tab');
|
||||
setTabValue(1);
|
||||
setOrderIdFromHash(null);
|
||||
break;
|
||||
case '#settings':
|
||||
console.log('ProfilePage: Switching to settings tab');
|
||||
setTabValue(2);
|
||||
setOrderIdFromHash(null);
|
||||
break;
|
||||
default:
|
||||
if (hash && hash.startsWith('#ORD-')) {
|
||||
const orderId = hash.substring(1);
|
||||
setOrderIdFromHash(orderId);
|
||||
setTabValue(1); // Switch to Orders tab
|
||||
if (hash && hash.length > 1) {
|
||||
// Check if it's a potential order ID (starts with # and has alphanumeric characters with dashes)
|
||||
const potentialOrderId = hash.substring(1);
|
||||
if (/^[A-Z0-9]+-[A-Z0-9]+$/i.test(potentialOrderId)) {
|
||||
console.log('ProfilePage: Detected order ID from hash:', potentialOrderId);
|
||||
setOrderIdFromHash(potentialOrderId);
|
||||
setTabValue(1); // Switch to Orders tab
|
||||
} else {
|
||||
console.log('ProfilePage: Hash does not match order ID pattern:', potentialOrderId);
|
||||
setOrderIdFromHash(null);
|
||||
}
|
||||
} else {
|
||||
setOrderIdFromHash(null);
|
||||
// If no hash is present, set default to cart tab
|
||||
if (!hash) {
|
||||
console.log('ProfilePage: No hash present, redirecting to cart');
|
||||
navigate('/profile#cart', { replace: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [location.hash]);
|
||||
}, [location.hash, navigate]);
|
||||
|
||||
useEffect(() => {
|
||||
const checkUserLoggedIn = () => {
|
||||
@@ -169,10 +185,23 @@ const ProfilePage = (props) => {
|
||||
|
||||
const handleTabChange = (event, newValue) => {
|
||||
setTabValue(newValue);
|
||||
|
||||
// Update the hash based on the selected tab
|
||||
const hashMap = {
|
||||
0: '#cart',
|
||||
1: '#orders',
|
||||
2: '#settings'
|
||||
};
|
||||
|
||||
const newHash = hashMap[newValue];
|
||||
if (newHash) {
|
||||
navigate(`/profile${newHash}`, { replace: true });
|
||||
}
|
||||
};
|
||||
|
||||
const handleGoToOrders = () => {
|
||||
setTabValue(1);
|
||||
navigate('/profile#orders', { replace: true });
|
||||
};
|
||||
|
||||
const handleClearPaymentCompletion = () => {
|
||||
|
||||
Reference in New Issue
Block a user