You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
6.1 KiB
192 lines
6.1 KiB
"use client";
|
|
|
|
import Image from "next/image";
|
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
import { createPortal } from "react-dom";
|
|
import { Ic } from "@/icons";
|
|
import { useHardwareBackHandler } from "@/hooks/use-hardware-back-handler";
|
|
import { useI18n } from "@/translations/provider";
|
|
|
|
const EXIT_ANIMATION_MS = 200;
|
|
|
|
export type SupportSheetProps = {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
};
|
|
|
|
export function SupportSheet({ isOpen, onClose }: SupportSheetProps) {
|
|
const { dictionary: t } = useI18n();
|
|
const [mounted, setMounted] = useState(false);
|
|
const [isRendered, setIsRendered] = useState(isOpen);
|
|
const [isClosing, setIsClosing] = useState(false);
|
|
const isClosingRef = useRef(false);
|
|
const isMountedRef = useRef(true);
|
|
const prevIsOpenRef = useRef(isOpen);
|
|
const timerRef = useRef<number | null>(null);
|
|
|
|
useEffect(() => {
|
|
isMountedRef.current = true;
|
|
setMounted(true);
|
|
return () => {
|
|
isMountedRef.current = false;
|
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
};
|
|
}, []);
|
|
|
|
const closeSheet = useCallback(() => {
|
|
if (isClosingRef.current) return;
|
|
isClosingRef.current = true;
|
|
setIsClosing(true);
|
|
|
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
timerRef.current = window.setTimeout(() => {
|
|
if (isMountedRef.current) {
|
|
setIsRendered(false);
|
|
setIsClosing(false);
|
|
isClosingRef.current = false;
|
|
}
|
|
onClose();
|
|
}, EXIT_ANIMATION_MS);
|
|
}, [onClose]);
|
|
|
|
// When isOpen changes from outside
|
|
useEffect(() => {
|
|
if (prevIsOpenRef.current !== isOpen) {
|
|
prevIsOpenRef.current = isOpen;
|
|
if (isOpen) {
|
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
isClosingRef.current = false;
|
|
setIsClosing(false);
|
|
setIsRendered(true);
|
|
} else if (!isClosingRef.current && isRendered) {
|
|
closeSheet();
|
|
}
|
|
}
|
|
}, [isOpen, isRendered, closeSheet]);
|
|
|
|
useHardwareBackHandler(closeSheet, isRendered && !isClosing);
|
|
|
|
// Lock body scroll
|
|
useEffect(() => {
|
|
if (!isRendered || !mounted) return;
|
|
const previousBodyOverflow = document.body.style.overflow;
|
|
const previousHtmlOverflow = document.documentElement.style.overflow;
|
|
document.body.style.overflow = "hidden";
|
|
document.documentElement.style.overflow = "hidden";
|
|
return () => {
|
|
document.body.style.overflow = previousBodyOverflow;
|
|
document.documentElement.style.overflow = previousHtmlOverflow;
|
|
};
|
|
}, [isRendered, mounted]);
|
|
|
|
const handleSupportContact = () => {
|
|
if (typeof window !== "undefined" && "HabibApp" in window) {
|
|
try {
|
|
const app = (
|
|
window as Window & {
|
|
HabibApp?: { postMessage: (msg: string) => void };
|
|
}
|
|
).HabibApp;
|
|
app?.postMessage(
|
|
JSON.stringify({
|
|
action: "open_consultant_page",
|
|
data: { consultant: "marriage_specialist@habibapp.com" },
|
|
}),
|
|
);
|
|
} catch (err) {
|
|
console.error("Error calling HabibApp bridge", err);
|
|
}
|
|
} else {
|
|
window.open("mailto:marriage_specialist@habibapp.com", "_blank");
|
|
}
|
|
closeSheet();
|
|
};
|
|
|
|
if (!isRendered || !mounted) return null;
|
|
|
|
return createPortal(
|
|
<div
|
|
className={[
|
|
"fixed inset-0 z-[100] flex items-end justify-center select-none",
|
|
isClosing ? "flutter-scrim-exit" : "flutter-scrim",
|
|
]
|
|
.filter(Boolean)
|
|
.join(" ")}
|
|
role="dialog"
|
|
aria-modal="true"
|
|
onClick={(event) => {
|
|
if (event.target === event.currentTarget) {
|
|
closeSheet();
|
|
}
|
|
}}
|
|
>
|
|
<section
|
|
className={[
|
|
"w-full max-w-[834px] sm:max-w-[540px] rounded-t-[22px] bg-white px-[14px] py-[14px] text-center shadow-[0_20px_60px_rgba(15,23,42,0.08)] flex flex-col items-center",
|
|
isClosing ? "flutter-sheet-surface-exit" : "flutter-sheet-surface",
|
|
]
|
|
.filter(Boolean)
|
|
.join(" ")}
|
|
>
|
|
<div className="flex flex-col items-center w-full gap-[11px]">
|
|
{/* Support Icon */}
|
|
<div className="flex h-[38px] w-[38px] items-center justify-center">
|
|
<Ic
|
|
name="headphones"
|
|
className="size-[27px] shrink-0 text-[#21C17D]"
|
|
/>
|
|
</div>
|
|
|
|
{/* Text Content */}
|
|
<div className="flex flex-col items-start gap-[14px] w-full">
|
|
<h3 className="w-full font-bold text-[16px] leading-[20px] text-[#111111] text-center">
|
|
{t["Contact Advisors"] || t["Contact Support"]}
|
|
</h3>
|
|
|
|
<p className="w-full font-normal text-[14px] leading-[20px] text-[#747474] text-center">
|
|
{
|
|
t[
|
|
"If you encounter any issues, please feel free to contact our advisors in WhatsApp"
|
|
] ||
|
|
t[
|
|
"If you encounter any issues, please feel free to contact our support specialists in WhatsApp"
|
|
]
|
|
}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Buttons Row */}
|
|
<div className="flex w-full items-center gap-3 mt-[14px]">
|
|
{/* Cancel Button */}
|
|
<button
|
|
type="button"
|
|
onClick={closeSheet}
|
|
className="flex-1 h-[52px] rounded-[11px] border border-[#747474] bg-transparent text-[#747474] font-semibold text-[16px] flex items-center justify-center cursor-pointer transition-transform active:scale-[0.98]"
|
|
>
|
|
{t["Cancel"]}
|
|
</button>
|
|
|
|
{/* Contact WhatsApp Button */}
|
|
<button
|
|
type="button"
|
|
onClick={handleSupportContact}
|
|
className="flex-1 h-[52px] rounded-[11px] bg-[#00AC78] text-white font-bold text-[16px] flex items-center justify-center gap-1 cursor-pointer transition-transform active:scale-[0.98]"
|
|
>
|
|
<Image
|
|
src="/assets/images/whatsapp-icon.svg"
|
|
alt=""
|
|
width={21}
|
|
height={21}
|
|
className="shrink-0 brightness-0 invert"
|
|
/>
|
|
{t["Contact"]}
|
|
</button>
|
|
</div>
|
|
</section>
|
|
</div>,
|
|
document.body,
|
|
);
|
|
}
|
|
|
|
export default SupportSheet;
|