"use client"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { getSubmitPath } from "@/lib/get-submit-path"; import { FiCopy, FiPhone } from "react-icons/fi"; import CallResultSheet from "@/components/ui/call-result-sheet"; import FemaleConsentSheet from "@/components/ui/female-consent-sheet"; import NavigationButton from "@/components/ui/navigation-button"; import SubscriptionRequiredSheet from "@/components/ui/subscription-required-sheet"; import { PageBackground } from "@/components/utils/page-background"; import type { MarriageField, MarriagePhoneFieldValue } from "@/hooks/marriage/types"; import { useMarriageContactInfoQuery } from "@/hooks/marriage/use-contact-info"; import { useSubmitMarriageContactStatusMutation } from "@/hooks/marriage/use-contact-status"; import { extractHabcoinPaymentUrl, useHabcoinPaymentMutation, } from "@/hooks/marriage/use-habcoin-payment"; import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main"; import { localizePath } from "@/translations/config"; import { useI18n } from "@/translations/provider"; type ContactInfoPhoneItem = { key: string; label: string; phoneNumber: string; }; function sanitizePhoneNumber(value: MarriageField["value"]) { if (value === null || value === "") { return null; } if (isMarriagePhoneFieldValue(value)) { const digits = value.phoneNumber.replace(/\D/g, ""); return digits ? `+${value.countryCode}${digits}` : null; } const trimmedValue = String(value).trim(); if (!trimmedValue) { return null; } const digits = trimmedValue.replace(/\D/g, ""); if (!digits) { return null; } return trimmedValue.startsWith("+") ? `+${digits}` : digits; } function isMarriagePhoneFieldValue( value: unknown, ): value is MarriagePhoneFieldValue { if (!value || typeof value !== "object") { return false; } const phoneValue = value as Partial; return ( typeof phoneValue.countryCode === "string" && typeof phoneValue.phoneNumber === "string" ); } function getContactInfoPhoneItems( contactInfoFields: MarriageField[] | null | undefined, ): ContactInfoPhoneItem[] { if (!contactInfoFields) { return []; } return contactInfoFields .map((field) => { const phoneNumber = sanitizePhoneNumber(field.value); if (!phoneNumber) { return null; } return { key: field.key, label: field.label || field.key, phoneNumber, }; }) .filter((item): item is ContactInfoPhoneItem => item !== null); } function ContactInfoPhoneCard({ item }: { item: ContactInfoPhoneItem }) { return (

{item.label}

{item.phoneNumber}

copy
); } export default function RequestAcceptedPage() { const { locale } = useI18n(); const router = useRouter(); const [isCallResultSheetOpen, setIsCallResultSheetOpen] = useState(false); const [isContactInfoSheetOpen, setIsContactInfoSheetOpen] = useState(false); const [isSubscriptionSheetOpen, setIsSubscriptionSheetOpen] = useState(false); const profileHref = localizePath("/new-match/profile", locale); const { data: profile } = useMarriageProfileQuery({ refetchInterval: 3000, }); useEffect(() => { if (!profile) { return; } const targetPath = getSubmitPath(profile); if (targetPath !== "/request-accepted") { router.replace(localizePath(targetPath, locale)); } }, [profile, router, locale]); const isFemaleProfile = profile?.gender === "female"; const caseId = profile?.active_case?.case_id; const caseStatus = profile?.active_case?.status; const recommendedPlanId = profile?.recommended_plan?.id; const paymentMutation = useHabcoinPaymentMutation(); const contactStatusMutation = useSubmitMarriageContactStatusMutation(caseId ?? "", { onSuccess: () => { router.push(localizePath("/finding-match", locale)); }, }); const contactInfoQuery = useMarriageContactInfoQuery(caseId, { enabled: false, }); const titleText = isFemaleProfile ? "درخواست تایید شد" : caseStatus === "payment_done" ? "اطلاعات تماس آزاد شد" : "درخواست توسط خانم تایید شد!"; const primaryActionText = isFemaleProfile ? "اطلاع‌رسانی عدم تماس" : "مشاهده پروفایل"; const secondaryActionText = isFemaleProfile ? "ثبت نتیجه تماس" : caseStatus === "payment_done" ? "مشاهده شماره تماس" : "پرداخت و دریافت تماس"; const contactInfoPhoneItems = getContactInfoPhoneItems( contactInfoQuery.data?.contact_info, ); const handleSecondaryAction = async () => { if (isFemaleProfile) { setIsCallResultSheetOpen(true); return; } if (caseStatus === "female_accepted" || caseStatus === "payment_pending") { setIsSubscriptionSheetOpen(true); return; } if (caseStatus === "payment_done") { if (!caseId) { return; } if (!contactInfoQuery.data) { await contactInfoQuery.refetch(); } setIsContactInfoSheetOpen(true); } }; const handlePayment = async () => { if (!recommendedPlanId || paymentMutation.isPending) { return; } try { const paymentResponse = await paymentMutation.mutateAsync(recommendedPlanId); const paymentUrl = extractHabcoinPaymentUrl(paymentResponse); if (paymentUrl) { window.location.assign(paymentUrl); return; } router.push(profileHref); } catch (error) { console.error("Habcoin payment request failed", error); } }; const handleNoContactReport = async () => { if (!caseId || contactStatusMutation.isPending) return; await contactStatusMutation.mutateAsync({ action: "no_contact", custom_note: "No contact reported by female candidate after decision window", }); }; return ( <> {isCallResultSheetOpen ? ( setIsCallResultSheetOpen(false)} onSubmit={async (value) => { if (caseId) { await contactStatusMutation.mutateAsync({ action: "contacted", custom_note: value, }); } }} /> ) : null} {isContactInfoSheetOpen ? ( {contactInfoPhoneItems.map((item) => ( ))} ) : (
Contact information is not available yet.
) } onClose={() => setIsContactInfoSheetOpen(false)} /> ) : null} {isSubscriptionSheetOpen ? ( setIsSubscriptionSheetOpen(false)} onPayment={handlePayment} isPaymentPending={!recommendedPlanId || paymentMutation.isPending} /> ) : null}

Habib Marriage

Request sent

{titleText}

You can now view their family's contact details and arrange further steps.

{isFemaleProfile ? ( ) : (
{primaryActionText}
)}

If they don’t contact you within 2 days, please inform us.

lock

Profile is locked

); }