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 { useT } from "@/lib/i18n"; import { useSession } from "@/lib/session"; const RoleSelection = () => { const { setUserRole } = useSession(); const t = useT(); 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(t("auth.role.alertErrorTitle"), t("auth.role.alertErrorBody")); } finally { setSaving(false); } }; return ( {t("auth.role.title")} {t("auth.role.subtitle")} chooseRole("rider")} disabled={saving} className="bg-primary-500 rounded-2xl p-7 mb-5 items-center" > 🧍 {t("auth.role.riderTitle")} {t("auth.role.riderDesc")} chooseRole("driver")} disabled={saving} className="bg-general-600 dark:bg-primary-500/20 border border-primary-500 rounded-2xl p-7 items-center" > 🚗 {t("auth.role.driverTitle")} {t("auth.role.driverDesc")} ); }; export default RoleSelection;