"use client"; import { useState } from "react"; import { toast } from "sonner"; import { Clock, Link2, Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { requestAccountLink } from "@/lib/actions/account-links"; /** * "Request Account Link": asks to link this account with another one on * the server by email. On success the form is replaced by the * "awaiting confirmation" status, since the recipient still has to accept * it from their own Profile page. */ export function RequestLinkForm() { const [email, setEmail] = useState(""); const [submitting, setSubmitting] = useState(false); // Set once a request goes out; the section then shows the awaiting // confirmation status until the recipient responds (or it's denied). const [requestedEmail, setRequestedEmail] = useState(null); async function handleSubmit(event: React.FormEvent) { event.preventDefault(); if (submitting) return; setSubmitting(true); try { const result = await requestAccountLink(email); if (result?.error) { toast.error(result.error); return; } setRequestedEmail(email.trim().toLowerCase()); toast.success("Link request sent."); } catch { toast.error("Couldn't send the link request. Try again."); } finally { setSubmitting(false); } } return ( Request Account Link Link this account with another account on this server so you can toggle between them. The other account has to accept the request. {requestedEmail ? (
Request sent to{" "} {requestedEmail} — awaiting confirmation.
) : (
setEmail(e.target.value)} />
)}
); }