"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { updateSocialLinks } from "@/actions/settings"; import { Loader2, Link } from "lucide-react"; import { GithubIcon, LinkedInIcon, XIcon } from "../icons"; interface SocialLinksFormProps { socialLinks?: { github?: string; twitter?: string; linkedin?: string; custom?: string[]; } | null; } export function SocialLinksForm({ socialLinks }: SocialLinksFormProps) { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const [customLinks, setCustomLinks] = useState([socialLinks?.custom?.[0] || "", socialLinks?.custom?.[1] || "", socialLinks?.custom?.[2] || ""]); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(null); setSuccess(false); const formData = new FormData(e.currentTarget); try { await updateSocialLinks({ github: formData.get("github") as string, twitter: formData.get("twitter") as string, linkedin: formData.get("linkedin") as string, custom: customLinks.filter(Boolean), }); setSuccess(true); setTimeout(() => setSuccess(false), 3000); } catch (err) { setError(err instanceof Error ? err.message : "Failed to update social links"); } finally { setLoading(false); } } return (
{[0, 1, 2].map((i) => ( { const newLinks = [...customLinks]; newLinks[i] = e.target.value; setCustomLinks(newLinks); }} placeholder={`Custom link ${i + 1}`} type="url" /> ))}

Add up to 3 custom links to your profile

{error &&
{error}
} {success &&
Social links updated!
}
); }