feat: update storefront — cart, checkout, services, topbar, credits & delivery APIs
This commit is contained in:
parent
3667f7a6a2
commit
f361732ff9
18 changed files with 811 additions and 200 deletions
|
|
@ -19,13 +19,21 @@ import {
|
||||||
Trash2,
|
Trash2,
|
||||||
Check,
|
Check,
|
||||||
ShieldCheck,
|
ShieldCheck,
|
||||||
|
Shield,
|
||||||
ShoppingBag,
|
ShoppingBag,
|
||||||
Loader2,
|
Loader2,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
X,
|
X,
|
||||||
|
Wallet,
|
||||||
|
Clock,
|
||||||
|
Coins,
|
||||||
|
Sparkles,
|
||||||
|
ArrowUpRight,
|
||||||
|
ArrowDownRight,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useAuthStore } from '@/store/authStore';
|
import { useAuthStore } from '@/store/authStore';
|
||||||
import { apiFetch, clearTokens } from '@/services/api/client';
|
import { apiFetch, clearTokens } from '@/services/api/client';
|
||||||
|
import { creditService, WalletSummary } from '@/services/api/creditService';
|
||||||
import { formatCurrency } from '@/lib/utils';
|
import { formatCurrency } from '@/lib/utils';
|
||||||
import GoogleAuthModal from '@/components/auth/GoogleAuthModal';
|
import GoogleAuthModal from '@/components/auth/GoogleAuthModal';
|
||||||
import { AnnouncementBar } from '@/layout/AnnouncementBar';
|
import { AnnouncementBar } from '@/layout/AnnouncementBar';
|
||||||
|
|
@ -37,12 +45,14 @@ import { PhoneInput, PincodeInput } from '@/components/PhoneInput';
|
||||||
import { validatePhone, validatePincode, validateAddress } from '@/lib/validation';
|
import { validatePhone, validatePincode, validateAddress } from '@/lib/validation';
|
||||||
import { FloatingButtons } from '@/components/FloatingButtons';
|
import { FloatingButtons } from '@/components/FloatingButtons';
|
||||||
|
|
||||||
type TabType = 'dashboard' | 'orders' | 'addresses' | 'settings';
|
type TabType = 'dashboard' | 'orders' | 'wallet' | 'addresses' | 'warranties' | 'settings';
|
||||||
|
|
||||||
const VALID_TABS: TabType[] = [
|
const VALID_TABS: TabType[] = [
|
||||||
'dashboard',
|
'dashboard',
|
||||||
'orders',
|
'orders',
|
||||||
|
'wallet',
|
||||||
'addresses',
|
'addresses',
|
||||||
|
'warranties',
|
||||||
'settings',
|
'settings',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -72,10 +82,23 @@ interface Order {
|
||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TABS: { id: TabType; label: string; icon: typeof User }[] = [
|
interface Warranty {
|
||||||
|
warranty_id: string;
|
||||||
|
reference_type: string;
|
||||||
|
reference_id: string;
|
||||||
|
serial_no_imei?: string;
|
||||||
|
start_date: string;
|
||||||
|
end_date: string;
|
||||||
|
status: string;
|
||||||
|
warranty_type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TABS: { id: TabType; label: string; icon: any }[] = [
|
||||||
{ id: 'dashboard', label: 'Dashboard', icon: User },
|
{ id: 'dashboard', label: 'Dashboard', icon: User },
|
||||||
{ id: 'orders', label: 'Order History', icon: Package },
|
{ id: 'orders', label: 'Order History', icon: Package },
|
||||||
|
{ id: 'wallet', label: 'Store Credits & Wallet', icon: Wallet },
|
||||||
{ id: 'addresses', label: 'Address Book', icon: MapPin },
|
{ id: 'addresses', label: 'Address Book', icon: MapPin },
|
||||||
|
{ id: 'warranties', label: 'My Warranties', icon: ShieldCheck },
|
||||||
{ id: 'settings', label: 'Settings', icon: Settings },
|
{ id: 'settings', label: 'Settings', icon: Settings },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -102,7 +125,9 @@ function AccountDashboardPage() {
|
||||||
|
|
||||||
const [profile, setProfile] = useState<any>(null);
|
const [profile, setProfile] = useState<any>(null);
|
||||||
const [addresses, setAddresses] = useState<Address[]>([]);
|
const [addresses, setAddresses] = useState<Address[]>([]);
|
||||||
|
const [warranties, setWarranties] = useState<Warranty[]>([]);
|
||||||
const [orders, setOrders] = useState<Order[]>([]);
|
const [orders, setOrders] = useState<Order[]>([]);
|
||||||
|
const [wallet, setWallet] = useState<WalletSummary | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const [addressModalOpen, setAddressModalOpen] = useState(false);
|
const [addressModalOpen, setAddressModalOpen] = useState(false);
|
||||||
|
|
@ -171,6 +196,12 @@ function AccountDashboardPage() {
|
||||||
|
|
||||||
const ords = await apiFetch<Order[]>('/api/v1/orders');
|
const ords = await apiFetch<Order[]>('/api/v1/orders');
|
||||||
setOrders(ords);
|
setOrders(ords);
|
||||||
|
|
||||||
|
const warrs = await apiFetch<Warranty[]>('/api/v1/warranties');
|
||||||
|
setWarranties(warrs);
|
||||||
|
|
||||||
|
const walletData = await creditService.getMyWallet().catch(() => null);
|
||||||
|
setWallet(walletData);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
setErrorMsg(err.message || 'Failed to retrieve account records.');
|
setErrorMsg(err.message || 'Failed to retrieve account records.');
|
||||||
|
|
@ -514,7 +545,35 @@ function AccountDashboardPage() {
|
||||||
manage your account here.
|
manage your account here.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||||
|
<div className="border border-[#e5e5e5] p-5 flex flex-col justify-between min-h-[160px] bg-gradient-to-br from-white to-emerald-50/30">
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<span className="text-[11px] font-semibold text-[#888] uppercase tracking-wide">
|
||||||
|
Store Credits
|
||||||
|
</span>
|
||||||
|
<span className="text-[9px] font-bold bg-emerald-100 text-emerald-800 px-2 py-0.5 rounded-full uppercase">
|
||||||
|
Spendable
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p className="text-[24px] font-black text-emerald-700 tracking-tight">
|
||||||
|
{formatCurrency(wallet?.active_balance || 0)}
|
||||||
|
</p>
|
||||||
|
{Boolean(wallet?.pending_balance && wallet.pending_balance > 0) && (
|
||||||
|
<p className="text-[12px] text-amber-700 font-medium mt-1 flex items-center gap-1">
|
||||||
|
<Clock className="w-3.5 h-3.5 text-amber-600 inline shrink-0" />
|
||||||
|
{formatCurrency(wallet?.pending_balance || 0)} pending unlock
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => goToTab('wallet')}
|
||||||
|
className="mt-4 text-emerald-700 hover:text-emerald-800 hover:underline text-[13px] font-semibold text-left w-max cursor-pointer flex items-center gap-1"
|
||||||
|
>
|
||||||
|
Open My Wallet <ArrowUpRight className="w-3.5 h-3.5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div className="border border-[#e5e5e5] p-5 flex flex-col justify-between min-h-[160px]">
|
<div className="border border-[#e5e5e5] p-5 flex flex-col justify-between min-h-[160px]">
|
||||||
<div>
|
<div>
|
||||||
<span className="text-[11px] font-semibold text-[#888] uppercase tracking-wide block mb-2.5">
|
<span className="text-[11px] font-semibold text-[#888] uppercase tracking-wide block mb-2.5">
|
||||||
|
|
@ -820,6 +879,223 @@ function AccountDashboardPage() {
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Store Credits & Wallet Tab */}
|
||||||
|
{activeTab === 'wallet' && (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Metric Stat Cards */}
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||||
|
<div className="border border-emerald-200/90 bg-gradient-to-br from-emerald-50/70 via-emerald-50/30 to-white p-5 rounded-lg">
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<span className="text-[11px] font-bold text-emerald-800 uppercase tracking-wider">
|
||||||
|
Spendable Credits
|
||||||
|
</span>
|
||||||
|
<div className="p-1.5 bg-emerald-100 rounded-md text-emerald-700">
|
||||||
|
<Wallet className="w-4 h-4" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-[26px] font-black text-emerald-700 tracking-tight">
|
||||||
|
{formatCurrency(wallet?.active_balance || 0)}
|
||||||
|
</p>
|
||||||
|
<p className="text-[11px] text-emerald-600 font-medium mt-1">
|
||||||
|
✓ Ready to apply at checkout
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border border-amber-200/90 bg-gradient-to-br from-amber-50/70 via-amber-50/30 to-white p-5 rounded-lg">
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<span className="text-[11px] font-bold text-amber-800 uppercase tracking-wider">
|
||||||
|
Pending Credits
|
||||||
|
</span>
|
||||||
|
<div className="p-1.5 bg-amber-100 rounded-md text-amber-700">
|
||||||
|
<Clock className="w-4 h-4" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-[26px] font-black text-amber-700 tracking-tight">
|
||||||
|
{formatCurrency(wallet?.pending_balance || 0)}
|
||||||
|
</p>
|
||||||
|
<p className="text-[11px] text-amber-600 font-medium mt-1">
|
||||||
|
⏳ Locked during return window
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border border-blue-200/90 bg-gradient-to-br from-blue-50/70 via-blue-50/30 to-white p-5 rounded-lg">
|
||||||
|
<div className="flex items-center justify-between mb-2">
|
||||||
|
<span className="text-[11px] font-bold text-blue-800 uppercase tracking-wider">
|
||||||
|
Lifetime Earned
|
||||||
|
</span>
|
||||||
|
<div className="p-1.5 bg-blue-100 rounded-md text-blue-700">
|
||||||
|
<Coins className="w-4 h-4" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-[26px] font-black text-blue-700 tracking-tight">
|
||||||
|
{formatCurrency(wallet?.lifetime_earned || 0)}
|
||||||
|
</p>
|
||||||
|
<p className="text-[11px] text-blue-600 font-medium mt-1">
|
||||||
|
Total rewards accumulated
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Educational Cashback Rules Card */}
|
||||||
|
<div className="border border-[#e5e5e5] bg-[#fafafa] p-5 rounded-lg space-y-3">
|
||||||
|
<h4 className="text-[13px] font-bold text-[#1a1a1a] flex items-center gap-2">
|
||||||
|
<Sparkles className="w-4 h-4 text-primary" />
|
||||||
|
How iFixKart Store Credits Work
|
||||||
|
</h4>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 text-[12px] text-gray-600">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="font-semibold text-[#1a1a1a]">1. 🛒 Purchases & Services</p>
|
||||||
|
<p className="leading-relaxed">
|
||||||
|
You earn 5% Store Credit cashback on all delivered product orders and repair jobs.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="font-semibold text-[#1a1a1a]">2. ⏳ Return Window Maturation</p>
|
||||||
|
<p className="leading-relaxed">
|
||||||
|
Credits remain pending during the active return window (e.g. 7 days for sales, 3 days for repairs).
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="font-semibold text-[#1a1a1a]">3. 🎁 1-Click Checkout Use</p>
|
||||||
|
<p className="leading-relaxed">
|
||||||
|
Once the window closes, credits unlock automatically to spendable balance for future checkout orders.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Transaction Ledger Table */}
|
||||||
|
<div className="border border-[#e5e5e5] bg-white rounded-lg overflow-hidden">
|
||||||
|
<div className="px-5 py-3.5 border-b border-[#e5e5e5] bg-gray-50 flex items-center justify-between">
|
||||||
|
<h4 className="text-[13px] font-bold text-[#1a1a1a]">
|
||||||
|
Credits Ledger & History
|
||||||
|
</h4>
|
||||||
|
<span className="text-[11px] text-gray-500">
|
||||||
|
{wallet?.transactions?.length || 0} transaction{wallet?.transactions?.length === 1 ? '' : 's'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!wallet?.transactions || wallet.transactions.length === 0 ? (
|
||||||
|
<div className="py-12 text-center text-gray-400">
|
||||||
|
<Wallet className="w-10 h-10 mx-auto text-gray-300 mb-2" />
|
||||||
|
<p className="text-[13px] font-semibold text-gray-600">No credit activity yet</p>
|
||||||
|
<p className="text-[12px] text-gray-400 mt-1">
|
||||||
|
Place an order or complete a repair service to start accumulating store credits!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-left text-[12px]">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-[#e5e5e5] bg-gray-50/50 text-[#666] font-semibold">
|
||||||
|
<th className="px-4 py-3">Date</th>
|
||||||
|
<th className="px-4 py-3">Description</th>
|
||||||
|
<th className="px-4 py-3">Reference</th>
|
||||||
|
<th className="px-4 py-3">Status</th>
|
||||||
|
<th className="px-4 py-3">Unlock Date</th>
|
||||||
|
<th className="px-4 py-3 text-right">Credit Amount</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-[#e5e5e5]">
|
||||||
|
{wallet.transactions.map((tx) => {
|
||||||
|
const isCredit = tx.credit_amount > 0;
|
||||||
|
return (
|
||||||
|
<tr key={tx.transaction_id} className="hover:bg-gray-50/80 transition-colors">
|
||||||
|
<td className="px-4 py-3 text-gray-500 whitespace-nowrap">
|
||||||
|
{tx.created_at ? new Date(tx.created_at).toLocaleDateString() : '—'}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 font-medium text-[#222]">
|
||||||
|
{tx.description || `${tx.transaction_type} for ${tx.reference_type}`}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 text-gray-600 whitespace-nowrap font-mono text-[11px]">
|
||||||
|
{tx.reference_no || tx.reference_id}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 whitespace-nowrap">
|
||||||
|
{tx.status === 'COMPLETED' || tx.status === 'MATURED' ? (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold bg-emerald-100 text-emerald-800">
|
||||||
|
✓ Active
|
||||||
|
</span>
|
||||||
|
) : tx.status === 'PENDING' ? (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold bg-amber-100 text-amber-800">
|
||||||
|
⏳ Pending
|
||||||
|
</span>
|
||||||
|
) : tx.status === 'VOIDED' ? (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold bg-red-100 text-red-800">
|
||||||
|
✕ Voided
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-bold bg-gray-100 text-gray-700">
|
||||||
|
{tx.status}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3 text-gray-500 whitespace-nowrap text-[11px]">
|
||||||
|
{tx.status === 'PENDING' && tx.matures_at ? (
|
||||||
|
<span className="text-amber-700 font-medium">
|
||||||
|
Unlocks {new Date(tx.matures_at).toLocaleDateString()}
|
||||||
|
</span>
|
||||||
|
) : tx.status === 'COMPLETED' || tx.status === 'MATURED' ? (
|
||||||
|
<span className="text-gray-400">Unlocked</span>
|
||||||
|
) : (
|
||||||
|
'—'
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className={`px-4 py-3 text-right font-bold whitespace-nowrap ${
|
||||||
|
isCredit ? 'text-emerald-600' : 'text-purple-600'
|
||||||
|
}`}>
|
||||||
|
{isCredit ? `+${formatCurrency(tx.credit_amount)}` : formatCurrency(tx.credit_amount)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Warranties */}
|
||||||
|
{activeTab === 'warranties' && (
|
||||||
|
<div className="space-y-4">
|
||||||
|
{warranties.length === 0 ? (
|
||||||
|
<div className="py-14 text-center border border-dashed border-[#e5e5e5]">
|
||||||
|
<ShieldCheck className="w-10 h-10 mx-auto text-gray-300 mb-3" />
|
||||||
|
<p className="text-[13px] font-semibold text-[#444]">
|
||||||
|
No active warranties found.
|
||||||
|
</p>
|
||||||
|
<p className="text-[12px] text-gray-500 mt-1">
|
||||||
|
Warranties for purchased products and repair services will appear here automatically.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
{warranties.map((warr) => (
|
||||||
|
<div key={warr.warranty_id} className="border border-[#e5e5e5] p-5 rounded-lg space-y-2">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<span className="font-bold text-[#1a1a1a] text-[13px]">
|
||||||
|
{warr.warranty_type}
|
||||||
|
</span>
|
||||||
|
<span className="text-[10px] font-bold px-2 py-0.5 rounded bg-emerald-100 text-emerald-800">
|
||||||
|
{warr.status}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{warr.serial_no_imei && (
|
||||||
|
<p className="text-[12px] text-gray-600 font-mono">
|
||||||
|
IMEI / Serial: {warr.serial_no_imei}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<p className="text-[11px] text-gray-500">
|
||||||
|
Valid: {new Date(warr.start_date).toLocaleDateString()} – {new Date(warr.end_date).toLocaleDateString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { useCartStore } from '@/store/cartStore';
|
import { useCartStore } from '@/store/cartStore';
|
||||||
|
|
@ -23,8 +24,7 @@ import {
|
||||||
Truck,
|
Truck,
|
||||||
Tag,
|
Tag,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
import { deliveryService, DeliverySettings } from '@/services/api/deliveryService';
|
||||||
const FREE_SHIPPING_THRESHOLD = 999;
|
|
||||||
|
|
||||||
function resolveItemImage(item: {
|
function resolveItemImage(item: {
|
||||||
product: { images?: { image_url?: string }[]; name?: string };
|
product: { images?: { image_url?: string }[]; name?: string };
|
||||||
|
|
@ -41,12 +41,25 @@ export default function CartPage() {
|
||||||
const removeFromCart = useCartStore((state) => state.removeFromCart);
|
const removeFromCart = useCartStore((state) => state.removeFromCart);
|
||||||
const updateQuantity = useCartStore((state) => state.updateQuantity);
|
const updateQuantity = useCartStore((state) => state.updateQuantity);
|
||||||
const getCartTotal = useCartStore((state) => state.getCartTotal);
|
const getCartTotal = useCartStore((state) => state.getCartTotal);
|
||||||
|
const [deliverySettings, setDeliverySettings] = useState<DeliverySettings | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
deliveryService.getDeliverySettings().then(setDeliverySettings).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const subtotal = getCartTotal();
|
const subtotal = getCartTotal();
|
||||||
const shipping = subtotal > 0 && subtotal < FREE_SHIPPING_THRESHOLD ? 15.0 : 0;
|
const isFreeDelivery = Boolean(
|
||||||
|
deliverySettings?.free_delivery_enabled &&
|
||||||
|
deliverySettings?.free_delivery_min_order_amount &&
|
||||||
|
subtotal >= deliverySettings.free_delivery_min_order_amount
|
||||||
|
);
|
||||||
|
const baseDeliveryFee = deliverySettings ? deliverySettings.delivery_charge : 99.0;
|
||||||
|
const shipping = subtotal > 0 ? (isFreeDelivery ? 0 : baseDeliveryFee) : 0;
|
||||||
const total = subtotal + shipping;
|
const total = subtotal + shipping;
|
||||||
const progressPercent = Math.min(100, (subtotal / FREE_SHIPPING_THRESHOLD) * 100);
|
|
||||||
const amountNeeded = Math.max(0, FREE_SHIPPING_THRESHOLD - subtotal);
|
const freeThreshold = deliverySettings?.free_delivery_min_order_amount || 999;
|
||||||
|
const progressPercent = Math.min(100, (subtotal / freeThreshold) * 100);
|
||||||
|
const amountNeeded = Math.max(0, freeThreshold - subtotal);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full min-h-screen bg-[#F8F9FB] flex flex-col">
|
<div className="w-full min-h-screen bg-[#F8F9FB] flex flex-col">
|
||||||
|
|
@ -198,7 +211,8 @@ export default function CartPage() {
|
||||||
Order summary
|
Order summary
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
{/* Free shipping progress */}
|
{/* Dynamic Free shipping progress (only when enabled by admin) */}
|
||||||
|
{deliverySettings?.free_delivery_enabled && (
|
||||||
<div className="rounded-lg bg-primary/5 border border-primary/10 p-3 space-y-2">
|
<div className="rounded-lg bg-primary/5 border border-primary/10 p-3 space-y-2">
|
||||||
<div className="flex items-start gap-2">
|
<div className="flex items-start gap-2">
|
||||||
<Truck className="w-4 h-4 text-primary shrink-0 mt-0.5" />
|
<Truck className="w-4 h-4 text-primary shrink-0 mt-0.5" />
|
||||||
|
|
@ -225,6 +239,7 @@ export default function CartPage() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="space-y-2.5 text-gray-500">
|
<div className="space-y-2.5 text-gray-500">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import {
|
||||||
type CustomerAddress,
|
type CustomerAddress,
|
||||||
type CheckoutCreateResponse,
|
type CheckoutCreateResponse,
|
||||||
} from '@/services/api/checkoutService';
|
} from '@/services/api/checkoutService';
|
||||||
|
import { deliveryService, DeliverySettings } from '@/services/api/deliveryService';
|
||||||
import GoogleAuthModal from '@/components/auth/GoogleAuthModal';
|
import GoogleAuthModal from '@/components/auth/GoogleAuthModal';
|
||||||
import { Header } from '@/layout/Header';
|
import { Header } from '@/layout/Header';
|
||||||
import { Footer } from '@/layout/Footer';
|
import { Footer } from '@/layout/Footer';
|
||||||
|
|
@ -47,8 +48,10 @@ import {
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
Trash2,
|
Trash2,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
|
Sparkles,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { motion, AnimatePresence } from 'framer-motion';
|
import { motion, AnimatePresence } from 'framer-motion';
|
||||||
|
import { creditService, WalletSummary } from '@/services/api/creditService';
|
||||||
|
|
||||||
type CheckoutStep = 'shipping' | 'payment' | 'review';
|
type CheckoutStep = 'shipping' | 'payment' | 'review';
|
||||||
|
|
||||||
|
|
@ -69,7 +72,10 @@ export default function CheckoutPage() {
|
||||||
const [authModalOpen, setAuthModalOpen] = useState(false);
|
const [authModalOpen, setAuthModalOpen] = useState(false);
|
||||||
const [addresses, setAddresses] = useState<CustomerAddress[]>([]);
|
const [addresses, setAddresses] = useState<CustomerAddress[]>([]);
|
||||||
const [selectedAddressId, setSelectedAddressId] = useState<string | null>(null);
|
const [selectedAddressId, setSelectedAddressId] = useState<string | null>(null);
|
||||||
const [paymentMethod, setPaymentMethod] = useState<'COD' | 'RAZORPAY'>('COD');
|
const paymentMethod = 'RAZORPAY';
|
||||||
|
const [wallet, setWallet] = useState<WalletSummary | null>(null);
|
||||||
|
const [deliverySettings, setDeliverySettings] = useState<DeliverySettings | null>(null);
|
||||||
|
const [useWalletCredits, setUseWalletCredits] = useState<boolean>(false);
|
||||||
const [loadingAddresses, setLoadingAddresses] = useState(false);
|
const [loadingAddresses, setLoadingAddresses] = useState(false);
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||||
|
|
@ -90,11 +96,26 @@ export default function CheckoutPage() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const subtotal = getCartTotal();
|
const subtotal = getCartTotal();
|
||||||
// Free shipping on INR orders over ₹999; ₹99 flat shipping for orders below ₹999
|
// Dynamic shipping calculation from backend admin settings
|
||||||
const shipping = subtotal > 0 && subtotal < 999 ? 99.0 : 0;
|
const isFreeDelivery = Boolean(
|
||||||
|
deliverySettings?.free_delivery_enabled &&
|
||||||
|
deliverySettings?.free_delivery_min_order_amount &&
|
||||||
|
subtotal >= deliverySettings.free_delivery_min_order_amount
|
||||||
|
);
|
||||||
|
const baseDeliveryFee = deliverySettings ? deliverySettings.delivery_charge : 99.0;
|
||||||
|
const shipping = subtotal > 0 ? (isFreeDelivery ? 0 : baseDeliveryFee) : 0;
|
||||||
|
|
||||||
const tax = Math.round(subtotal * 0.18 * 100) / 100;
|
const taxable_amount = subtotal / 1.18;
|
||||||
const total = subtotal + shipping + tax;
|
const tax = Math.round((subtotal - taxable_amount) * 100) / 100;
|
||||||
|
const grossTotal = Math.round(subtotal + shipping);
|
||||||
|
|
||||||
|
// Store credits deduction calculation
|
||||||
|
const availableCredits = wallet?.active_balance || 0;
|
||||||
|
const maxCreditsToApply = Math.min(availableCredits, grossTotal);
|
||||||
|
const appliedCredits = useWalletCredits ? maxCreditsToApply : 0;
|
||||||
|
const finalPayableTotal = Math.max(0, grossTotal - appliedCredits);
|
||||||
|
const total = finalPayableTotal;
|
||||||
|
const estimatedCashback = Math.round(finalPayableTotal * 0.05);
|
||||||
|
|
||||||
const hasOutOfStockItems = cart.some((item) =>
|
const hasOutOfStockItems = cart.some((item) =>
|
||||||
outOfStockVariantIds.has(item.selectedVariant.variant_id)
|
outOfStockVariantIds.has(item.selectedVariant.variant_id)
|
||||||
|
|
@ -102,6 +123,7 @@ export default function CheckoutPage() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void bootstrapAuth();
|
void bootstrapAuth();
|
||||||
|
deliveryService.getDeliverySettings().then(setDeliverySettings).catch(() => {});
|
||||||
}, [bootstrapAuth]);
|
}, [bootstrapAuth]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -122,6 +144,7 @@ export default function CheckoutPage() {
|
||||||
setAuthModalOpen(false);
|
setAuthModalOpen(false);
|
||||||
loadAddresses();
|
loadAddresses();
|
||||||
void syncAndValidateCart();
|
void syncAndValidateCart();
|
||||||
|
creditService.getMyWallet().then(setWallet).catch(() => null);
|
||||||
}, [isAuthenticated, authReady]);
|
}, [isAuthenticated, authReady]);
|
||||||
|
|
||||||
const syncAndValidateCart = async () => {
|
const syncAndValidateCart = async () => {
|
||||||
|
|
@ -358,13 +381,9 @@ export default function CheckoutPage() {
|
||||||
const orderData = await createCheckoutOrder({
|
const orderData = await createCheckoutOrder({
|
||||||
address_id: selectedAddressId,
|
address_id: selectedAddressId,
|
||||||
payment_method: paymentMethod,
|
payment_method: paymentMethod,
|
||||||
|
use_wallet_credits: useWalletCredits,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (paymentMethod === 'COD') {
|
|
||||||
clearCart();
|
|
||||||
setOrderResult(orderData);
|
|
||||||
setSubmitting(false);
|
|
||||||
} else {
|
|
||||||
const scriptLoaded = await loadRazorpayScript();
|
const scriptLoaded = await loadRazorpayScript();
|
||||||
if (!scriptLoaded) {
|
if (!scriptLoaded) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
@ -445,7 +464,6 @@ export default function CheckoutPage() {
|
||||||
|
|
||||||
const rzp = new (window as any).Razorpay(options);
|
const rzp = new (window as any).Razorpay(options);
|
||||||
rzp.open();
|
rzp.open();
|
||||||
}
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const detail = err.message || 'Failed to place order';
|
const detail = err.message || 'Failed to place order';
|
||||||
|
|
||||||
|
|
@ -835,65 +853,25 @@ export default function CheckoutPage() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<label
|
<div className="flex items-start gap-3 p-4 border border-primary bg-primary/5 ring-1 ring-primary rounded-lg transition-all">
|
||||||
className={`flex items-start gap-3 p-4 border rounded-lg cursor-pointer transition-all ${
|
<div className="mt-1 w-4 h-4 rounded-full border-2 border-primary flex items-center justify-center bg-primary">
|
||||||
paymentMethod === 'RAZORPAY'
|
<div className="w-1.5 h-1.5 rounded-full bg-white" />
|
||||||
? 'border-primary bg-primary/5 ring-1 ring-primary'
|
</div>
|
||||||
: 'border-gray-200 hover:border-gray-300'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="payment"
|
|
||||||
value="RAZORPAY"
|
|
||||||
checked={paymentMethod === 'RAZORPAY'}
|
|
||||||
onChange={() => setPaymentMethod('RAZORPAY')}
|
|
||||||
className="mt-1 accent-[var(--color-primary,#1976F3)] w-4 h-4"
|
|
||||||
/>
|
|
||||||
<div className="flex-1 space-y-1.5">
|
<div className="flex-1 space-y-1.5">
|
||||||
<div className="flex items-center justify-between gap-2">
|
<div className="flex items-center justify-between gap-2">
|
||||||
<span className="font-bold text-[#1a1a1a] text-[13px] flex items-center gap-2">
|
<span className="font-bold text-[#1a1a1a] text-[13px] flex items-center gap-2">
|
||||||
Online payment
|
Online payment
|
||||||
<span className="bg-emerald-50 text-emerald-700 text-[9px] font-bold px-1.5 py-0.5 rounded uppercase">
|
<span className="bg-emerald-50 text-emerald-700 text-[9px] font-bold px-1.5 py-0.5 rounded uppercase">
|
||||||
Instant
|
Instant & Secure
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<Wallet className="w-5 h-5 text-primary" />
|
<Wallet className="w-5 h-5 text-primary" />
|
||||||
</div>
|
</div>
|
||||||
<p className="text-[12px] text-gray-500 leading-relaxed">
|
<p className="text-[12px] text-gray-500 leading-relaxed">
|
||||||
Cards, net banking, wallets, or UPI (GPay, PhonePe,
|
Cards, UPI (GPay, PhonePe, Paytm), Netbanking, and Wallets via Razorpay.
|
||||||
Paytm).
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
|
||||||
|
|
||||||
<label
|
|
||||||
className={`flex items-start gap-3 p-4 border rounded-lg cursor-pointer transition-all ${
|
|
||||||
paymentMethod === 'COD'
|
|
||||||
? 'border-primary bg-primary/5 ring-1 ring-primary'
|
|
||||||
: 'border-gray-200 hover:border-gray-300'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="payment"
|
|
||||||
value="COD"
|
|
||||||
checked={paymentMethod === 'COD'}
|
|
||||||
onChange={() => setPaymentMethod('COD')}
|
|
||||||
className="mt-1 accent-[var(--color-primary,#1976F3)] w-4 h-4"
|
|
||||||
/>
|
|
||||||
<div className="flex-1 space-y-1.5">
|
|
||||||
<div className="flex items-center justify-between gap-2">
|
|
||||||
<span className="font-bold text-[#1a1a1a] text-[13px]">
|
|
||||||
Cash on delivery
|
|
||||||
</span>
|
|
||||||
<CreditCard className="w-5 h-5 text-gray-400" />
|
|
||||||
</div>
|
</div>
|
||||||
<p className="text-[12px] text-gray-500 leading-relaxed">
|
|
||||||
Pay in cash when your order arrives at the door.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center justify-between pt-4 border-t border-gray-100">
|
<div className="flex items-center justify-between pt-4 border-t border-gray-100">
|
||||||
|
|
@ -962,18 +940,20 @@ export default function CheckoutPage() {
|
||||||
Payment
|
Payment
|
||||||
</h4>
|
</h4>
|
||||||
<p className="font-semibold text-[#1a1a1a] flex items-center gap-2">
|
<p className="font-semibold text-[#1a1a1a] flex items-center gap-2">
|
||||||
{paymentMethod === 'RAZORPAY'
|
Online payment
|
||||||
? 'Online payment'
|
|
||||||
: 'Cash on delivery'}
|
|
||||||
<span className="text-[9px] font-bold px-1.5 py-0.5 rounded uppercase bg-primary/10 text-primary">
|
<span className="text-[9px] font-bold px-1.5 py-0.5 rounded uppercase bg-primary/10 text-primary">
|
||||||
{paymentMethod}
|
RAZORPAY
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p className="text-gray-500 text-[12px]">
|
<p className="text-gray-500 text-[12px]">
|
||||||
{paymentMethod === 'RAZORPAY'
|
Secured via Razorpay (UPI, Cards, Netbanking).
|
||||||
? 'Secured via Razorpay.'
|
|
||||||
: 'Pay in cash on delivery.'}
|
|
||||||
</p>
|
</p>
|
||||||
|
{useWalletCredits && appliedCredits > 0 && (
|
||||||
|
<div className="pt-1.5 flex items-center gap-1.5 text-[12px] font-bold text-emerald-700">
|
||||||
|
<Wallet className="w-3.5 h-3.5 text-emerald-600" />
|
||||||
|
<span>Store Credits Applied: -{formatCurrency(appliedCredits)}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -1112,13 +1092,13 @@ export default function CheckoutPage() {
|
||||||
|
|
||||||
<div className="space-y-2 text-[#1a1a1a] border-t border-gray-100 pt-3">
|
<div className="space-y-2 text-[#1a1a1a] border-t border-gray-100 pt-3">
|
||||||
<div className="flex justify-between text-gray-500">
|
<div className="flex justify-between text-gray-500">
|
||||||
<span>Subtotal</span>
|
<span>Item Total</span>
|
||||||
<span className="font-semibold text-[#1a1a1a]">
|
<span className="font-semibold text-[#1a1a1a]">
|
||||||
{formatCurrency(subtotal)}
|
{formatCurrency(subtotal)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between text-gray-500">
|
<div className="flex justify-between text-gray-500 text-[13px]">
|
||||||
<span>GST (18%)</span>
|
<span>Includes GST (18%)</span>
|
||||||
<span className="font-semibold text-[#1a1a1a]">
|
<span className="font-semibold text-[#1a1a1a]">
|
||||||
{formatCurrency(tax)}
|
{formatCurrency(tax)}
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -1137,12 +1117,57 @@ export default function CheckoutPage() {
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Store Credits Applied Row */}
|
||||||
|
{useWalletCredits && appliedCredits > 0 && (
|
||||||
|
<div className="flex justify-between text-emerald-700 font-semibold text-[13px] pt-1">
|
||||||
|
<span className="flex items-center gap-1">
|
||||||
|
<Wallet className="w-3.5 h-3.5" /> Store Credits Applied
|
||||||
|
</span>
|
||||||
|
<span>-{formatCurrency(appliedCredits)}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Store Credit Redemption Card */}
|
||||||
|
{Boolean(wallet && wallet.active_balance > 0) && (
|
||||||
|
<div className="p-3 bg-emerald-50/70 border border-emerald-200/90 rounded-lg space-y-1.5">
|
||||||
|
<label className="flex items-center justify-between cursor-pointer">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={useWalletCredits}
|
||||||
|
onChange={(e) => setUseWalletCredits(e.target.checked)}
|
||||||
|
className="w-4 h-4 rounded text-emerald-600 accent-emerald-600 focus:ring-emerald-500 cursor-pointer"
|
||||||
|
/>
|
||||||
|
<span className="text-[12px] font-bold text-emerald-950">
|
||||||
|
Redeem Store Credits
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="text-[11px] font-bold px-1.5 py-0.5 rounded bg-emerald-100 text-emerald-800">
|
||||||
|
{formatCurrency(wallet?.active_balance || 0)} Available
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<p className="text-[11px] text-emerald-800/80 pl-6 leading-tight">
|
||||||
|
{useWalletCredits
|
||||||
|
? `Deducting ${formatCurrency(appliedCredits)} from your order total.`
|
||||||
|
: 'Check to deduct available store credits from this order.'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="border-t border-gray-200 pt-3 flex justify-between items-center">
|
<div className="border-t border-gray-200 pt-3 flex justify-between items-center">
|
||||||
<span className="font-bold text-[#1a1a1a]">Total</span>
|
<span className="font-bold text-[#1a1a1a]">Payable Amount</span>
|
||||||
<span className="text-lg font-bold text-primary">
|
<span className="text-lg font-bold text-primary">
|
||||||
{formatCurrency(total)}
|
{formatCurrency(finalPayableTotal)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Cashback Reward Earn Preview */}
|
||||||
|
<div className="p-2.5 bg-blue-50/60 border border-blue-200/70 rounded-lg flex items-center gap-2 text-[11px] text-blue-900 font-medium">
|
||||||
|
<Sparkles className="w-4 h-4 text-blue-600 shrink-0" />
|
||||||
|
<span>
|
||||||
|
You will earn <strong>≈ {formatCurrency(estimatedCashback)}</strong> Store Credit (5%) after the return window.
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ export default function ServiceBookingPage() {
|
||||||
null | 'preparing' | 'verifying'
|
null | 'preparing' | 'verifying'
|
||||||
>(null);
|
>(null);
|
||||||
const paymentHandledRef = useRef(false);
|
const paymentHandledRef = useRef(false);
|
||||||
|
const isPrefillingRef = useRef(false);
|
||||||
|
|
||||||
// Dynamic CMS Layout Sections State
|
// Dynamic CMS Layout Sections State
|
||||||
const [layoutCMS, setLayoutCMS] = useState<any[]>([]);
|
const [layoutCMS, setLayoutCMS] = useState<any[]>([]);
|
||||||
|
|
@ -252,9 +253,73 @@ export default function ServiceBookingPage() {
|
||||||
void loadLocations();
|
void loadLocations();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Pre-fill from URL
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window === 'undefined') return;
|
||||||
|
const qs = new URLSearchParams(window.location.search);
|
||||||
|
const prefillBrandId = qs.get('brand_id');
|
||||||
|
const prefillSeriesId = qs.get('series_id');
|
||||||
|
const prefillModelId = qs.get('model_id');
|
||||||
|
const prefillServiceTypeId = qs.get('service_type_id');
|
||||||
|
const prefillVariantSku = qs.get('variant_sku');
|
||||||
|
|
||||||
|
if (prefillBrandId && prefillSeriesId && prefillModelId) {
|
||||||
|
isPrefillingRef.current = true;
|
||||||
|
const initFlow = async () => {
|
||||||
|
try {
|
||||||
|
const type = qs.get('device_type') || 'mobile';
|
||||||
|
setDeviceType(type);
|
||||||
|
|
||||||
|
const brandsData = await serviceBookingService.fetchBrands(type);
|
||||||
|
setBrands(brandsData);
|
||||||
|
const brandObj = brandsData.find((b: any) => b.brand_id === prefillBrandId);
|
||||||
|
if (brandObj) setSelectedBrand(brandObj);
|
||||||
|
|
||||||
|
const seriesData = await serviceBookingService.fetchSeriesByBrand(prefillBrandId, type);
|
||||||
|
setSeriesList(seriesData);
|
||||||
|
const seriesObj = seriesData.find((s: any) => s.series_id === prefillSeriesId);
|
||||||
|
if (seriesObj) setSelectedSeries(seriesObj);
|
||||||
|
|
||||||
|
const modelsData = await serviceBookingService.fetchModelsBySeries(prefillSeriesId);
|
||||||
|
setModels(modelsData);
|
||||||
|
const modelObj = modelsData.find((m: any) => m.model_id === prefillModelId);
|
||||||
|
if (modelObj) {
|
||||||
|
setSelectedModel(modelObj);
|
||||||
|
const config = await serviceBookingService.fetchRepairConfig(prefillModelId);
|
||||||
|
setRepairConfig(config);
|
||||||
|
|
||||||
|
if (config.categories && config.categories.length > 0) {
|
||||||
|
const categoryObj = prefillServiceTypeId
|
||||||
|
? config.categories.find((c: any) => c.service_type_id === prefillServiceTypeId)
|
||||||
|
: config.categories[0];
|
||||||
|
|
||||||
|
if (categoryObj) {
|
||||||
|
setSelectedCategory(categoryObj);
|
||||||
|
if (categoryObj.variants && categoryObj.variants.length > 0) {
|
||||||
|
const variantObj = prefillVariantSku
|
||||||
|
? categoryObj.variants.find((v: any) => v.name === prefillVariantSku)
|
||||||
|
: categoryObj.variants[0];
|
||||||
|
|
||||||
|
if (variantObj) {
|
||||||
|
setSelectedVariant(variantObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error prefilling data", err);
|
||||||
|
} finally {
|
||||||
|
isPrefillingRef.current = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
initFlow();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Load Brands when Device Type changes
|
// Load Brands when Device Type changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!deviceType) return;
|
if (!deviceType || isPrefillingRef.current) return;
|
||||||
loadBrands(deviceType);
|
loadBrands(deviceType);
|
||||||
}, [deviceType]);
|
}, [deviceType]);
|
||||||
|
|
||||||
|
|
@ -263,12 +328,14 @@ export default function ServiceBookingPage() {
|
||||||
try {
|
try {
|
||||||
const data = await serviceBookingService.fetchBrands(type);
|
const data = await serviceBookingService.fetchBrands(type);
|
||||||
setBrands(data);
|
setBrands(data);
|
||||||
|
if (!isPrefillingRef.current) {
|
||||||
setSelectedBrand(null);
|
setSelectedBrand(null);
|
||||||
setSelectedSeries(null);
|
setSelectedSeries(null);
|
||||||
setSelectedModel(null);
|
setSelectedModel(null);
|
||||||
setRepairConfig(null);
|
setRepairConfig(null);
|
||||||
setSelectedCategory(null);
|
setSelectedCategory(null);
|
||||||
setSelectedVariant(null);
|
setSelectedVariant(null);
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
toast.error(err.message || 'Failed to load brands.');
|
toast.error(err.message || 'Failed to load brands.');
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -476,6 +543,7 @@ export default function ServiceBookingPage() {
|
||||||
},
|
},
|
||||||
service_id: serviceId || 'OTHER_SERVICE',
|
service_id: serviceId || 'OTHER_SERVICE',
|
||||||
custom_service_name: customServiceName || undefined,
|
custom_service_name: customServiceName || undefined,
|
||||||
|
quoted_price: selectedVariant.price,
|
||||||
customer_name: custName.trim() || undefined,
|
customer_name: custName.trim() || undefined,
|
||||||
customer_email: custEmail.trim() || undefined,
|
customer_email: custEmail.trim() || undefined,
|
||||||
device_type: deviceType,
|
device_type: deviceType,
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,76 @@ function BookingSuccessContent() {
|
||||||
const [verifyState, setVerifyState] = useState<'idle' | 'verifying' | 'done'>(
|
const [verifyState, setVerifyState] = useState<'idle' | 'verifying' | 'done'>(
|
||||||
needsVerify ? 'verifying' : 'idle'
|
needsVerify ? 'verifying' : 'idle'
|
||||||
);
|
);
|
||||||
|
const [isRetrying, setIsRetrying] = useState(false);
|
||||||
|
|
||||||
|
const handleRetryPayment = async () => {
|
||||||
|
if (!jobId && !jobNoParam) return;
|
||||||
|
setIsRetrying(true);
|
||||||
|
try {
|
||||||
|
const loadRazorpayScript = (): Promise<boolean> => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (document.querySelector('script[src="https://checkout.razorpay.com/v1/checkout.js"]')) {
|
||||||
|
resolve(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const script = document.createElement('script');
|
||||||
|
script.src = 'https://checkout.razorpay.com/v1/checkout.js';
|
||||||
|
script.onload = () => resolve(true);
|
||||||
|
script.onerror = () => resolve(false);
|
||||||
|
document.body.appendChild(script);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const rzpLoaded = await loadRazorpayScript();
|
||||||
|
if (!rzpLoaded) {
|
||||||
|
throw new Error('Razorpay SDK failed to load. Please check your network connection.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we don't have jobDetails loaded yet, use the query param ID
|
||||||
|
const targetId = jobDetails?.job_id || jobId || jobNoParam;
|
||||||
|
|
||||||
|
const pmtOrder = await serviceBookingService.initiateServicePayment(targetId, {
|
||||||
|
payment_type: 'ADVANCE',
|
||||||
|
amount: Math.max(1, Math.round(qAmount > 0 ? qAmount : 100)), // fallback to query amount or minimum
|
||||||
|
provider: 'RAZORPAY',
|
||||||
|
});
|
||||||
|
|
||||||
|
const rzpKey = pmtOrder.rzp_key_id || process.env.NEXT_PUBLIC_RAZORPAY_KEY_ID || 'rzp_test_TTUzPFYF0hRV89';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
key: rzpKey,
|
||||||
|
amount: pmtOrder.amount,
|
||||||
|
currency: pmtOrder.currency || 'INR',
|
||||||
|
name: 'iFixKart Commerce',
|
||||||
|
description: `Advance Booking Deposit (${jobNoParam})`,
|
||||||
|
order_id: pmtOrder.rzp_order_id,
|
||||||
|
redirect: false,
|
||||||
|
handler: (response: any) => {
|
||||||
|
const qs = new URLSearchParams(searchParams.toString());
|
||||||
|
qs.set('payment_id', String(pmtOrder.payment_id || ''));
|
||||||
|
qs.set('amount', String(pmtOrder.amount));
|
||||||
|
qs.set('method', 'Razorpay');
|
||||||
|
qs.set('rzp_payment_id', String(response.razorpay_payment_id || ''));
|
||||||
|
qs.set('rzp_order_id', String(response.razorpay_order_id || ''));
|
||||||
|
qs.set('rzp_signature', String(response.razorpay_signature || ''));
|
||||||
|
qs.set('verify', '1');
|
||||||
|
router.replace(`/services/success?${qs.toString()}`);
|
||||||
|
},
|
||||||
|
modal: {
|
||||||
|
escape: true,
|
||||||
|
handleback: true,
|
||||||
|
confirm_close: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const rzp = new (window as any).Razorpay(options);
|
||||||
|
rzp.open();
|
||||||
|
} catch (err: any) {
|
||||||
|
toast.error(err.message || 'Failed to initiate payment retry.');
|
||||||
|
} finally {
|
||||||
|
setIsRetrying(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void bootstrapAuth();
|
void bootstrapAuth();
|
||||||
|
|
@ -364,6 +434,23 @@ function BookingSuccessContent() {
|
||||||
? 'is saved. Complete the advance payment to lock your technician slot.'
|
? 'is saved. Complete the advance payment to lock your technician slot.'
|
||||||
: 'is confirmed. Your advance payment is complete and our team is preparing your repair schedule.'}
|
: 'is confirmed. Your advance payment is complete and our team is preparing your repair schedule.'}
|
||||||
</p>
|
</p>
|
||||||
|
{isPending && (
|
||||||
|
<div className="mt-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={isRetrying}
|
||||||
|
onClick={handleRetryPayment}
|
||||||
|
className="px-6 py-2.5 bg-primary hover:bg-primary-hover text-white font-bold text-[13px] rounded-lg flex items-center gap-2"
|
||||||
|
>
|
||||||
|
{isRetrying ? (
|
||||||
|
<Loader2 className="w-4 h-4 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<CreditCard className="w-4 h-4" />
|
||||||
|
)}
|
||||||
|
{isRetrying ? 'Loading...' : 'Complete Payment Now'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ import {
|
||||||
HelpCircle,
|
HelpCircle,
|
||||||
GitCompare,
|
GitCompare,
|
||||||
ChevronUp,
|
ChevronUp,
|
||||||
ChevronDown
|
ChevronDown,
|
||||||
|
Wrench,
|
||||||
|
Sparkles,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
|
|
||||||
interface ProductInteractiveGridProps {
|
interface ProductInteractiveGridProps {
|
||||||
|
|
@ -247,6 +249,18 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
}
|
}
|
||||||
}, [galleryImages, selectedImage, failedImages, selectedVariantIndex, selectedVariant?.variant_id]);
|
}, [galleryImages, selectedImage, failedImages, selectedVariantIndex, selectedVariant?.variant_id]);
|
||||||
|
|
||||||
|
const handleBookService = () => {
|
||||||
|
if (!selectedVariant) return;
|
||||||
|
const qs = new URLSearchParams();
|
||||||
|
if (product.device_type) qs.set('device_type', product.device_type);
|
||||||
|
if (product.brand_id) qs.set('brand_id', product.brand_id);
|
||||||
|
if (product.device_series_id) qs.set('series_id', product.device_series_id);
|
||||||
|
if (product.device_model_id) qs.set('model_id', product.device_model_id);
|
||||||
|
if (product.mapped_service_category_id) qs.set('service_type_id', product.mapped_service_category_id);
|
||||||
|
qs.set('variant_sku', selectedVariant.sku);
|
||||||
|
router.push(`/services?${qs.toString()}`);
|
||||||
|
};
|
||||||
|
|
||||||
const handleAddToCart = () => {
|
const handleAddToCart = () => {
|
||||||
if (selectedVariant) {
|
if (selectedVariant) {
|
||||||
const available = selectedVariant.available_stock;
|
const available = selectedVariant.available_stock;
|
||||||
|
|
@ -434,6 +448,16 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Store Credit Cashback Incentive Badge */}
|
||||||
|
{selectedPrice > 0 && (
|
||||||
|
<div className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-emerald-50 border border-emerald-200/80 text-emerald-800 text-[12px] font-semibold">
|
||||||
|
<Sparkles size={14} className="text-emerald-600 shrink-0" />
|
||||||
|
<span>
|
||||||
|
Earn 5% Store Credit (≈ {formatCurrency(Math.round(selectedPrice * 0.05))}) after 7-day return window
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Interactive Variant Attribute Selectors */}
|
{/* Interactive Variant Attribute Selectors */}
|
||||||
{product.variants && product.variants.length > 0 && (
|
{product.variants && product.variants.length > 0 && (
|
||||||
<div className="space-y-4 pt-2 pb-2 border-t border-b border-gray-100 my-4">
|
<div className="space-y-4 pt-2 pb-2 border-t border-b border-gray-100 my-4">
|
||||||
|
|
@ -589,8 +613,8 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
onClick={() => toggleWishlist(product)}
|
onClick={() => toggleWishlist(product)}
|
||||||
className={`flex items-center gap-1.5 cursor-pointer ${isInWishlist ? 'text-primary' : 'hover:text-primary'}`}
|
className={`flex items-center gap-1.5 cursor-pointer ${isInWishlist ? 'text-primary' : 'hover:text-primary'}`}
|
||||||
>
|
>
|
||||||
<Heart size={14} className={isInWishlist ? 'fill-[#e4382f] text-[#e4382f]' : ''} />
|
<Heart size={14} className={isInWishlist ? 'fill-primary text-primary' : ''} />
|
||||||
Wishlist
|
{isInWishlist ? 'Saved' : 'Wishlist'}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -607,6 +631,31 @@ export const ProductInteractiveGrid: React.FC<ProductInteractiveGridProps> = ({
|
||||||
Share
|
Share
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{product.is_service_booking && (
|
||||||
|
<div className="mt-4 p-4 border border-emerald-200 bg-emerald-50 rounded-xl flex flex-col gap-3">
|
||||||
|
<div className="flex items-start gap-3">
|
||||||
|
<Wrench className="w-5 h-5 text-emerald-600 mt-0.5 shrink-0" />
|
||||||
|
<div>
|
||||||
|
<h4 className="font-semibold text-emerald-900 text-sm">Need Professional Installation?</h4>
|
||||||
|
<p className="text-xs text-emerald-700 mt-1">
|
||||||
|
Book a doorstep or store service for this part. We will assign an expert engineer to install it for you.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
disabled={!selectedVariant}
|
||||||
|
onClick={handleBookService}
|
||||||
|
className={`w-full font-semibold text-sm py-2.5 px-6 rounded-md transition-colors flex items-center justify-center gap-2 cursor-pointer ${
|
||||||
|
selectedVariant
|
||||||
|
? 'bg-emerald-600 hover:bg-emerald-700 text-white shadow-sm'
|
||||||
|
: 'bg-emerald-200 text-emerald-500 cursor-not-allowed'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Book Service Now
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@
|
||||||
*/
|
*/
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { X, Trash2, Plus, Minus, ShoppingBag, ArrowRight, Truck } from 'lucide-react';
|
import { X, Trash2, Plus, Minus, ShoppingBag, ArrowRight, Truck } from 'lucide-react';
|
||||||
import { useCartStore } from '@/store/cartStore';
|
import { useCartStore } from '@/store/cartStore';
|
||||||
import { formatCurrency, getImageUrl } from '@/lib/utils';
|
import { formatCurrency, getImageUrl } from '@/lib/utils';
|
||||||
import { requireLoginForCheckout } from '@/lib/requireLoginForCheckout';
|
import { requireLoginForCheckout } from '@/lib/requireLoginForCheckout';
|
||||||
|
import { deliveryService, DeliverySettings } from '@/services/api/deliveryService';
|
||||||
|
|
||||||
function resolveItemImage(item: {
|
function resolveItemImage(item: {
|
||||||
product: { images?: { image_url?: string }[]; name?: string };
|
product: { images?: { image_url?: string }[]; name?: string };
|
||||||
|
|
@ -27,9 +28,11 @@ export function CartDrawer() {
|
||||||
const removeFromCart = useCartStore((state) => state.removeFromCart);
|
const removeFromCart = useCartStore((state) => state.removeFromCart);
|
||||||
const updateQuantity = useCartStore((state) => state.updateQuantity);
|
const updateQuantity = useCartStore((state) => state.updateQuantity);
|
||||||
const getCartTotal = useCartStore((state) => state.getCartTotal);
|
const getCartTotal = useCartStore((state) => state.getCartTotal);
|
||||||
|
const [deliverySettings, setDeliverySettings] = useState<DeliverySettings | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isOpen) return;
|
if (!isOpen) return;
|
||||||
|
deliveryService.getDeliverySettings().then(setDeliverySettings).catch(() => {});
|
||||||
const prev = document.body.style.overflow;
|
const prev = document.body.style.overflow;
|
||||||
document.body.style.overflow = 'hidden';
|
document.body.style.overflow = 'hidden';
|
||||||
const onKey = (e: KeyboardEvent) => {
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
|
@ -46,7 +49,7 @@ export function CartDrawer() {
|
||||||
|
|
||||||
const total = getCartTotal();
|
const total = getCartTotal();
|
||||||
const itemCount = cart.reduce((sum, i) => sum + (i.quantity || 1), 0);
|
const itemCount = cart.reduce((sum, i) => sum + (i.quantity || 1), 0);
|
||||||
const freeShippingThreshold = 999;
|
const freeShippingThreshold = deliverySettings?.free_delivery_min_order_amount || 999;
|
||||||
const progressPercent = Math.min(100, (total / freeShippingThreshold) * 100);
|
const progressPercent = Math.min(100, (total / freeShippingThreshold) * 100);
|
||||||
const amountNeeded = Math.max(0, freeShippingThreshold - total);
|
const amountNeeded = Math.max(0, freeShippingThreshold - total);
|
||||||
|
|
||||||
|
|
@ -80,8 +83,8 @@ export function CartDrawer() {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Free shipping bar */}
|
{/* Dynamic Free shipping bar (only when enabled by admin) */}
|
||||||
{cart.length > 0 && (
|
{deliverySettings?.free_delivery_enabled && cart.length > 0 && (
|
||||||
<div className="shrink-0 px-4 py-3 bg-[#f0f7ff] border-b border-[#d6e8fb]">
|
<div className="shrink-0 px-4 py-3 bg-[#f0f7ff] border-b border-[#d6e8fb]">
|
||||||
<div className="flex items-start gap-2 text-[12px] font-semibold text-[#1a1a1a] mb-2">
|
<div className="flex items-start gap-2 text-[12px] font-semibold text-[#1a1a1a] mb-2">
|
||||||
<Truck className="w-4 h-4 text-primary shrink-0 mt-0.5" />
|
<Truck className="w-4 h-4 text-primary shrink-0 mt-0.5" />
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ export function TopBar() {
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right Free Shipping Text */}
|
{/* Right Delivery Text */}
|
||||||
<div className="hidden md:flex items-center gap-1.5 text-[11px] font-semibold text-gray-700">
|
<div className="hidden md:flex items-center gap-1.5 text-[11px] font-semibold text-gray-700">
|
||||||
<span>Free Shipping on orders over ₹999!</span>
|
<span>Express Pan-India Delivery | 100% Genuine Spare Parts</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ export const DEFAULT_FAQ_PAGE: FaqPageData = {
|
||||||
{
|
{
|
||||||
question: 'What payment modes are available for refurbished mobiles?',
|
question: 'What payment modes are available for refurbished mobiles?',
|
||||||
answer:
|
answer:
|
||||||
'You can pay with Visa and Mastercard debit or credit cards, UPI, net banking, RuPay, and Razorpay-supported wallets. Cash on delivery may not be available on every listing.',
|
'You can pay with Visa and Mastercard debit or credit cards, UPI, net banking, RuPay, and Razorpay-supported wallets. All orders require secure online prepaid payment.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
question: 'Will I get a warranty card with the product?',
|
question: 'Will I get a warranty card with the product?',
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ export const DEFAULT_PROMO_CARDS: any[] = [];
|
||||||
export const DEFAULT_PROMO_BANNERS: any[] = [];
|
export const DEFAULT_PROMO_BANNERS: any[] = [];
|
||||||
|
|
||||||
export const DEFAULT_TRUST_FEATURES = [
|
export const DEFAULT_TRUST_FEATURES = [
|
||||||
{ title: 'Free Shipping', desc: 'On orders over ₹1,000', icon: 'Truck' },
|
{ title: 'Fast Express Shipping', desc: 'Pan-India Insured Delivery', icon: 'Truck' },
|
||||||
|
|
||||||
{ title: 'Flexible & Easy Return', desc: 'Return within 14 days', icon: 'RefreshCcw' },
|
{ title: 'Flexible & Easy Return', desc: 'Return within 14 days', icon: 'RefreshCcw' },
|
||||||
{ title: '24/7 Support Services', desc: 'Any Time Customer Support', icon: 'Headphones' },
|
{ title: '24/7 Support Services', desc: 'Any Time Customer Support', icon: 'Headphones' },
|
||||||
|
|
@ -173,7 +173,7 @@ export const DEFAULT_SECTION_TITLES: Record<string, { title: string; subtitle: s
|
||||||
},
|
},
|
||||||
trust_badges: {
|
trust_badges: {
|
||||||
title: 'Certified Quality Guarantee',
|
title: 'Certified Quality Guarantee',
|
||||||
subtitle: 'Free Shipping, 1-Year Warranty & 24/7 Technical Support',
|
subtitle: 'Express Delivery, 1-Year Warranty & 24/7 Technical Support',
|
||||||
},
|
},
|
||||||
announcement_bar: {
|
announcement_bar: {
|
||||||
title: 'Top Navigation Links',
|
title: 'Top Navigation Links',
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ export function buildPaymentsDoc(storeName: string): PaymentsDoc {
|
||||||
title: 'Accepted methods',
|
title: 'Accepted methods',
|
||||||
paragraphs: [
|
paragraphs: [
|
||||||
`At checkout you can pay with Visa and Mastercard debit or credit cards, RuPay, UPI, net banking, and Razorpay-supported wallets. The exact list on a product or repair booking is what we accept for that order.`,
|
`At checkout you can pay with Visa and Mastercard debit or credit cards, RuPay, UPI, net banking, and Razorpay-supported wallets. The exact list on a product or repair booking is what we accept for that order.`,
|
||||||
'Cash on delivery is not available on every listing. If COD is offered, it is shown before you confirm the order.',
|
'All orders are processed via secure online payment gateways (Cards, UPI, Netbanking, Wallets). Cash on delivery (COD) is not accepted.',
|
||||||
'Split payments across cards, UPI, and wallets are not supported. Complete the order with a single method.',
|
'Split payments across cards, UPI, and wallets are not supported. Complete the order with a single method.',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ const REFERENCE_FEATURES: FeatureItem[] = [
|
||||||
{
|
{
|
||||||
id: 'shipping',
|
id: 'shipping',
|
||||||
icon: 'shipping',
|
icon: 'shipping',
|
||||||
title: 'Free Shipping',
|
title: 'Fast Express Delivery',
|
||||||
desc: 'On order over $100',
|
desc: 'Pan-India Insured Shipping',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'return',
|
id: 'return',
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,9 @@ export interface ProductResponse {
|
||||||
color?: string | null;
|
color?: string | null;
|
||||||
colors?: string[];
|
colors?: string[];
|
||||||
brand_name?: string | null;
|
brand_name?: string | null;
|
||||||
|
device_type?: string | null;
|
||||||
|
mapped_service_category_id?: string | null;
|
||||||
|
is_service_booking?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeviceModelResponse {
|
export interface DeviceModelResponse {
|
||||||
|
|
|
||||||
|
|
@ -58,13 +58,15 @@ export async function createCheckoutOrder(payload: {
|
||||||
address_id: string;
|
address_id: string;
|
||||||
payment_method?: string;
|
payment_method?: string;
|
||||||
coupon_code?: string;
|
coupon_code?: string;
|
||||||
|
use_wallet_credits?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return apiFetch<CheckoutCreateResponse>('/api/v1/checkout/create', {
|
return apiFetch<CheckoutCreateResponse>('/api/v1/checkout/create', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
address_id: payload.address_id,
|
address_id: payload.address_id,
|
||||||
payment_method: payload.payment_method || 'COD',
|
payment_method: payload.payment_method || 'RAZORPAY',
|
||||||
coupon_code: payload.coupon_code,
|
coupon_code: payload.coupon_code,
|
||||||
|
use_wallet_credits: Boolean(payload.use_wallet_credits),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
57
services/api/creditService.ts
Normal file
57
services/api/creditService.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { apiFetch } from './client';
|
||||||
|
|
||||||
|
export interface WalletTransaction {
|
||||||
|
transaction_id: string;
|
||||||
|
transaction_type: 'EARN' | 'REDEEM' | 'REFUND' | 'ADJUSTMENT' | string;
|
||||||
|
reference_type: string;
|
||||||
|
reference_id: string;
|
||||||
|
reference_no: string;
|
||||||
|
base_amount: number;
|
||||||
|
percentage_applied: number | null;
|
||||||
|
credit_amount: number;
|
||||||
|
status: 'PENDING' | 'MATURED' | 'COMPLETED' | 'VOIDED' | 'EXPIRED' | string;
|
||||||
|
matures_at: string | null;
|
||||||
|
matured_at: string | null;
|
||||||
|
voided_at: string | null;
|
||||||
|
void_reason: string | null;
|
||||||
|
description: string | null;
|
||||||
|
created_at: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WalletSummary {
|
||||||
|
wallet_id: string;
|
||||||
|
customer_id: string;
|
||||||
|
active_balance: number;
|
||||||
|
pending_balance: number;
|
||||||
|
lifetime_earned: number;
|
||||||
|
lifetime_redeemed: number;
|
||||||
|
currency: string;
|
||||||
|
is_locked: boolean;
|
||||||
|
transactions: WalletTransaction[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CreditSettings {
|
||||||
|
credits_enabled: boolean;
|
||||||
|
credits_sales_percentage: number;
|
||||||
|
credits_sales_return_window_days: number;
|
||||||
|
credits_service_percentage: number;
|
||||||
|
credits_service_claim_window_days: number;
|
||||||
|
credits_minimum_order_value: number;
|
||||||
|
credits_expiry_days: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const creditService = {
|
||||||
|
/**
|
||||||
|
* Retrieves the current customer's spendable balance, pending balance, and transaction history.
|
||||||
|
*/
|
||||||
|
async getMyWallet(): Promise<WalletSummary> {
|
||||||
|
return apiFetch<WalletSummary>('/api/v1/credits/my-wallet');
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves current credit & return window parameters.
|
||||||
|
*/
|
||||||
|
async getCreditSettings(): Promise<CreditSettings> {
|
||||||
|
return apiFetch<CreditSettings>('/api/v1/credits/settings', { skipAuth: true });
|
||||||
|
},
|
||||||
|
};
|
||||||
25
services/api/deliveryService.ts
Normal file
25
services/api/deliveryService.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { apiFetch } from './client';
|
||||||
|
|
||||||
|
export interface DeliverySettings {
|
||||||
|
delivery_charge: number;
|
||||||
|
free_delivery_enabled: boolean;
|
||||||
|
free_delivery_min_order_amount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const deliveryService = {
|
||||||
|
/**
|
||||||
|
* Retrieves active delivery fee and dynamic free delivery configuration.
|
||||||
|
*/
|
||||||
|
async getDeliverySettings(): Promise<DeliverySettings> {
|
||||||
|
try {
|
||||||
|
return await apiFetch<DeliverySettings>('/api/v1/settings/delivery', { skipAuth: true });
|
||||||
|
} catch {
|
||||||
|
// Fallback defaults if offline or uninitialized
|
||||||
|
return {
|
||||||
|
delivery_charge: 99.0,
|
||||||
|
free_delivery_enabled: false,
|
||||||
|
free_delivery_min_order_amount: 999.0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
@ -65,6 +65,7 @@ export interface ServiceBookingPayload {
|
||||||
};
|
};
|
||||||
service_id?: string;
|
service_id?: string;
|
||||||
custom_service_name?: string;
|
custom_service_name?: string;
|
||||||
|
quoted_price?: number;
|
||||||
customer_name?: string;
|
customer_name?: string;
|
||||||
customer_email?: string;
|
customer_email?: string;
|
||||||
customer_phone?: string;
|
customer_phone?: string;
|
||||||
|
|
@ -402,7 +403,7 @@ export const serviceBookingService = {
|
||||||
serviceId
|
serviceId
|
||||||
)}&target_date=${encodeURIComponent(targetDate)}`
|
)}&target_date=${encodeURIComponent(targetDate)}`
|
||||||
);
|
);
|
||||||
if (Array.isArray(data) && data.length > 0) return data;
|
if (Array.isArray(data)) return data;
|
||||||
} catch {
|
} catch {
|
||||||
/* fall through */
|
/* fall through */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,7 @@ export const MOCK_REVIEWS: ProductReview[] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export const MOCK_TRUST_BADGES: TrustBadge[] = [
|
export const MOCK_TRUST_BADGES: TrustBadge[] = [
|
||||||
{ id: 'tb1', title: 'Free Shipping', subtitle: 'On order over $100', icon: 'truck' },
|
{ id: 'tb1', title: 'Express Delivery', subtitle: 'Fast & Insured Pan-India', icon: 'truck' },
|
||||||
{ id: 'tb2', title: 'Flexible & Easy Return', subtitle: 'Return within 14 days', icon: 'refresh' },
|
{ id: 'tb2', title: 'Flexible & Easy Return', subtitle: 'Return within 14 days', icon: 'refresh' },
|
||||||
{ id: 'tb3', title: '24/7 Support Services', subtitle: 'Any Time Customer Support', icon: 'headset' },
|
{ id: 'tb3', title: '24/7 Support Services', subtitle: 'Any Time Customer Support', icon: 'headset' },
|
||||||
{ id: 'tb4', title: 'Secure payment', subtitle: '100% Fast & Secure Payment', icon: 'shield' },
|
{ id: 'tb4', title: 'Secure payment', subtitle: '100% Fast & Secure Payment', icon: 'shield' },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue