"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import dayjs from "dayjs"; import { displayNameSchema, usernameSchema } from "@/lib/schemas"; import ProfilePictureSettings from "./profile-picture"; import SubmitDialogButton from "./submit-dialog-button"; import DeleteAccount from "./delete-account"; import z from "zod"; interface Props { currentDescription: string | null | undefined; } export default function ProfileSettings({ currentDescription }: Props) { const router = useRouter(); const [description, setDescription] = useState(currentDescription); const [displayName, setDisplayName] = useState(""); const [username, setUsername] = useState(""); const [descriptionChangeError, setDescriptionChangeError] = useState(undefined); const [displayNameChangeError, setDisplayNameChangeError] = useState(undefined); const [usernameChangeError, setUsernameChangeError] = useState(undefined); const usernameDate = dayjs().add(90, "days"); const handleSubmitDescriptionChange = async (close: () => void) => { const parsed = z.string().trim().max(256).safeParse(description); if (!parsed.success) { setDescriptionChangeError(parsed.error.issues[0].message); return; } const response = await fetch("/api/auth/about-me", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ description }), }); if (!response.ok) { const { error } = await response.json(); setDescriptionChangeError(error); return; } close(); router.refresh(); }; const handleSubmitDisplayNameChange = async (close: () => void) => { const parsed = displayNameSchema.safeParse(displayName); if (!parsed.success) { setDisplayNameChangeError(parsed.error.issues[0].message); return; } const response = await fetch("/api/auth/display-name", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ displayName }), }); if (!response.ok) { const { error } = await response.json(); setDisplayNameChangeError(error); return; } close(); router.refresh(); }; const handleSubmitUsernameChange = async (close: () => void) => { const parsed = usernameSchema.safeParse(username); if (!parsed.success) { setUsernameChangeError(parsed.error.issues[0].message); return; } const response = await fetch("/api/auth/username", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username }), }); if (!response.ok) { const { error } = await response.json(); setUsernameChangeError(error); return; } close(); router.refresh(); }; return (

Profile Settings

Update your account info, and username.

{/* Separator */}

Account Info
{/* Profile Picture */} {/* Description */}

Write about yourself on your profile