below is the function that I created to copy a link, send it via whatsapp and send it via email but it’s showing just simple text on the email and whatsapp what am I missing here?
const handleShareOption = async (option: 'copy' | 'email' | 'whatsapp') => {
try {
const externalUrl = `${window.location.protocol}//${window.location.host}/report/view/${report.reportExternalId}`;
const message = `Confira este relatório: ${externalUrl}`;
const subject = 'Compartilhar Relatório';
const whatsappLink = `https://wa.me/?text=${encodeURIComponent(message)}`;
const mailtoLink = `mailto:?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(message)}`;
switch (option) {
case 'copy':
if (navigator.clipboard) {
try {
await navigator.clipboard.writeText(externalUrl);
toast.success('Link compartilhável copiado!');
} catch (error) {
toast.error('Não foi possível copiar o link. Tente novamente.');
}
} else {
// Fallback for browsers without clipboard API
try {
const textArea = document.createElement('textarea');
textArea.value = externalUrl;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
toast.success('Link copiado com sucesso!');
} catch (error) {
toast.error(
'Seu navegador não suporta copiar para área de transferência.'
);
}
}
break;
case 'email':
try {
window.open(mailtoLink, '_blank');
} catch (error) {
toast.error('Não foi possível abrir o cliente de email.');
}
break;
case 'whatsapp':
try {
window.open(whatsappLink, '_blank');
} catch (error) {
toast.error('Não foi possível abrir o WhatsApp.');
}
break;
default:
throw new Error('Opção inválida');
}
handleMenuClose(); // Close the menu after selecting an option
} catch (error) {
toast.error('Ocorreu um erro ao tentar compartilhar. Tente novamente.');
console.error(error); // Log the error for debugging purposes
}
};
So I’m making this so the user can share the link for its report but its only being send as a plain text and I want it to be a clickable link