import { useCallback, useState } from "react"; import { type FileWithPath } from "react-dropzone"; import { Icon } from "@iconify/react"; import dayjs from "dayjs"; import SubmitDialogButton from "./submit-dialog-button"; import Dropzone from "../dropzone"; import { useNavigate } from "react-router"; export default function ProfilePictureSettings() { const navigate = useNavigate(); 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(`${import.meta.env.VITE_API_URL}/api/auth/picture`, { method: "POST", body: formData, credentials: "include", }); if (!response.ok) { const { error } = await response.json(); setError(error); return; } close(); navigate(0); }; 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
); }