diff --git a/application/src/App.tsx b/application/src/App.tsx index 02a1ba1..cd62250 100644 --- a/application/src/App.tsx +++ b/application/src/App.tsx @@ -50,7 +50,7 @@ function App() { } /> } /> - } /> + } /> {/* Protected Routes */} { if (page.custom_domain) { window.open(`https://${page.custom_domain}`, '_blank'); } else { - // Navigate to the public status page route - window.open(`/status/${page.slug}`, '_blank'); + // Navigate to the public status page route using the correct format + window.open(`/public/${page.slug}`, '_blank'); } }; diff --git a/application/src/components/regional-monitoring/AddRegionalAgentDialog.tsx b/application/src/components/regional-monitoring/AddRegionalAgentDialog.tsx index 14d8bd4..70caad3 100644 --- a/application/src/components/regional-monitoring/AddRegionalAgentDialog.tsx +++ b/application/src/components/regional-monitoring/AddRegionalAgentDialog.tsx @@ -1,4 +1,3 @@ - import React, { useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; @@ -54,19 +53,69 @@ export const AddRegionalAgentDialog: React.FC = ({ } }; - const copyToClipboard = async (text: string) => { + const copyToClipboard = async (text: string, description: string = "Content") => { try { - await navigator.clipboard.writeText(text); - toast({ - title: "Copied!", - description: "Installation script copied to clipboard.", - }); + // Try the modern clipboard API first + if (navigator.clipboard && window.isSecureContext) { + await navigator.clipboard.writeText(text); + toast({ + title: "Copied!", + description: `${description} copied to clipboard.`, + }); + return; + } + + // Fallback for older browsers or non-secure contexts (like localhost) + const textArea = document.createElement('textarea'); + textArea.value = text; + textArea.style.position = 'fixed'; + textArea.style.left = '-999999px'; + textArea.style.top = '-999999px'; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + const successful = document.execCommand('copy'); + document.body.removeChild(textArea); + + if (successful) { + toast({ + title: "Copied!", + description: `${description} copied to clipboard.`, + }); + } else { + throw new Error('execCommand failed'); + } } catch (error) { + console.error('Failed to copy to clipboard:', error); + + // Show the text in a modal or alert as final fallback + const userAgent = navigator.userAgent.toLowerCase(); + const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'; + + let errorMessage = "Failed to copy to clipboard."; + if (isLocalhost) { + errorMessage += " This is common in local development. Please manually copy the text."; + } else if (userAgent.includes('chrome')) { + errorMessage += " Try using HTTPS or enable clipboard permissions."; + } + toast({ title: "Copy failed", - description: "Failed to copy to clipboard.", + description: errorMessage, variant: "destructive", }); + + // As a last resort, select the text for manual copying + try { + const textarea = document.querySelector('textarea[readonly]') as HTMLTextAreaElement; + if (textarea) { + textarea.select(); + textarea.setSelectionRange(0, 99999); // For mobile devices + } + } catch (selectError) { + console.error('Failed to select text:', selectError); + } } }; @@ -89,16 +138,6 @@ export const AddRegionalAgentDialog: React.FC = ({ }); }; - const copyOneClickCommand = () => { - if (!installCommand) return; - - const oneClickCommand = `curl -fsSL -H "User-Agent: CheckCle-Installer" \\ - "data:text/plain;base64,$(echo '${installCommand.bash_script}' | base64 -w 0)" \\ - | sudo bash`; - - copyToClipboard(oneClickCommand); - }; - const handleComplete = () => { onAgentAdded(); setStep(1); @@ -211,7 +250,7 @@ export const AddRegionalAgentDialog: React.FC = ({