perf: the support modal fixed

This commit is contained in:
Afra ‌ 2026-07-25 11:28:38 +03:30
parent 434b5b5235
commit ae70edf99b

View file

@ -1,42 +1,45 @@
import { useState } from 'react' import { useState } from "react";
import { createPortal } from 'react-dom' import { createPortal } from "react-dom";
import Icon from './Icon' import Icon from "./Icon";
const SUPPORT_PHONE = '02111111111' const SUPPORT_PHONE = "02111111111";
const SUPPORT_PHONE_DISPLAY = '۰۲۱-۱۱۱۱۱۱۱۱' const SUPPORT_PHONE_DISPLAY = "۰۲۱-۱۱۱۱۱۱۱۱";
function isMobileDevice() { function isMobileDevice() {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0 return "ontouchstart" in window || navigator.maxTouchPoints > 0;
} }
export default function SupportButton({ className }: { className?: string }) { export default function SupportButton({ className }: { className?: string }) {
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false);
const [copied, setCopied] = useState(false) const [copied, setCopied] = useState(false);
const handleClick = () => { const handleClick = () => {
if (isMobileDevice()) { if (isMobileDevice()) {
window.location.href = `tel:${SUPPORT_PHONE}` window.location.href = `tel:${SUPPORT_PHONE}`
} else { } else {
setOpen(true) setOpen(true);
} }
} };
const handleCopy = async () => { const handleCopy = async () => {
try { try {
await navigator.clipboard.writeText(SUPPORT_PHONE) await navigator.clipboard.writeText(SUPPORT_PHONE);
setCopied(true) setCopied(true);
setTimeout(() => setCopied(false), 2000) setTimeout(() => setCopied(false), 2000);
} catch { } catch {
// silent fallback // silent fallback
} }
} };
return ( return (
<> <>
<button <button
type="button" type="button"
onClick={handleClick} onClick={handleClick}
className={className ?? 'rounded-full bg-[#223D5D] px-5 py-3 font-semibold text-white'} className={
className ??
"rounded-full bg-[#223D5D] px-5 py-3 font-semibold text-white"
}
> >
پشتیبانی پشتیبانی
</button> </button>
@ -44,33 +47,47 @@ export default function SupportButton({ className }: { className?: string }) {
{open && {open &&
createPortal( createPortal(
<> <>
<div className="fixed inset-0 z-9998" onClick={() => setOpen(false)} /> <div
<div className="fixed inset-x-4 top-20 z-9999 rounded-2xl bg-white px-5 py-4 shadow-xl sm:inset-x-auto sm:left-1/2 sm:w-96 sm:-translate-x-1/2"> className="fixed inset-0 z-9998 bg-black/40"
<button onClick={() => setOpen(false)}
type="button" />
onClick={() => setOpen(false)} <div
className="absolute left-4 top-4 flex h-7 w-7 items-center justify-center text-gray-400 hover:text-gray-600" dir="rtl"
aria-label="بستن" className="fixed inset-x-6 top-1/2 z-9999 -translate-y-1/2 rounded-2xl bg-white px-5 shadow-xl"
> style={{ height: "72px" }}
✕ >
</button> <div className="flex h-full items-center justify-start gap-3">
<div className="flex items-center justify-end gap-3 pt-1"> <p className="text-right text-gray-900">
{copied ? (
"کپی شد!"
) : (
<div className="flex items-center gap-2">
شماره تماس پشتیبانی:{" "}
<span dir="ltr">{SUPPORT_PHONE_DISPLAY}</span>
<button
type="button"
onClick={handleCopy}
aria-label="کپی شماره"
className="shrink-0 text-gray-400 transition-colors hover:text-gray-700"
>
<Icon name="copy" className="h-5 w-5" />
</button>
</div>
)}
</p>
<button <button
type="button" type="button"
onClick={handleCopy} onClick={() => setOpen(false)}
aria-label="کپی شماره" className="absolute left-3 top-1/3 -translate-y-1/2 text-black hover:text-gray-600"
className="shrink-0 text-gray-400 transition-colors hover:text-gray-700" aria-label="بستن"
> >
<Icon name="copy" className="h-5 w-5" /> ✕
</button> </button>
<p dir="ltr" className="text-right text-gray-900">
{copied ? 'کپی شد!' : `شماره تماس پشتیبانی: ${SUPPORT_PHONE_DISPLAY}`}
</p>
</div> </div>
</div> </div>
</>, </>,
document.body, document.body,
)} )}
</> </>
) );
} }