Waseel: driver capture, chat/calls, dispatch, and session fixes

Driver onboarding now photographs the licence, ID card and vehicle
registration and reads the credential fields off them, plus a camera-only
profile selfie riders check the arriving driver against. Adds in-app chat
and WebRTC calls, push-backed ride offers, ratings, cancellation and
payment sheets, settlement, and the owner dashboard endpoints behind them.

Camera permission on Android:
  - Declare CAMERA and READ_MEDIA_IMAGES in the manifest. expo-image-picker's
    own plugin never declares CAMERA, and Android denies a request for an
    undeclared permission instantly and silently — no dialog is ever shown,
    which is indistinguishable from the app not asking at all.
  - Handle canAskAgain: once Android stops showing the dialog, repeating why
    we need it is a dead end, so offer Open Settings instead (lib/capture-
    permission.ts), matching what the location flow already did.

Session: a 401 on a request that carried a token now ends the session
instead of being reinterpreted per-screen — driver-home had been reading it
as "this user has no driver profile" and showing an onboarding form to an
already-onboarded driver. Requests without a token are exempt so a failed
sign-in doesn't sign you out, and the notification is latched per token so
concurrent polls tear the session down once. (root) gains the auth guard
that turns that into the sign-in screen; app/index.tsx only guarded the way
in, leaving a session that ended mid-screen with nowhere to go.

Also ignore .uploads/ — it holds driver licence, ID and vehicle scans plus
profile photos, which are personal data and must not be committed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Krikorios
2026-08-26 02:17:55 +03:00
co-authored by Claude Opus 5
parent 1d84003e0a
commit 8807ff41c5
111 changed files with 14568 additions and 1411 deletions
+146
View File
@@ -0,0 +1,146 @@
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { router } from "expo-router";
import { useCallback, useEffect, useState } from "react";
import { Text, TouchableOpacity, View } from "react-native";
import { RatingSheet } from "@/components/rating-sheet";
import { fetchAPI } from "@/lib/fetch";
import { useT } from "@/lib/i18n";
// Home-screen banner for unfinished business. Two things can be unfinished
// after the rider leaves the tracking screen:
//
// * a ride still in flight — before this, killing the app mid-ride stranded
// the rider with no route back to their driver, since home only lists
// completed history;
// * a finished ride they never rated — the prompt is easy to miss when the
// app is backgrounded the moment the door closes.
//
// Both are recoverable from one poll, so they share one banner.
const POLL_MS = 15000;
type ActiveRide = {
ride_id: number;
status: string;
service: string;
destination_address: string;
driver_name: string | null;
};
type PendingRating = {
ride_id: number;
destination_address: string;
driver_name: string | null;
driver_avatar: string | null;
};
const STATUS_KEY: Record<string, string> = {
requested: "bookRide.status.requested",
accepted: "bookRide.status.accepted",
arrived: "bookRide.status.arrived",
en_route: "bookRide.status.enRoute",
};
export const ActiveRideBanner = () => {
const t = useT();
const [active, setActive] = useState<ActiveRide | null>(null);
const [pending, setPending] = useState<PendingRating | null>(null);
const [ratingOpen, setRatingOpen] = useState(false);
const [dismissed, setDismissed] = useState<number[]>([]);
const load = useCallback(async () => {
try {
const res = await fetchAPI("/(api)/ride/active");
setActive(res.data?.active ?? null);
setPending(res.data?.pending_rating ?? null);
} catch (err) {
// A signed-out or offline home screen simply shows no banner.
console.log("[ACTIVE_RIDE_BANNER]: ", err);
}
}, []);
useEffect(() => {
void load();
const timer = setInterval(() => void load(), POLL_MS);
return () => clearInterval(timer);
}, [load]);
if (active) {
return (
<TouchableOpacity
onPress={() =>
router.push({
pathname: "/(root)/book-ride",
params: { id: String(active.ride_id) },
})
}
className="bg-primary-500 rounded-2xl p-4 mb-4 flex-row items-center"
>
<View className="flex-1">
<Text className="text-white/80 text-xs font-JakartaMedium">
{STATUS_KEY[active.status]
? t(STATUS_KEY[active.status])
: active.status}
</Text>
<Text
className="text-white font-JakartaBold mt-0.5"
numberOfLines={1}
>
{active.driver_name
? t("home.activeRideWithDriver", { name: active.driver_name })
: active.destination_address}
</Text>
</View>
<MaterialCommunityIcons name="chevron-right" size={24} color="white" />
</TouchableOpacity>
);
}
if (pending && !dismissed.includes(pending.ride_id)) {
return (
<>
<View className="bg-white dark:bg-neutral-900 rounded-2xl p-4 mb-4 flex-row items-center">
<View className="flex-1">
<Text className="text-general-200 dark:text-neutral-400 text-xs font-JakartaMedium">
{t("home.rateLastRide")}
</Text>
<Text
className="text-black dark:text-white font-JakartaBold mt-0.5"
numberOfLines={1}
>
{pending.destination_address}
</Text>
</View>
<TouchableOpacity
onPress={() => setRatingOpen(true)}
className="bg-primary-500 rounded-full px-4 py-2 ml-3"
>
<Text className="text-white font-JakartaBold text-xs">
{t("home.rate")}
</Text>
</TouchableOpacity>
</View>
<RatingSheet
visible={ratingOpen}
rideId={pending.ride_id}
audience="rider"
subjectName={pending.driver_name}
subjectAvatar={pending.driver_avatar}
onDone={() => {
setRatingOpen(false);
setDismissed((prev) => [...prev, pending.ride_id]);
void load();
}}
onSkip={() => {
setRatingOpen(false);
setDismissed((prev) => [...prev, pending.ride_id]);
}}
/>
</>
);
}
return null;
};