import React, { useEffect, useRef, useState } from "react"; import { View, Text, Image, ScrollView, Share, TouchableOpacity, TextInput, } from "react-native"; import { Button } from "~/components/ui/button"; import { SafeAreaView } from "react-native-safe-area-context"; import { router, useLocalSearchParams } from "expo-router"; import { ROUTES } from "~/lib/routes"; import { SuccessIcon } from "~/components/ui/icons"; import { useAuthWithProfile } from "~/lib/hooks/useAuthWithProfile"; import ScreenWrapper from "~/components/ui/ScreenWrapper"; import ModalToast from "~/components/ui/toast"; import { useTranslation } from "react-i18next"; import LottieView from "lottie-react-native"; import { Icons } from "~/assets/icons"; export default function TaskComp() { const { t } = useTranslation(); const params = useLocalSearchParams<{ message?: string; amount?: string; recipientName?: string; recipientPhoneNumber?: string; flowType?: string; }>(); const { wallet } = useAuthWithProfile(); const [toastVisible, setToastVisible] = useState(false); const [toastTitle, setToastTitle] = useState(""); const [toastDescription, setToastDescription] = useState( undefined ); const [toastVariant, setToastVariant] = useState< "success" | "error" | "warning" | "info" >("info"); const toastTimeoutRef = useRef | null>(null); const isEventTicketFlow = params.flowType === "event_ticket"; const [ratingSheetVisible, setRatingSheetVisible] = useState(false); const [rating, setRating] = useState(0); const [selectedIssues, setSelectedIssues] = useState([]); const [comments, setComments] = useState(""); const [selectedPurpose, setSelectedPurpose] = useState(null); const [isPurposeDropdownOpen, setIsPurposeDropdownOpen] = useState(false); const [otherPurpose, setOtherPurpose] = useState(""); const showToast = ( title: string, description?: string, variant: "success" | "error" | "warning" | "info" = "info" ) => { if (toastTimeoutRef.current) { clearTimeout(toastTimeoutRef.current); } setToastTitle(title); setToastDescription(description); setToastVariant(variant); setToastVisible(true); toastTimeoutRef.current = setTimeout(() => { setToastVisible(false); toastTimeoutRef.current = null; }, 2500); }; useEffect(() => { return () => { if (toastTimeoutRef.current) { clearTimeout(toastTimeoutRef.current); } }; }, []); const toggleIssue = (key: string) => { setSelectedIssues((prev) => prev.includes(key) ? prev.filter((i) => i !== key) : [...prev, key] ); }; const handleSendAgain = () => { const balance = wallet?.balance; if (balance === undefined) { showToast( t("taskcomp.toastErrorTitle"), t("taskcomp.toastNoBalance"), "error" ); return; } if (balance < 1000) { showToast( t("taskcomp.toastErrorTitle"), t("taskcomp.toastMinError"), "error" ); return; } // Navigate to home first, then to send money to prevent going back to success page router.replace(ROUTES.HOME); // Use setTimeout to ensure home navigation completes before send money navigation router.push(ROUTES.SEND_OR_REQUEST_MONEY); }; const handleSubmitRating = () => { setRatingSheetVisible(false); router.replace(ROUTES.HOME); }; const handleShare = async () => { try { const shareMessage = params.message ? t("taskcomp.shareMessageWithParam", { message: params.message }) : t("taskcomp.shareMessageDefault"); const result = await Share.share({ message: shareMessage, title: t("taskcomp.shareTitle"), }); if (result.action === Share.sharedAction) { // Content was shared console.log("Content shared successfully"); } else if (result.action === Share.dismissedAction) { // Share dialog was dismissed console.log("Share dialog dismissed"); } } catch (error) { console.error("Error sharing:", error); showToast( t("taskcomp.toastErrorTitle"), t("taskcomp.toastShareError"), "error" ); } }; return ( {/* */} {/* */} {params.amount ? ( {params.amount} ) : ( <> )} {params.message || t("taskcomp.successDescription")} {/* Bottom action buttons */} {isEventTicketFlow ? ( <> ) : ( <> )} {!isEventTicketFlow && ratingSheetVisible && ( setRatingSheetVisible(false)} /> {t("taskcomp.ratingTitle")} {t("taskcomp.ratingSubtitle")} {t("taskcomp.ratingOverallLabel")} {[1, 2, 3, 4, 5].map((star) => ( setRating(star)} activeOpacity={0.8} > ))} {t("taskcomp.ratingPurposeLabel")} setIsPurposeDropdownOpen((prev) => !prev)} className="border border-gray-300 rounded-2xl px-3 py-2 flex-row items-center justify-between" > {selectedPurpose ? t( { family: "taskcomp.ratingPurposeFamily", medical: "taskcomp.ratingPurposeMedical", loan: "taskcomp.ratingPurposeLoan", purchase: "taskcomp.ratingPurposePurchase", other: "taskcomp.ratingPurposeOther", }[ selectedPurpose as | "family" | "medical" | "loan" | "purchase" | "other" ] ) : t("taskcomp.ratingPurposePlaceholder")} {isPurposeDropdownOpen && ( {[ { key: "family", labelKey: "taskcomp.ratingPurposeFamily", }, { key: "medical", labelKey: "taskcomp.ratingPurposeMedical", }, { key: "loan", labelKey: "taskcomp.ratingPurposeLoan" }, { key: "purchase", labelKey: "taskcomp.ratingPurposePurchase", }, { key: "other", labelKey: "taskcomp.ratingPurposeOther" }, ].map((option) => ( { setSelectedPurpose(option.key); setIsPurposeDropdownOpen(false); }} > {t(option.labelKey as any)} ))} )} {selectedPurpose === "other" && ( {t("taskcomp.ratingOtherLabel")} )} )} ); }