import { router } from "expo-router"; import { useState } from "react"; import { Alert, Text, TouchableOpacity, View } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { fetchAPI } from "@/lib/fetch"; import { useSession } from "@/lib/session"; const RoleSelection = () => { const { setUserRole } = useSession(); const [saving, setSaving] = useState(false); const chooseRole = async (role: "rider" | "driver") => { if (saving) return; setSaving(true); try { const { error } = await fetchAPI("/(api)/user", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ role }), }); if (error) throw new Error(error); setUserRole(role); router.replace( role === "driver" ? "/(root)/driver-home" : "/(root)/(tabs)/home", ); } catch (err) { console.log("[ROLE_SELECT]: ", err); Alert.alert("Error", "Could not save your choice. Please try again."); } finally { setSaving(false); } }; return ( How will you use Waseel? You can change this later by contacting support. chooseRole("rider")} disabled={saving} className="bg-primary-500 rounded-2xl p-7 mb-5 items-center" > 🧍 I'm a Rider Book rides and get around Lebanon chooseRole("driver")} disabled={saving} className="bg-general-600 rounded-2xl p-7 items-center" > 🚗 I'm a Driver Give rides and earn money ); }; export default RoleSelection;