diff --git a/components/doctor/detailDoctor/List.js b/components/doctor/detailDoctor/List.js index 4de120a..9b16283 100644 --- a/components/doctor/detailDoctor/List.js +++ b/components/doctor/detailDoctor/List.js @@ -9,8 +9,9 @@ import LinkedingBlueD from "@/components/icons/LinkedingBlueD"; import html2canvas from "html2canvas"; import jsPDF from "jspdf"; import { Button } from "@mui/material"; +import { toast } from "react-toastify"; -function List({ hiddenRef }) { +function List({ hiddenRef, data }) { const handleDownloadPDF = async () => { const element = hiddenRef.current; if (!element) return; @@ -38,12 +39,51 @@ function List({ hiddenRef }) { pdf.save("poster.pdf"); }; + const getShareUrl = () => + typeof window !== "undefined" ? window.location.href : ""; + + const getShareText = () => + data?.name ? `معرفی ${data.name} در نوبت 724` : "معرفی پزشک در نوبت 724"; + + const openShareWindow = (url) => { + if (typeof window !== "undefined") { + window.open(url, "_blank", "noopener,noreferrer"); + } + }; + + const handleWhatsapp = () => { + const text = encodeURIComponent(`${getShareText()}\n${getShareUrl()}`); + openShareWindow(`https://wa.me/?text=${text}`); + }; + + const handleTelegram = () => { + const url = encodeURIComponent(getShareUrl()); + const text = encodeURIComponent(getShareText()); + openShareWindow(`https://t.me/share/url?url=${url}&text=${text}`); + }; + + const handleLinkedin = () => { + const url = encodeURIComponent(getShareUrl()); + openShareWindow( + `https://www.linkedin.com/sharing/share-offsite/?url=${url}` + ); + }; + + const handleCopyLink = async () => { + try { + await navigator.clipboard.writeText(getShareUrl()); + toast.success("لینک کپی شد"); + } catch { + toast.error("کپی لینک ناموفق بود"); + } + }; + const listIcons = [ - { name: "واتساپ", icon: }, - { name: "تلگرام", icon: }, - { name: "لینکدین", icon: }, - { name: "کپی لینک", icon: }, - { name: "دانلود", icon: }, + { name: "واتساپ", icon: , onClick: handleWhatsapp }, + { name: "تلگرام", icon: , onClick: handleTelegram }, + { name: "لینکدین", icon: , onClick: handleLinkedin }, + { name: "کپی لینک", icon: , onClick: handleCopyLink }, + { name: "دانلود", icon: , onClick: handleDownloadPDF }, ]; return ( @@ -60,7 +100,8 @@ function List({ hiddenRef }) { !w-[24px] sm:!w-[28px] md:!w-[32px] lg:!w-[36px] !h-[24px] sm:!h-[28px] md:!h-[32px] lg:!h-[36px] " - onClick={handleDownloadPDF} + onClick={item.onClick} + aria-label={item.name} variant="text" >
+ + {item.name} + ))} diff --git a/components/doctor/detailDoctor/Share.js b/components/doctor/detailDoctor/Share.js index c0ed040..284550b 100644 --- a/components/doctor/detailDoctor/Share.js +++ b/components/doctor/detailDoctor/Share.js @@ -53,7 +53,7 @@ function Share({ data }) {

شما می توانید این پزشک را با دیگران به اشتراک بگذارید:

- +