import React, { useState } from "react"; import { View, Text, StyleSheet, Alert, ActivityIndicator, ScrollView, KeyboardAvoidingView, Platform, TouchableOpacity, } from "react-native"; import * as Keychain from "react-native-keychain"; import { CustomInput, CustomButton } from "../../components/common/Custom"; import colors from "../../components/colors"; import { useNavigation } from "@react-navigation/native"; import AppView from "../../components/AppView"; import { Ionicons } from "@react-native-vector-icons/ionicons"; const BecomeOrg = () => { const navigation = useNavigation(); const [idName, setIdName] = useState(""); const [idNumber, setIdNumber] = useState(""); const [issueDate, setIssueDate] = useState(""); const [loading, setLoading] = useState(false); const handleSubmit = async () => { if (!idName || !idNumber || !issueDate) { Alert.alert("Error", "Please fill all fields"); return; } try { setLoading(true); const credentials = await Keychain.getGenericPassword(); if (!credentials) { Alert.alert("Error", "You are not logged in. Please log in to continue."); setLoading(false); // Optionally navigate to login screen // navigation.navigate("Login"); return; } const token = credentials.password; const response = await fetch( "https://exotic-humpback-mistakenly.ngrok-free.app/api/organizer/registration/apply", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, body: JSON.stringify({ idName, idNumber, issueDate, }), } ); const result = await response.json(); if (response.ok && result.status === "success") { Alert.alert("Success", "Organizer registration application submitted successfully!"); setIdName(""); setIdNumber(""); setIssueDate(""); navigation.navigate("Home" as never); } else { Alert.alert("Error", result.message || "Failed to submit application"); } } catch (error) { console.error("❌ Registration error:", error); Alert.alert("Error", "An unexpected error occurred. Please try again."); } finally { setLoading(false); } }; return ( navigation.goBack()} style={styles.backButton}> Become an Organizer Submit Your ID for Verification Please provide your official identification details to become a verified organizer. {loading && ( )} ); }; export default BecomeOrg; const styles = StyleSheet.create({ container: { flexGrow: 1, padding: 20, justifyContent: "center", }, title: { fontSize: 24, fontWeight: "700", marginBottom: 10, textAlign: "center", color: colors.textDark, }, subtitle: { fontSize: 16, textAlign: "center", color: colors.textDark, marginBottom: 30, }, header: { flexDirection: "row", alignItems: "center", paddingHorizontal: 16, paddingVertical: 12, backgroundColor: '#FFF', borderBottomWidth: 1, borderBottomColor: '#E0E0E0', }, backButton: { padding: 5, }, headerTitle: { flex: 1, fontSize: 20, fontWeight: "600", color: "#000", textAlign: "center", }, placeholder: { width: 24, // to balance the back button }, });