import React, { useEffect, useRef, useState } from "react"; import { View, Text, ScrollView, Share } 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 ScreenWrapper from "~/components/ui/ScreenWrapper"; import ModalToast from "~/components/ui/toast"; import { useTranslation } from "react-i18next"; import LottieView from "lottie-react-native"; export default function RecipAddedComp() { const { t } = useTranslation(); const params = useLocalSearchParams<{ message?: string; recipientName?: string; recipientPhone?: string; }>(); 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 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 handleAddAnother = () => { // Navigate to add recipient page router.replace(ROUTES.ADD_RECIPIENT); }; const handleGoToRecipients = () => { // Navigate to list recipients page router.replace(ROUTES.LIST_RECIPIENTS); }; const handleShare = async () => { try { const shareMessage = params.message ? t("recipaddedcomp.shareMessageWithParam", { message: params.message, }) : t("recipaddedcomp.shareMessageDefault"); const result = await Share.share({ message: shareMessage, title: t("recipaddedcomp.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("recipaddedcomp.toastErrorTitle"), t("recipaddedcomp.toastShareError"), "error" ); } }; return ( {/* Center content */} {t("recipaddedcomp.title")} {t("recipaddedcomp.description")} ); }