import { useRouter } from "next/navigation"; import Image from "next/image"; import { useCallback, useState } from "react"; import { FileWithPath } from "react-dropzone"; import { Icon } from "@iconify/react"; import dayjs from "dayjs"; import SubmitDialogButton from "./submit-dialog-button"; import Dropzone from "../dropzone"; export default function ProfilePictureSettings() { const router = useRouter(); const [error, setError] = useState(undefined); const [newPicture, setNewPicture] = useState(); const changeDate = dayjs().add(7, "days"); const handleSubmit = async (close: () => void) => { const formData = new FormData(); if (newPicture) formData.append("image", newPicture); const response = await fetch("/api/auth/picture", { method: "PATCH", body: formData, }); if (!response.ok) { const { error } = await response.json(); setError(error); return; } close(); router.refresh(); }; const handleDrop = useCallback((acceptedFiles: FileWithPath[]) => { if (!acceptedFiles[0]) return; setNewPicture(acceptedFiles[0]); }, []); return (

Manage your profile picture. Can only be changed once every 7 days.

Drag and drop your profile picture here
or click to open

new profile picture
{newPicture && ( )}

After submitting, you can change it again on {changeDate.toDate().toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" })} .

New profile picture:

new profile picture
); }