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.
 
 
 
 
 

987 lines
29 KiB

import React, { useEffect, useMemo, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { MobileShell } from '../../components/layout/MobileShell';
import { HabibCoinsBanner } from '../../components/account/HabibCoinsBanner';
import { ProviderBadgeCard } from '../../components/account/ProviderBadgeCard';
import { AccountMenuRow } from '../../components/account/AccountMenuRow';
import { EmptyStateBox } from '../../components/common/ShimmerSkeletons';
import {
type AccountMenuRowItem,
PROVIDER_BADGE_CARDS,
type ProviderBadgeCardItem,
PROVIDER_INFO_MENU_ROWS,
PROVIDER_SETTINGS_MENU_ROWS,
} from '../../data/accountData';
import { useShopApp } from '../../context/ShopAppContext';
import { useHardwareBackHandler } from '../../hooks/use-hardware-back-handler';
import { useSmartBack } from '../../hooks/useSmartBack';
import { resolveMediaUrl } from '../../lib/http';
import { isBareMode, ROUTES, USE_MOCK_DATA } from '../../lib/routes';
import {
useApplyProviderMutation,
useUpdateProfileMutation,
} from '../../lib/shopQueries';
import { openExternalUrl } from '../../lib/webview-actions';
/**
* Node 4214:10531 — `provider requst` (Provider Request & Profile Settings, 375×1768)
*/
export const ProviderRequestPage: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();
const bare = isBareMode(location.search);
const useMockFallback = bare || USE_MOCK_DATA;
const smartBack = useSmartBack(ROUTES.account);
const {
isUserAuthenticated,
requireAuth,
profile,
language,
orderCounters,
selectedAddress,
showToast,
} = useShopApp();
const updateProfileMutation = useUpdateProfileMutation();
const applyProviderMutation = useApplyProviderMutation();
const [fullName, setFullName] = useState('');
const [email, setEmail] = useState('');
const [phoneNumber, setPhoneNumber] = useState('');
const savingProfile = updateProfileMutation.isPending;
const [applyOpen, setApplyOpen] = useState(false);
const [storeName, setStoreName] = useState('');
const [storeDesc, setStoreDesc] = useState('');
const submittingProvider = applyProviderMutation.isPending;
useEffect(() => {
if (bare || !profile) return;
setFullName((prev) => prev || profile.full_name || '');
setEmail((prev) => prev || profile.email || '');
setPhoneNumber((prev) => prev || profile.phone_number || '');
}, [bare, profile]);
useHardwareBackHandler(() => {
if (!submittingProvider) setApplyOpen(false);
return true;
}, applyOpen);
const providerBadges = useMemo<ProviderBadgeCardItem[]>(() => {
if (bare || !profile?.provider_requests?.length) {
return useMockFallback ? PROVIDER_BADGE_CARDS : [];
}
const mapped = profile.provider_requests.slice(0, 4).map((req, idx): ProviderBadgeCardItem => {
const normalized = (req.status || '').toLowerCase();
const isApproved = normalized.includes('accept') || normalized.includes('approv');
const isDenied = normalized.includes('reject') || normalized.includes('deni');
const svcTitle =
req.service === 'shop'
? req.public_name || 'Habib Shop'
: req.service
? `Habib ${req.service.charAt(0).toUpperCase()}${req.service.slice(1)}`
: req.public_name || 'Habib Shop';
return {
id: `prov-live-${req.id}-${idx}`,
x: idx % 2 === 0 ? 28 : 194,
y: 532 + Math.floor(idx / 2) * 66,
width: 154,
innerLeft: 13,
innerWidth: 128,
statusText: isApproved ? 'Provider in' : isDenied ? 'Request Denied' : 'Under Review',
statusWidth: 96,
title: svcTitle,
titleWidth: 86,
gradientBg: isApproved
? 'linear-gradient(180deg, #203bcc 0%, #9961e7 100%)'
: isDenied
? 'linear-gradient(180deg, #cd4343 0%, #862222 100%)'
: 'linear-gradient(180deg, #eca533 0%, #ffd74b 100%)',
iconSrc: isApproved
? '/assets/images/icon-provider-events-calendar.svg'
: isDenied
? '/assets/images/icon-provider-maukibs-flag.svg'
: '/assets/images/icon-provider-requests-doc.svg',
iconLeft: 9,
iconTop: 12,
iconWidth: 16,
iconHeight: 16,
badgeType: isApproved ? 'approved' : isDenied ? 'denied' : 'review',
};
});
return mapped.length > 0 ? mapped : useMockFallback ? PROVIDER_BADGE_CARDS : [];
}, [bare, profile, useMockFallback]);
const settingsRows = useMemo<AccountMenuRowItem[]>(() => {
if (bare) return PROVIDER_SETTINGS_MENU_ROWS;
const langLabel =
language === 'fa' ? 'فارسی' : language === 'ar' ? 'العربية' : 'English';
const activeOrders = orderCounters?.in_progress ?? 0;
return PROVIDER_SETTINGS_MENU_ROWS.map((row) => {
if (row.id === 'prov-azan') {
return {
...row,
subtitle:
selectedAddress?.city || (useMockFallback ? row.subtitle : 'Not set'),
targetRoute: ROUTES.addresses,
};
}
if (row.id === 'prov-language') {
return {
...row,
subtitle: langLabel,
rightIconType: 'arrow-right',
targetRoute: ROUTES.settings,
};
}
if (row.id === 'prov-notifications') {
return {
...row,
badgeCount: activeOrders > 0 ? String(activeOrders) : undefined,
targetRoute: ROUTES.orders('current'),
};
}
return {
...row,
targetRoute: ROUTES.settings,
};
});
}, [bare, language, orderCounters, selectedAddress, useMockFallback]);
const infoRows = useMemo<AccountMenuRowItem[]>(() => {
if (bare) return PROVIDER_INFO_MENU_ROWS;
return PROVIDER_INFO_MENU_ROWS.map((row) => {
if (row.id === 'info-faqs') {
return { ...row, targetRoute: ROUTES.support };
}
if (row.id === 'info-about') {
return { ...row, targetRoute: ROUTES.stores };
}
return { ...row, targetRoute: '' };
});
}, [bare]);
const handleSaveProfile = async () => {
if (savingProfile) return;
if (!bare && !isUserAuthenticated) {
const authed = await requireAuth({
featureName: 'profile settings',
});
if (!authed) return;
}
try {
await updateProfileMutation.mutateAsync({
full_name: fullName.trim(),
email: email.trim(),
phone_number: phoneNumber.trim(),
});
showToast('Profile saved');
} catch (err) {
showToast(err instanceof Error ? err.message : 'Could not update profile');
}
};
const handleApplyProvider = async (e: React.FormEvent) => {
e.preventDefault();
if (!storeName.trim() || submittingProvider) return;
if (!bare && !isUserAuthenticated) {
const authed = await requireAuth({
featureName: 'provider application',
});
if (!authed) return;
}
try {
const res = await applyProviderMutation.mutateAsync({
store_name: storeName.trim(),
description: storeDesc.trim(),
});
showToast(res.message || 'Provider application submitted');
setApplyOpen(false);
setStoreName('');
setStoreDesc('');
} catch (err) {
showToast(err instanceof Error ? err.message : 'Could not submit application');
}
};
const avatarSrc =
!bare && profile?.avatar_url
? resolveMediaUrl(profile.avatar_url)
: useMockFallback
? '/assets/images/avatar-provider-ahd-art.png'
: '/assets/images/icon-account-avatar-gold.svg';
return (
<MobileShell width={375} height={1768} backgroundColor="#f5f5f5">
<div
style={{
display: 'flex',
flexDirection: 'column',
flex: 1,
padding: '21px var(--page-px) 44px',
gap: 23,
}}
>
{/* Top Bar: Back + Center Avatar + Edit/Settings */}
<div
style={{
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'space-between',
minHeight: 89,
}}
>
<button
type="button"
onClick={() => (bare ? navigate('/shop-account') : smartBack(ROUTES.account))}
aria-label="Back"
style={{
width: 40,
height: 40,
borderRadius: 15,
backgroundColor: '#ffffff',
border: 'none',
padding: 0,
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
}}
>
<img
src="/assets/images/icon-back-arrow-dark.svg"
alt=""
style={{
width: 18.22,
height: 15.21,
}}
/>
</button>
<img
src={avatarSrc}
alt="Profile"
style={{
marginTop: 5,
width: 84,
height: 84,
borderRadius: 80,
objectFit: 'cover',
flexShrink: 0,
}}
/>
<button
type="button"
onClick={() => navigate(bare ? '/language-setting' : ROUTES.settings)}
aria-label="Settings"
style={{
width: 40,
height: 40,
borderRadius: 15,
backgroundColor: '#ffffff',
border: 'none',
padding: 0,
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
}}
>
<img
src="/assets/images/icon-camera-edit-white.svg"
alt=""
style={{
width: 24,
height: 24,
}}
/>
</button>
</div>
{/* Form Card (4214:10540) */}
<div
style={{
width: '100%',
padding: '20px 12px',
borderRadius: 16.5,
backgroundColor: '#fbfbfc',
boxShadow: '0px 2px 13px rgba(71, 85, 105, 0.1)',
display: 'flex',
flexDirection: 'column',
gap: 20,
}}
>
{/* Field 1: Full Name */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<label
htmlFor="provider-full-name"
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 12,
lineHeight: '20px',
color: '#3d3d3d',
}}
>
Full Name
</label>
<input
id="provider-full-name"
type="text"
className="habib-search-input"
value={fullName}
onChange={(e) => setFullName(e.target.value)}
placeholder="Full Name"
style={{
width: '100%',
height: 55,
padding: '0 15px',
borderRadius: 11,
backgroundColor: '#fbfbfc',
border: '1px solid #8b8b8b',
boxSizing: 'border-box',
fontFamily: 'var(--font-sans)',
fontWeight: 400,
fontSize: 14,
lineHeight: '20px',
color: '#111111',
}}
/>
</div>
{/* Field 2: Email */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<label
htmlFor="provider-email"
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 12,
lineHeight: '20px',
color: '#111111',
}}
>
Email
</label>
<input
id="provider-email"
type="email"
className="habib-search-input"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Email"
style={{
width: '100%',
height: 55,
padding: '0 15px',
borderRadius: 11,
backgroundColor: '#fbfbfc',
border: '1px solid #8b8b8b',
boxSizing: 'border-box',
fontFamily: 'var(--font-sans)',
fontWeight: 400,
fontSize: 14,
lineHeight: '20px',
color: '#111111',
}}
/>
</div>
{/* Field 3: Phone Number */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
<label
htmlFor="provider-phone"
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 12,
lineHeight: '20px',
color: '#111111',
}}
>
Phone Number
</label>
<div
style={{
width: '100%',
height: 55,
padding: '0 15px',
borderRadius: 11,
backgroundColor: '#fbfbfc',
border: '1px solid #8b8b8b',
boxSizing: 'border-box',
display: 'flex',
alignItems: 'center',
gap: 8,
}}
>
<span
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 400,
fontSize: 14,
lineHeight: '20px',
color: '#292a2e',
flexShrink: 0,
}}
>
+23
</span>
<div
style={{
width: 1,
height: 17,
backgroundColor: '#292a2e',
flexShrink: 0,
}}
/>
<input
id="provider-phone"
type="tel"
className="habib-search-input"
value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)}
placeholder="Phone number"
style={{
flex: 1,
minWidth: 0,
height: '100%',
fontFamily: 'var(--font-sans)',
fontWeight: 400,
fontSize: 14,
lineHeight: '20px',
color: '#111111',
backgroundColor: 'transparent',
}}
/>
</div>
</div>
{!bare && (
<button
type="button"
onClick={handleSaveProfile}
disabled={savingProfile}
className="habib-cta-btn"
style={{
width: '100%',
height: 48,
borderRadius: 11,
color: '#fbfbfc',
fontFamily: 'var(--font-sans)',
fontWeight: 700,
fontSize: 14,
cursor: savingProfile ? 'not-allowed' : 'pointer',
opacity: savingProfile ? 0.7 : 1,
}}
>
{savingProfile ? 'Saving...' : 'Save Profile'}
</button>
)}
</div>
{/* Provider Status Card (4214:10539) */}
<div
style={{
width: '100%',
padding: '14px 12px 16px',
borderRadius: 16.5,
backgroundColor: '#fbfbfc',
boxShadow: '0px 2px 13px rgba(71, 85, 105, 0.1)',
display: 'flex',
flexDirection: 'column',
gap: 11,
}}
>
<div
style={{
padding: '0 3px',
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 14,
lineHeight: '16px',
color: '#73889d',
}}
>
Your are a provider in:
</div>
{providerBadges.length > 0 ? (
<div className="habib-provider-badges-grid">
{providerBadges.map((badge) => (
<ProviderBadgeCard key={badge.id} badge={badge} />
))}
</div>
) : (
<EmptyStateBox message="No active provider roles yet." compact />
)}
</div>
{/* Habib Coins Banner (4214:10558) */}
<HabibCoinsBanner />
{/* "Become a provider on Habib" Card (4214:10599) */}
<div
onClick={() => {
if (bare) {
navigate('/language-setting');
} else {
setApplyOpen(true);
}
}}
style={{
width: '100%',
minHeight: 55,
padding: '10px 13px',
borderRadius: 15,
backgroundColor: '#fbfbfc',
boxShadow: '0px 2px 13px rgba(180, 187, 200, 0.25)',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
gap: 10,
}}
>
<div
style={{
width: 34,
height: 34,
borderRadius: 11,
backgroundColor: 'rgba(17, 17, 17, 0.1)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
}}
>
<img
src="/assets/images/icon-menu-bookmark-subtract.svg"
alt=""
style={{
width: 15,
height: 18,
}}
/>
</div>
<div
style={{
flex: 1,
minWidth: 0,
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 14,
lineHeight: '16px',
color: '#111111',
}}
>
Become a provider on Habib
</div>
</div>
{/* "My Wallet ($24)" Card (4214:10615) */}
<div
onClick={() => {
if (!bare) {
navigate(ROUTES.settings);
}
}}
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: 'rgba(17, 17, 17, 0.1)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
}}
>
<img
src="/assets/images/icon-menu-edit-profile-user.svg"
alt=""
style={{
width: 18,
height: 18,
}}
/>
</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: '#111111',
}}
>
{useMockFallback ? 'My Wallet ($24)' : 'My Wallet ($0)'}
</div>
<div
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 10,
lineHeight: '12.9px',
color: '#73889d',
}}
>
Habib Income
</div>
</div>
<img
src="/assets/images/icon-menu-arrow-right.svg"
alt=""
style={{
width: 5,
height: 10,
flexShrink: 0,
}}
/>
</div>
{/* Settings Card (4214:10627) */}
<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,
}}
>
{settingsRows.map((row) => (
<AccountMenuRow key={row.id} row={row} />
))}
</div>
{/* Info Card (4214:10628) */}
<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,
}}
>
{infoRows.map((row) => (
<AccountMenuRow
key={row.id}
row={row}
onClick={
!bare && row.id === 'info-web'
? () => openExternalUrl('https://habibapp.com')
: undefined
}
/>
))}
</div>
{/* Delete Account Card (4214:10703) */}
<div
onClick={() => {
if (!bare) {
navigate(ROUTES.support);
showToast('Submit an account deletion request to Habib Support');
}
}}
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: 'rgba(17, 17, 17, 0.1)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
}}
>
<img
src="/assets/images/icon-logout-door-red.svg"
alt=""
style={{
width: 20,
height: 20,
}}
/>
</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: '#d44747',
}}
>
Delete Account
</div>
<div
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 600,
fontSize: 10,
lineHeight: '12.9px',
color: '#8b8b8b',
wordBreak: 'break-word',
}}
>
Permanently remove user and associated data
</div>
</div>
</div>
{/* Footer Version & Social Icons */}
<div
style={{
marginTop: 32,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 28,
}}
>
<div
style={{
fontFamily: 'var(--font-inter)',
fontWeight: 400,
fontSize: 10,
lineHeight: '20px',
color: '#203bcc',
textAlign: 'center',
}}
>
Habib | Version 2.1
</div>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: 27,
}}
>
<img
src="/assets/images/icon-social-instagram.svg"
alt="Instagram"
onClick={() => {
if (!bare) openExternalUrl('https://habibapp.com');
}}
style={{
width: 32,
height: 31,
cursor: 'pointer',
}}
/>
<img
src="/assets/images/icon-social-telegram.svg"
alt="Telegram"
onClick={() => {
if (!bare) openExternalUrl('https://habibapp.com');
}}
style={{
width: 32,
height: 31,
cursor: 'pointer',
}}
/>
<img
src="/assets/images/icon-social-youtube.svg"
alt="WhatsApp"
onClick={() => {
if (!bare) openExternalUrl('https://habibapp.com');
}}
style={{
width: 30.25,
height: 30.28,
cursor: 'pointer',
}}
/>
</div>
</div>
</div>
{/* Provider Application Bottom Sheet */}
{applyOpen && (
<div
onClick={() => {
if (!submittingProvider) setApplyOpen(false);
}}
style={{
position: 'fixed',
inset: 0,
backgroundColor: 'rgba(17, 17, 17, 0.9)',
zIndex: 60,
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
}}
>
<form
className="habib-bottom-sheet"
onClick={(e) => e.stopPropagation()}
onSubmit={handleApplyProvider}
style={{
padding: '22px var(--page-px) calc(24px + var(--safe-bottom, 0px))',
display: 'flex',
flexDirection: 'column',
gap: 14,
}}
>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<span
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 700,
fontSize: 15,
color: '#111111',
}}
>
Open a Habib Shop Booth
</span>
<button
type="button"
onClick={() => setApplyOpen(false)}
aria-label="Close"
style={{
width: 24,
height: 24,
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<img
src="/assets/images/icon-modal-close-cross.svg"
alt=""
style={{ width: 11.67, height: 11.67 }}
/>
</button>
</div>
<input
type="text"
required
placeholder="Store / Booth public name *"
value={storeName}
onChange={(e) => setStoreName(e.target.value)}
style={{
width: '100%',
height: 46,
borderRadius: 12,
backgroundColor: '#ffffff',
border: '1px solid #d7dbe2',
padding: '0 12px',
fontFamily: 'var(--font-sans)',
fontSize: 13,
color: '#111111',
}}
/>
<textarea
rows={3}
placeholder="Tell us about your products, craftsmanship, or bookstore"
value={storeDesc}
onChange={(e) => setStoreDesc(e.target.value)}
style={{
width: '100%',
borderRadius: 12,
backgroundColor: '#ffffff',
border: '1px solid #d7dbe2',
padding: '10px 12px',
fontFamily: 'var(--font-sans)',
fontSize: 13,
color: '#111111',
resize: 'none',
}}
/>
<button
type="submit"
disabled={submittingProvider || !storeName.trim()}
className="habib-cta-btn"
style={{
width: '100%',
height: 50,
borderRadius: 11,
color: '#fbfbfc',
fontFamily: 'var(--font-sans)',
fontWeight: 700,
fontSize: 15,
cursor: submittingProvider ? 'not-allowed' : 'pointer',
opacity: submittingProvider || !storeName.trim() ? 0.65 : 1,
}}
>
{submittingProvider ? 'Submitting...' : 'Submit Provider Request'}
</button>
</form>
</div>
)}
</MobileShell>
);
};