Files
waseel/components/cancel-sheet.tsx
KrikoriosandClaude Opus 5 8807ff41c5 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>
2026-08-26 02:17:55 +03:00

107 lines
3.2 KiB
TypeScript

import { useState } from "react";
import { Text, TouchableOpacity, View } from "react-native";
import ReactNativeModal from "react-native-modal";
import { useT } from "@/lib/i18n";
// Cancelling asks *why* before it asks "are you sure". The reason codes are
// fixed (lib/ride-lifecycle CANCELLATION_REASONS) rather than free text, so
// the admin portal can count them — "driver never showed" and "I changed my
// mind" are the same cancellation in the ledger otherwise, and only one of
// them is a problem worth chasing.
const RIDER_REASONS = [
"wait_too_long",
"driver_no_show",
"unreachable",
"wrong_address",
"changed_mind",
"other",
] as const;
const DRIVER_REASONS = [
"rider_no_show",
"unreachable",
"wrong_address",
"vehicle_issue",
"other",
] as const;
type Props = {
visible: boolean;
audience: "rider" | "driver";
submitting?: boolean;
onCancel: () => void;
onConfirm: (reason: string) => void;
};
export const CancelSheet = ({
visible,
audience,
submitting,
onCancel,
onConfirm,
}: Props) => {
const t = useT();
const [reason, setReason] = useState<string | null>(null);
const reasons = audience === "rider" ? RIDER_REASONS : DRIVER_REASONS;
return (
<ReactNativeModal isVisible={visible} onBackdropPress={onCancel}>
<View className="bg-white dark:bg-neutral-900 p-6 rounded-2xl">
<Text className="text-xl font-JakartaBold text-black dark:text-white">
{t("cancelSheet.title")}
</Text>
<Text className="text-sm text-general-200 dark:text-neutral-400 mt-1 mb-4">
{audience === "rider"
? t("cancelSheet.subtitleRider")
: t("cancelSheet.subtitleDriver")}
</Text>
{reasons.map((code) => {
const selected = reason === code;
return (
<TouchableOpacity
key={code}
onPress={() => setReason(code)}
className={`rounded-2xl border px-4 py-3 mb-2 ${
selected
? "border-primary-500 bg-primary-500/10"
: "border-neutral-200 dark:border-neutral-800"
}`}
>
<Text
className={`font-JakartaMedium ${
selected ? "text-primary-500" : "text-black dark:text-white"
}`}
>
{t(`cancelSheet.reasons.${code}`)}
</Text>
</TouchableOpacity>
);
})}
<TouchableOpacity
onPress={() => reason && onConfirm(reason)}
disabled={!reason || submitting}
className={`rounded-full py-3 items-center mt-3 bg-rose-500 ${
!reason || submitting ? "opacity-50" : ""
}`}
>
<Text className="font-JakartaBold text-white">
{submitting
? t("cancelSheet.cancelling")
: t("cancelSheet.confirm")}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={onCancel} className="py-3 mt-1">
<Text className="text-center font-JakartaMedium text-general-200 dark:text-neutral-400">
{t("cancelSheet.keepRide")}
</Text>
</TouchableOpacity>
</View>
</ReactNativeModal>
);
};