Fix copy link & Instagram sharing: add clipboard fallback for HTTP
All checks were successful
Build frontend / build (push) Successful in 52s
All checks were successful
Build frontend / build (push) Successful in 52s
This commit is contained in:
@ -49,6 +49,30 @@ import { getRentProperty, getSaleProperty, bookReservation, checkAvailability, g
|
||||
import AuthService from '../../services/AuthService';
|
||||
import { BuildingTypeKeys, PropertyStatusKeys, extractCity } from '../../enums';
|
||||
|
||||
// Copy to clipboard that works on HTTP too
|
||||
async function copyToClipboard(text) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
// Fallback for HTTP / older browsers
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.opacity = '0';
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Map API response to the UI format
|
||||
function mapApiDetail(item) {
|
||||
if (!item) return null;
|
||||
@ -478,9 +502,13 @@ export default function PropertyDetailsPage() {
|
||||
|
||||
{/* Instagram (copy link) */}
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(window.location.href);
|
||||
toast.success('تم نسخ الرابط! الصقه في انستغرام');
|
||||
onClick={async () => {
|
||||
const ok = await copyToClipboard(window.location.href);
|
||||
if (ok) {
|
||||
toast.success('تم نسخ الرابط! الصقه في انستغرام');
|
||||
} else {
|
||||
toast.error('فشل نسخ الرابط');
|
||||
}
|
||||
window.open('https://www.instagram.com', '_blank');
|
||||
setShowShareMenu(false);
|
||||
}}
|
||||
@ -494,9 +522,13 @@ export default function PropertyDetailsPage() {
|
||||
|
||||
{/* Copy Link */}
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(window.location.href);
|
||||
toast.success('تم نسخ الرابط');
|
||||
onClick={async () => {
|
||||
const ok = await copyToClipboard(window.location.href);
|
||||
if (ok) {
|
||||
toast.success('✅ تم نسخ الرابط');
|
||||
} else {
|
||||
toast.error('فشل نسخ الرابط');
|
||||
}
|
||||
setShowShareMenu(false);
|
||||
}}
|
||||
className="w-full flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-gray-100 transition-colors"
|
||||
|
||||
Reference in New Issue
Block a user