You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

454 lines
13 KiB

import React, { useMemo } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { MobileShell } from '../../components/layout/MobileShell';
import { BottomNavBar } from '../../components/layout/BottomNavBar';
import { OrderCounterCard } from '../../components/account/OrderCounterCard';
import { AccountMenuRow } from '../../components/account/AccountMenuRow';
import {
ACCOUNT_ORDER_COUNTERS,
type AccountMenuRowItem,
SHOP_ACCOUNT_MENU_ROWS,
} from '../../data/accountData';
import { useShopApp } from '../../context/ShopAppContext';
import { resolveMediaUrl } from '../../lib/http';
import { isBareMode, ROUTES, USE_MOCK_DATA } from '../../lib/routes';
/**
* Node 4214:345 — `shop-category` (Shop Account Overview, 375×814)
*/
export const ShopAccountPage: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();
const bare = isBareMode(location.search);
const useMockFallback = bare || USE_MOCK_DATA;
const {
isUserAuthenticated,
openLoginModal,
requireAuth,
profile,
orderCounters,
selectedAddress,
language,
bookmarkedProducts,
cartItemsCount,
} = useShopApp();
const counters = useMemo(() => {
if (bare || (!orderCounters && useMockFallback)) return ACCOUNT_ORDER_COUNTERS;
if (!isUserAuthenticated) {
return [
{ ...ACCOUNT_ORDER_COUNTERS[0], countText: '0 Orders' },
{ ...ACCOUNT_ORDER_COUNTERS[1], countText: '0 Orders' },
{ ...ACCOUNT_ORDER_COUNTERS[2], countText: '0 Orders' },
];
}
return [
{
...ACCOUNT_ORDER_COUNTERS[0],
countText: `${orderCounters?.in_progress ?? 0} Orders`,
},
{
...ACCOUNT_ORDER_COUNTERS[1],
countText: `${orderCounters?.delivered ?? 0} Orders`,
},
{
...ACCOUNT_ORDER_COUNTERS[2],
countText: `${orderCounters?.returned ?? 0} Orders`,
},
];
}, [bare, isUserAuthenticated, orderCounters, useMockFallback]);
const menuRows = useMemo<AccountMenuRowItem[]>(() => {
if (bare) return SHOP_ACCOUNT_MENU_ROWS;
const langLabel =
language === 'fa' ? 'فارسی' : language === 'ar' ? 'العربية' : 'English';
const mapped = SHOP_ACCOUNT_MENU_ROWS.map((row): AccountMenuRowItem => {
if (row.id === 'acc-addresses') {
return {
...row,
subtitle: isUserAuthenticated
? selectedAddress?.full_address ||
(useMockFallback ? row.subtitle : 'No saved address')
: 'Sign in to manage addresses',
targetRoute: ROUTES.addresses,
};
}
if (row.id === 'acc-language') {
return {
...row,
subtitle: langLabel,
rightIconType: 'arrow-right',
targetRoute: ROUTES.settings,
};
}
if (row.id === 'acc-notifications') {
const activeCount = isUserAuthenticated
? orderCounters?.in_progress ?? 0
: 0;
return {
...row,
badgeCount: activeCount > 0 ? String(activeCount) : undefined,
targetRoute: ROUTES.orders('current'),
};
}
if (row.id === 'acc-support') {
return {
...row,
targetRoute: ROUTES.support,
};
}
if (row.id === 'acc-faq') {
return {
...row,
targetRoute: ROUTES.profile,
};
}
return row;
});
const bookmarksRow: AccountMenuRowItem = {
id: 'acc-bookmarks',
y: 250,
title: 'Saved Items',
titleWidth: 110,
titleColor: '#151c31',
subtitle: isUserAuthenticated
? `${bookmarkedProducts.length} bookmarked products`
: 'Sign in to view saved items',
subtitleWidth: 180,
iconBoxBg: 'rgba(215, 142, 6, 0.14)',
iconSrc: '/assets/images/icon-menu-bookmark-subtract.svg',
iconLeft: 10,
iconTop: 8,
iconWidth: 14,
iconHeight: 18,
rightIconType: 'arrow-right',
targetRoute: ROUTES.bookmarks,
};
return [mapped[0], bookmarksRow, ...mapped.slice(1)];
}, [
bare,
bookmarkedProducts.length,
isUserAuthenticated,
language,
orderCounters,
selectedAddress,
useMockFallback,
]);
const displayName = bare
? 'Habib shoper'
: isUserAuthenticated
? profile?.full_name || 'Habib Shopper'
: useMockFallback
? 'Habib shoper'
: 'Guest';
const displaySub = bare
? '09102036523'
: isUserAuthenticated
? profile?.phone_number || profile?.email || 'Verified Habib Account'
: useMockFallback
? '09102036523'
: 'Sign in with your Habib account';
const avatarUrl =
!bare && isUserAuthenticated && profile?.avatar_url
? resolveMediaUrl(profile.avatar_url)
: '';
const handleProtectedNavigate = (targetRoute: string, featureName: string) => {
if (bare) {
navigate(targetRoute);
return;
}
void requireAuth({
featureName,
onAuthenticated: () => navigate(targetRoute),
});
};
return (
<MobileShell width={375} height={814} backgroundColor="#f3f1ef">
<div
style={{
display: 'flex',
flexDirection: 'column',
flex: 1,
padding: '21px var(--page-px) 24px',
}}
>
{/* Top Profile Header */}
<div
style={{
position: 'relative',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
marginBottom: 31,
}}
>
{/* Right Edit Profile Button (4214:11436) */}
<button
type="button"
onClick={() =>
handleProtectedNavigate(
bare ? '/provider-requst' : ROUTES.profile,
'your profile settings'
)
}
aria-label="Edit Profile"
style={{
position: 'absolute',
right: 0,
top: 0,
width: 40,
height: 40,
borderRadius: 15,
backgroundColor: '#ffffff',
border: 'none',
padding: 0,
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<img
src="/assets/images/icon-edit-pencil-gold.svg"
alt=""
style={{
width: 24,
height: 24,
}}
/>
</button>
{/* Avatar Circle (4215:11560) */}
<div
style={{
width: 84,
height: 84,
borderRadius: 78.5,
backgroundColor: '#768293',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
overflow: 'hidden',
}}
>
{avatarUrl ? (
<img
src={avatarUrl}
alt={displayName}
style={{
width: '100%',
height: '100%',
objectFit: 'cover',
}}
/>
) : (
<img
src="/assets/images/icon-account-avatar-gold.svg"
alt={displayName}
style={{
width: 31,
height: 33.04,
}}
/>
)}
</div>
{/* User Name "Habib shoper" (4214:366) */}
<div
style={{
marginTop: 9,
fontFamily: 'var(--font-sans)',
fontWeight: 700,
fontSize: 18,
lineHeight: '26px',
color: '#111111',
textAlign: 'center',
}}
>
{displayName}
</div>
{/* Phone "09102036523" (4214:367) */}
<div
style={{
marginTop: 3,
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 10,
lineHeight: '12.9px',
color: '#8b8b8b',
textAlign: 'center',
}}
>
{displaySub}
</div>
</div>
{/* 3 Order Status Counter Cards (4215:11563) */}
<div className="habib-counters-grid" style={{ marginBottom: 24 }}>
{counters.map((counter) => (
<OrderCounterCard
key={counter.id}
counter={counter}
onClick={() => {
if (bare) {
navigate('/shop-orders');
return;
}
const target =
counter.id === 'cnt-delivered'
? ROUTES.orders('delivered')
: counter.id === 'cnt-returned'
? ROUTES.orders('canceled')
: ROUTES.orders('current');
handleProtectedNavigate(target, 'your orders');
}}
/>
))}
</div>
{/* White Menu Card (4214:364) with Account Menu Rows */}
<div
style={{
width: '100%',
padding: '18px 13px',
borderRadius: 15,
backgroundColor: '#fbfbfc',
boxShadow: '0px 2px 13px rgba(180, 187, 200, 0.21)',
display: 'flex',
flexDirection: 'column',
gap: 19,
marginBottom: 15,
}}
>
{menuRows.map((row) => (
<AccountMenuRow
key={row.id}
row={row}
onClick={() => {
if (bare || row.id === 'acc-language') {
if (row.targetRoute) navigate(row.targetRoute);
return;
}
const labelMap: Record<string, string> = {
'acc-addresses': 'your saved addresses',
'acc-bookmarks': 'your saved items',
'acc-notifications': 'order notifications',
'acc-support': 'support requests',
'acc-faq': 'provider & account settings',
};
if (row.targetRoute) {
handleProtectedNavigate(
row.targetRoute,
labelMap[row.id] || row.title.toLowerCase()
);
}
}}
/>
))}
</div>
{/* Sign In Prompt Card when no authentication is provided by HabibApp (4214:464) */}
{(bare || !isUserAuthenticated) && (
<div
onClick={() => {
if (bare) {
navigate('/shop-home');
return;
}
openLoginModal({
title: 'Sign in with Habib',
description:
'Log in with your Habib account to access orders, saved items, addresses, and checkout.',
});
}}
style={{
width: '100%',
minHeight: 55,
padding: '10px 13px',
borderRadius: 15,
backgroundColor: '#ffffff',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
gap: 10,
}}
>
<div
style={{
width: 34,
height: 34,
borderRadius: 11,
backgroundColor: bare
? 'rgba(17, 17, 17, 0.1)'
: 'rgba(215, 142, 6, 0.14)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
}}
>
<img
src={
bare
? '/assets/images/icon-exit-booth-red.svg'
: '/assets/images/icon-account-avatar-gold.svg'
}
alt=""
style={{
width: 19,
height: 19,
}}
/>
</div>
<div
style={{
flex: 1,
minWidth: 0,
display: 'flex',
flexDirection: 'column',
gap: 2,
}}
>
<div
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 14,
lineHeight: '16px',
color: bare ? '#d44747' : '#d78e06',
}}
>
{bare ? 'Sign out' : 'Log in with Habib'}
</div>
<div
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 10,
lineHeight: '12.9px',
color: '#8b8b8b',
}}
>
{bare ? 'sign out from account' : 'connect your Habib account'}
</div>
</div>
</div>
)}
</div>
{/* Bottom Navigation Bar (4214:470) */}
<BottomNavBar
activeTab="account"
showCartBadge={bare ? true : cartItemsCount > 0}
/>
</MobileShell>
);
};