// ============================================================
// GOLDLINE DELIVERY - VERSION COMPLÈTE AVEC CLASSIFICATION
// Livreur / Commandeur + Abonné / Non-abonné + Paiements
// ============================================================
// ============================================================
// FILE: src/types/index.ts
// ============================================================
export type UserRole = 'client' | 'partner_rider' | 'goldline_rider' | 'admin' | 'dispatcher';
export type RiderType = 'subscribed' | 'non_subscribed'; // Nouveau
export type OrderStatus =
| 'pending'
| 'assigned'
| 'picked_up'
| 'in_transit'
| 'delivered'
| 'cancelled'
| 'disputed';
export type PaymentMethod =
| 'mobile_money'
| 'airtel_money'
| 'orange_money'
| 'bank_card'
| 'paypal'
| 'deposit'
| 'cash_cod'
| 'subscription';
export interface Profile {
id: string;
full_name: string;
phone: string;
email?: string;
role: UserRole;
rider_type?: RiderType; // 'subscribed' | 'non_subscribed'
subscription_credit?: number; // Crédit restant pour les abonnés
avatar_url?: string;
rating: number;
is_online?: boolean;
created_at: string;
}
export interface Address {
label: string;
lat: number;
lng: number;
commune?: string;
details?: string;
}
export interface Order {
id: string;
client_id: string;
rider_id?: string;
pickup: Address;
dropoff: Address;
package_description: string;
package_photo_url?: string;
estimated_value: number;
price: number;
status: OrderStatus;
payment_method: PaymentMethod;
is_express: boolean;
distance_km?: number;
proof_pickup_url?: string;
proof_delivery_url?: string;
signature_url?: string;
sms_code?: string;
commission_amount?: number; // Commission prélevée (20% pour non-abonnés)
created_at: string;
picked_up_at?: string;
delivered_at?: string;
rating?: number;
rating_comment?: string;
}
// ============================================================
// FILE: src/lib/constants.ts
// ============================================================
export const PRICING = {
INTRA_COMMUNE: 3000,
INTER_COMMUNE_MIN: 5000,
INTER_COMMUNE_MAX: 7500,
EXPRESS_MULTIPLIER: 1.5,
GUARANTEE_DEPOSIT: 500,
PARTNER_COMMISSION: 0.20, // 20% pour les livreurs NON abonnés
};
export const SUBSCRIPTION_PLANS = [
{
id: 'particulier',
name: 'Particulier',
price_usd: 20,
deliveries: 10,
extra_price: 2.5,
description: 'Idéal pour les habitants et petits revendeurs',
},
{
id: 'petite_entreprise',
name: 'Petite Entreprise',
price_usd: 50,
deliveries: 30,
extra_price: 1.8,
description: 'Boutiques, salons, snacks',
},
{
id: 'grande_entreprise',
name: 'Grande Entreprise',
price_usd: 75,
deliveries: 50,
extra_price: 1.5,
description: 'Pharmacies, grossistes, écoles',
},
] as const;
// Abonnement spécial pour les livreurs
export const RIDER_SUBSCRIPTION = {
price_usd: 15,
name: 'Abonnement Livreur GoldLine',
benefits: [
'Recevoir l\'argent en cash',
'Priorité sur les courses',
'Commission réduite',
'Support prioritaire',
],
};
export const STATUS_LABELS: Record<string, string> = {
pending: 'En attente',
assigned: 'Livreur assigné',
picked_up: 'Colis collecté',
in_transit: 'En cours de livraison',
delivered: 'Livré',
cancelled: 'Annulé',
disputed: 'Litige',
};
export const PAYMENT_METHODS = [
{ id: 'airtel_money', label: 'Airtel Money', icon: '📱' },
{ id: 'orange_money', label: 'Orange Money', icon: '🍊' },
{ id: 'mobile_money', label: 'M-Pesa / Mobile Money', icon: '💳' },
{ id: 'bank_card', label: 'Carte Bancaire', icon: '💳' },
{ id: 'paypal', label: 'PayPal', icon: '🅿️' },
{ id: 'cash_cod', label: 'Cash à la livraison', icon: '💵' },
];
// ============================================================
// FILE: src/contexts/AuthContext.tsx
// ============================================================
import { createContext, useContext, useEffect, useState } from 'react';
import { supabase } from '../lib/supabase';
import { Profile, RiderType } from '../types';
interface AuthContextType {
user: any;
profile: Profile | null;
loading: boolean;
signIn: (phone: string, password: string) => Promise<void>;
signOut: () => Promise<void>;
refreshProfile: () => Promise<void>;
completeOnboarding: (data: {
full_name: string;
phone: string;
role: 'client' | 'partner_rider';
rider_type?: RiderType;
}) => Promise<void>;
}
const AuthContext = createContext<AuthContextType>({} as any);
export function AuthProvider({ children }: { children: React.ReactNode }) {
const [user, setUser] = useState<any>(null);
const [profile, setProfile] = useState<Profile | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
supabase.auth.getSession().then(({ data: { session } }) => {
setUser(session?.user ?? null);
if (session?.user) fetchProfile(session.user.id);
else setLoading(false);
});
const { data: { subscription } } = supabase.auth.onAuthStateChange((_event, session) => {
setUser(session?.user ?? null);
if (session?.user) fetchProfile(session.user.id);
else {
setProfile(null);
setLoading(false);
}
});
return () => subscription.unsubscribe();
}, []);
async function fetchProfile(userId: string) {
const { data } = await supabase.from('profiles').select('*').eq('id', userId).single();
setProfile(data);
setLoading(false);
}
async function signIn(phone: string, password: string) {
const { error } = await supabase.auth.signInWithPassword({
email: `${phone}@goldline.cd`,
password,
});
if (error) throw error;
}
async function signOut() {
await supabase.auth.signOut();
}
async function refreshProfile() {
if (user) await fetchProfile(user.id);
}
// Nouvelle fonction d'onboarding
async function completeOnboarding(data: {
full_name: string;
phone: string;
role: 'client' | 'partner_rider';
rider_type?: RiderType;
}) {
// Ici tu peux créer le compte + le profil
// Pour la démo on simule
console.log('Onboarding completed:', data);
}
return (
<AuthContext.Provider value={{
user, profile, loading, signIn, signOut, refreshProfile, completeOnboarding
}}>
{children}
</AuthContext.Provider>
);
}
export const useAuth = () => useContext(AuthContext);
// ============================================================
// FILE: src/pages/Onboarding.tsx ← NOUVELLE PAGE PRINCIPALE
// ============================================================
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { User, Bike, CheckCircle, XCircle } from 'lucide-react';
import { RIDER_SUBSCRIPTION } from '../lib/constants';
type Step = 'role' | 'rider_type' | 'info';
export default function Onboarding() {
const navigate = useNavigate();
const [step, setStep] = useState<Step>('role');
const [role, setRole] = useState<'client' | 'partner_rider' | null>(null);
const [riderType, setRiderType] = useState<'subscribed' | 'non_subscribed' | null>(null);
const [fullName, setFullName] = useState('');
const [phone, setPhone] = useState('');
function handleRoleSelect(selectedRole: 'client' | 'partner_rider') {
setRole(selectedRole);
if (selectedRole === 'client') {
setStep('info');
} else {
setStep('rider_type');
}
}
function handleRiderTypeSelect(type: 'subscribed' | 'non_subscribed') {
setRiderType(type);
setStep('info');
}
function handleFinish() {
// Ici on sauvegarde le profil
// Puis on redirige selon le rôle
if (role === 'client') {
navigate('/app');
} else {
navigate('/rider');
}
}
return (
<div className="min-h-screen bg-black text-white flex flex-col">
{/* Header */}
<div className="pt-12 pb-6 px-6 text-center">
<h1 className="text-3xl font-bold text-yellow-500">GoldLine Delivery</h1>
<p className="text-white/60 mt-2">Bienvenue ! Commençons par vous classer</p>
</div>
<div className="flex-1 px-6">
{/* ========== STEP 1 : Choix Livreur ou Commandeur ========== */}
{step === 'role' && (
<div className="space-y-6">
<h2 className="text-xl font-semibold text-center mb-8">
Qui êtes-vous ?
</h2>
<button
onClick={() => handleRoleSelect('client')}
className="w-full bg-[#1a1a1a] border-2 border-white/10 hover:border-yellow-500 rounded-2xl p-6 flex items-center gap-5 transition active:scale-95"
>
<div className="w-16 h-16 rounded-full bg-yellow-500/20 flex items-center justify-center">
<User className="w-8 h-8 text-yellow-500" />
</div>
<div className="text-left">
<p className="text-xl font-bold">Commandeur</p>
<p className="text-white/60 text-sm">Je veux envoyer ou recevoir des colis</p>
</div>
</button>
<button
onClick={() => handleRoleSelect('partner_rider')}
className="w-full bg-[#1a1a1a] border-2 border-white/10 hover:border-yellow-500 rounded-2xl p-6 flex items-center gap-5 transition active:scale-95"
>
<div className="w-16 h-16 rounded-full bg-yellow-500/20 flex items-center justify-center">
<Bike className="w-8 h-8 text-yellow-500" />
</div>
<div className="text-left">
<p className="text-xl font-bold">Livreur</p>
<p className="text-white/60 text-sm">Je veux livrer des colis et gagner de l'argent</p>
</div>
</button>
</div>
)}
{/* ========== STEP 2 : Abonné ou Non-abonné (seulement pour livreurs) ========== */}
{step === 'rider_type' && (
<div className="space-y-6">
<button onClick={() => setStep('role')} className="text-yellow-500 text-sm mb-4">
← Retour
</button>
<h2 className="text-xl font-semibold text-center mb-2">
Type de livreur
</h2>
<p className="text-center text-white/60 text-sm mb-8">
Choisissez votre mode de collaboration
</p>
{/* Option Abonné */}
<button
onClick={() => handleRiderTypeSelect('subscribed')}
className="w-full bg-[#1a1a1a] border-2 border-yellow-500/50 hover:border-yellow-500 rounded-2xl p-6 text-left transition"
>
<div className="flex items-start gap-4">
<CheckCircle className="w-7 h-7 text-yellow-500 mt-1 shrink-0" />
<div>
<p className="text-lg font-bold text-yellow-500">Livreur Abonné</p>
<p className="text-sm text-white/70 mt-1">
{RIDER_SUBSCRIPTION.price_usd}$ / mois
</p>
<ul className="mt-3 space-y-1 text-sm text-white/80">
{RIDER_SUBSCRIPTION.benefits.map((b) => (
<li key={b}>✓ {b}</li>
))}
</ul>
</div>
</div>
</button>
{/* Option Non-abonné */}
<button
onClick={() => handleRiderTypeSelect('non_subscribed')}
className="w-full bg-[#1a1a1a] border-2 border-white/10 hover:border-white/30 rounded-2xl p-6 text-left transition"
>
<div className="flex items-start gap-4">
<XCircle className="w-7 h-7 text-white/50 mt-1 shrink-0" />
<div>
<p className="text-lg font-bold">Livreur Non-abonné</p>
<p className="text-sm text-white/70 mt-1">Gratuit</p>
<ul className="mt-3 space-y-1 text-sm text-white/80">
<li>• Commission de <span className="text-yellow-500 font-bold">20%</span> sur chaque course</li>
<li>• Pas de retrait en cash direct</li>
<li>• Paiement uniquement via Mobile Money</li>
</ul>
</div>
</div>
</button>
</div>
)}
{/* ========== STEP 3 : Informations personnelles ========== */}
{step === 'info' && (
<div className="space-y-6">
<button
onClick={() => role === 'client' ? setStep('role') : setStep('rider_type')}
className="text-yellow-500 text-sm"
>
← Retour
</button>
<h2 className="text-xl font-semibold text-center mb-6">
Vos informations
</h2>
<div>
<label className="text-sm text-yellow-500 mb-2 block">Nom complet</label>
<input
type="text"
value={fullName}
onChange={(e) => setFullName(e.target.value)}
placeholder="Ex: Jean Mukendi"
className="w-full bg-[#1a1a1a] border border-white/10 rounded-xl py-4 px-4"
/>
</div>
<div>
<label className="text-sm text-yellow-500 mb-2 block">Numéro de téléphone</label>
<input
type="tel"
value={phone}
onChange={(e) => setPhone(e.target.value)}
placeholder="Ex: 099 123 4567"
className="w-full bg-[#1a1a1a] border border-white/10 rounded-xl py-4 px-4"
/>
</div>
{/* Résumé du choix */}
<div className="bg-[#1a1a1a] border border-yellow-500/30 rounded-xl p-4 text-sm">
<p className="text-white/60">Vous êtes :</p>
<p className="font-bold text-yellow-500 mt-1">
{role === 'client' ? 'Commandeur' :
riderType === 'subscribed' ? 'Livreur Abonné' : 'Livreur Non-abonné'}
</p>
</div>
<button
onClick={handleFinish}
disabled={!fullName || !phone}
className="w-full bg-yellow-500 text-black font-bold py-4 rounded-xl disabled:opacity-40"
>
Continuer
</button>
</div>
)}
</div>
</div>
);
}
// ============================================================
// FILE: src/pages/client/RequestDelivery.tsx (avec console de paiement style Uber)
// ============================================================
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { MapPin, Camera, CheckCircle } from 'lucide-react';
import { PRICING, PAYMENT_METHODS } from '../../lib/constants';
export default function RequestDelivery() {
const navigate = useNavigate();
const [step, setStep] = useState(1); // 1=adresses, 2=colis, 3=paiement, 4=confirmation
const [loading, setLoading] = useState(false);
const [form, setForm] = useState({
pickup: '',
dropoff: '',
description: '',
isExpress: false,
paymentMethod: 'airtel_money',
});
const estimatedPrice = form.isExpress
? Math.round(PRICING.INTRA_COMMUNE * PRICING.EXPRESS_MULTIPLIER)
: PRICING.INTRA_COMMUNE;
async function handleConfirmPayment() {
setLoading(true);
// Simulation d'appel API
await new Promise(r => setTimeout(r, 1500));
setLoading(false);
setStep(4); // Écran de confirmation
}
// ========== ÉCRAN DE CONFIRMATION (style Uber) ==========
if (step === 4) {
return (
<div className="min-h-screen bg-black text-white flex flex-col items-center justify-center p-6">
<div className="w-20 h-20 rounded-full bg-green-500/20 flex items-center justify-center mb-6">
<CheckCircle className="w-12 h-12 text-green-500" />
</div>
<h1 className="text-2xl font-bold mb-2">Commande confirmée !</h1>
<p className="text-white/60 text-center mb-8">
Un livreur va bientôt prendre en charge votre colis
</p>
<div className="w-full bg-[#1a1a1a] border border-white/10 rounded-2xl p-6 mb-8">
<div className="flex justify-between mb-3">
<span className="text-white/60">Montant payé</span>
<span className="font-bold text-yellow-500">{estimatedPrice.toLocaleString()} FC</span>
</div>
<div className="flex justify-between mb-3">
<span className="text-white/60">Moyen de paiement</span>
<span>{PAYMENT_METHODS.find(p => p.id === form.paymentMethod)?.label}</span>
</div>
<div className="flex justify-between">
<span className="text-white/60">De → Vers</span>
<span className="text-right text-sm">{form.pickup} → {form.dropoff}</span>
</div>
</div>
<button
onClick={() => navigate('/app/tracking/demo')}
className="w-full bg-yellow-500 text-black font-bold py-4 rounded-xl"
>
Suivre ma livraison
</button>
</div>
);
}
return (
<div className="min-h-screen bg-black text-white pb-32">
<div className="px-6 pt-12">
<h1 className="text-2xl font-bold mb-8">Nouvelle livraison</h1>
{/* STEP 1 - Adresses */}
{step === 1 && (
<div className="space-y-6">
<div>
<label className="text-sm text-yellow-500 mb-2 block">Adresse de collecte</label>
<div className="relative">
<MapPin className="absolute left-4 top-4 text-yellow-500 w-5 h-5" />
<input
className="w-full bg-[#1a1a1a] border border-white/10 rounded-xl py-4 pl-12 pr-4"
placeholder="Ex: Avenue de la Paix, Kadutu"
value={form.pickup}
onChange={(e) => setForm({ ...form, pickup: e.target.value })}
/>
</div>
</div>
<div>
<label className="text-sm text-yellow-500 mb-2 block">Adresse de livraison</label>
<div className="relative">
<MapPin className="absolute left-4 top-4 text-yellow-500 w-5 h-5" />
<input
className="w-full bg-[#1a1a1a] border border-white/10 rounded-xl py-4 pl-12 pr-4"
placeholder="Ex: Quartier Nguba"
value={form.dropoff}
onChange={(e) => setForm({ ...form, dropoff: e.target.value })}
/>
</div>
</div>
<button
onClick={() => setStep(2)}
disabled={!form.pickup || !form.dropoff}
className="w-full bg-yellow-500 text-black font-bold py-4 rounded-xl disabled:opacity-40"
>
Continuer
</button>
</div>
)}
{/* STEP 2 - Colis */}
{step === 2 && (
<div className="space-y-6">
<div>
<label className="text-sm text-yellow-500 mb-2 block">Description du colis</label>
<textarea
className="w-full bg-[#1a1a1a] border border-white/10 rounded-xl p-4 h-28"
placeholder="Ex: Médicaments, documents, repas..."
value={form.description}
onChange={(e) => setForm({ ...form, description: e.target.value })}
/>
</div>
<label className="flex items-center gap-3">
<input
type="checkbox"
checked={form.isExpress}
onChange={(e) => setForm({ ...form, isExpress: e.target.checked })}
className="w-5 h-5 accent-yellow-500"
/>
<span>Livraison Express (+50%)</span>
</label>
<div className="flex gap-3">
<button onClick={() => setStep(1)} className="flex-1 border border-white/20 py-4 rounded-xl">Retour</button>
<button onClick={() => setStep(3)} className="flex-1 bg-yellow-500 text-black font-bold py-4 rounded-xl">Continuer</button>
</div>
</div>
)}
{/* STEP 3 - CONSOLE DE PAIEMENT (style Uber) */}
{step === 3 && (
<div className="space-y-6">
{/* Récapitulatif */}
<div className="bg-[#1a1a1a] border border-yellow-500/30 rounded-2xl p-6">
<div className="flex justify-between items-center mb-1">
<span className="text-white/70">Total à payer</span>
<span className="text-3xl font-bold text-yellow-500">
{estimatedPrice.toLocaleString()} FC
</span>
</div>
<p className="text-sm text-white/50">≈ ${(estimatedPrice / 2850).toFixed(2)} USD</p>
</div>
{/* Choix du moyen de paiement */}
<div>
<p className="text-sm text-yellow-500 mb-3 font-medium">Choisir le moyen de paiement</p>
<div className="space-y-3">
{PAYMENT_METHODS.map((method) => (
<label
key={method.id}
className={`flex items-center gap-4 p-4 rounded-xl border cursor-pointer transition ${
form.paymentMethod === method.id
? 'border-yellow-500 bg-yellow-500/10'
: 'border-white/10 bg-[#1a1a1a]'
}`}
>
<input
type="radio"
name="payment"
value={method.id}
checked={form.paymentMethod === method.id}
onChange={() => setForm({ ...form, paymentMethod: method.id })}
className="accent-yellow-500 w-5 h-5"
/>
<span className="text-2xl">{method.icon}</span>
<span className="font-medium">{method.label}</span>
</label>
))}
</div>
</div>
<div className="flex gap-3 pt-4">
<button onClick={() => setStep(2)} className="flex-1 border border-white/20 py-4 rounded-xl">
Retour
</button>
<button
onClick={handleConfirmPayment}
disabled={loading}
className="flex-1 bg-yellow-500 text-black font-bold py-4 rounded-xl disabled:opacity-50"
>
{loading ? 'Traitement...' : 'Confirmer et Payer'}
</button>
</div>
</div>
)}
</div>
</div>
);
}
// ============================================================
// FILE: src/pages/rider/Home.tsx (avec distinction Abonné / Non-abonné)
// ============================================================
import { useState } from 'react';
import { Link } from 'react-router-dom';
import { useAuth } from '../../contexts/AuthContext';
import { PRICING } from '../../lib/constants';
export default function RiderHome() {
const { profile } = useAuth();
const [isOnline, setIsOnline] = useState(false);
const isSubscribed = profile?.rider_type === 'subscribed';
const commission = isSubscribed ? 0 : PRICING.PARTNER_COMMISSION * 100;
return (
<div className="min-h-screen bg-black text-white p-6">
{/* Header */}
<div className="flex justify-between items-center mb-6">
<div>
<h1 className="text-2xl font-bold">Espace Livreur</h1>
<p className="text-sm text-yellow-500">
{isSubscribed ? '⭐ Abonné GoldLine' : 'Non-abonné • Commission 20%'}
</p>
</div>
<button
onClick={() => setIsOnline(!isOnline)}
className={`px-4 py-2 rounded-full font-medium text-sm ${
isOnline ? 'bg-green-500 text-black' : 'bg-gray-700'
}`}
>
{isOnline ? 'En ligne' : 'Hors ligne'}
</button>
</div>
{/* Info Commission */}
{!isSubscribed && (
<div className="bg-orange-500/10 border border-orange-500/30 rounded-xl p-4 mb-6 text-sm">
<p className="text-orange-400 font-medium">Mode Non-abonné</p>
<p className="text-white/70 mt-1">
Une commission de <strong>20%</strong> est prélevée sur chaque course.
Passez à l'abonnement pour recevoir l'argent en cash.
</p>
</div>
)}
{isOnline ? (
<div className="space-y-4">
<p className="text-white/60">En attente de nouvelles courses...</p>
{/* Exemple de course */}
<div className="bg-[#1a1a1a] border border-yellow-500/30 rounded-2xl p-5">
<div className="flex justify-between items-start">
<div>
<p className="text-yellow-500 font-bold text-xl">3 000 FC</p>
{!isSubscribed && (
<p className="text-xs text-white/50">
Vous recevrez : {(3000 * 0.8).toLocaleString()} FC (après 20%)
</p>
)}
</div>
<span className="text-sm text-white/50">1.8 km</span>
</div>
<p className="mt-3 font-medium">Kadutu → Nguba</p>
<div className="flex gap-3 mt-5">
<button className="flex-1 border border-red-500/50 text-red-400 py-3 rounded-xl">
Refuser
</button>
<Link
to="/rider/job/demo"
className="flex-1 bg-yellow-500 text-black font-bold py-3 rounded-xl text-center"
>
Accepter
</Link>
</div>
</div>
</div>
) : (
<div className="text-center mt-20">
<p className="text-white/60">Passez en ligne pour recevoir des courses</p>
</div>
)}
</div>
);
}
// ============================================================
// FILE: src/App.tsx (mis à jour avec Onboarding)
// ============================================================
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import { AuthProvider, useAuth } from './contexts/AuthContext';
import Onboarding from './pages/Onboarding';
import ClientHome from './pages/client/Home';
import RequestDelivery from './pages/client/RequestDelivery';
import Tracking from './pages/client/Tracking';
import RiderHome from './pages/rider/Home';
import RiderJob from './pages/rider/Job';
import Login from './pages/Login';
import Landing from './pages/Landing';
function ProtectedRoute({ children, allowedRoles }: { children: React.ReactNode; allowedRoles: string[] }) {
const { user, profile, loading } = useAuth();
if (loading) return <div className="min-h-screen bg-black text-yellow-500 flex items-center justify-center">Chargement...</div>;
if (!user || !profile) return <Navigate to="/onboarding" />;
if (!allowedRoles.includes(profile.role)) return <Navigate to="/" />;
return <>{children}</>;
}
export default function App() {
return (
<AuthProvider>
<BrowserRouter>
<Routes>
<Route path="/" element={<Landing />} />
<Route path="/onboarding" element={<Onboarding />} />
<Route path="/login" element={<Login />} />
<Route path="/app" element={
<ProtectedRoute allowedRoles={['client']}>
<ClientHome />
</ProtectedRoute>
} />
<Route path="/app/request" element={<RequestDelivery />} />
<Route path="/app/tracking/:orderId" element={<Tracking />} />
<Route path="/rider" element={
<ProtectedRoute allowedRoles={['partner_rider', 'goldline_rider']}>
<RiderHome />
</ProtectedRoute>
} />
<Route path="/rider/job/:orderId" element={<RiderJob />} />
</Routes>
</BrowserRouter>
</AuthProvider>
);
}