import React, { useState, useEffect } from 'react';
import { Copy, Download, Wifi, Mail, Calendar, FolderOpen } from 'lucide-react';
import { peerAPI } from '../services/api';
function CopyButton({ text }) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch {}
};
return (
);
}
function InfoRow({ label, value }) {
return (
{label}
{value}
{value && }
);
}
export default function MyServices() {
const [data, setData] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState('');
useEffect(() => {
peerAPI.services()
.then(r => setData(r.data))
.catch(() => setError('Could not load services. Please try again.'))
.finally(() => setIsLoading(false));
}, []);
const downloadConfig = (filename, content) => {
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
if (isLoading) {
return (
);
}
if (error) {
return (
);
}
const wg = data?.wireguard || {};
const email = data?.email || {};
const caldav = data?.caldav || {};
const files = data?.files || {};
return (
My Services
Credentials and configuration for your personal services
WireGuard VPN
{wg.config && (
)}
{wg.qr_code && (
Scan with the WireGuard mobile app:
)}
Email
{(email.smtp || email.imap) && (
When setting up your mail client, use your dashboard username and password for authentication.
)}
Calendar & Contacts
{caldav.url && (
Use this URL in your calendar client. Authenticate with your username and dashboard password.
)}
Files
{files.url && (
Mount this URL as a network drive or use a WebDAV client. Authenticate with your username and dashboard password.
)}
Note: Changing your dashboard password does not update email, calendar, or files passwords.
);
}