import { useRef, useState } from "react"; import { Box, Button, Group, Image, Paper, Stack, Text } from "@mantine/core"; import { RefreshCw, Stamp, X } from "lucide-react"; const MAX_STAMP_MB = 5; export interface StampUploadProps { /** Stamp image as a data URL, or null when none is attached yet. */ value: string | null; onChange: (dataUrl: string | null) => void; label?: string; description?: string; } /** * Company stamp/seal attachment for the contract signing modal. Reads the * picked image straight into a data URL because the signing endpoint takes * base64 in JSON (same transport as the drawn signature), not multipart. */ export function StampUpload({ value, onChange, label = "Company stamp", description = "Attach your official company stamp or seal.", }: StampUploadProps) { const inputRef = useRef(null); const [dragging, setDragging] = useState(false); const [error, setError] = useState(null); const [fileName, setFileName] = useState(null); const readFile = (file: File | undefined | null) => { if (!file) return; if (!file.type.startsWith("image/")) { setError("The stamp must be an image file (PNG or JPG)."); return; } if (file.size > MAX_STAMP_MB * 1024 * 1024) { setError(`The stamp image must be under ${MAX_STAMP_MB} MB.`); return; } const reader = new FileReader(); reader.onload = () => { setError(null); setFileName(file.name); onChange(typeof reader.result === "string" ? reader.result : null); }; reader.onerror = () => setError("Could not read that file. Try another."); reader.readAsDataURL(file); }; const openPicker = () => inputRef.current?.click(); const clear = () => { setFileName(null); setError(null); onChange(null); if (inputRef.current) inputRef.current.value = ""; }; return ( {label} readFile(e.currentTarget.files?.[0])} /> {value ? ( Company stamp {fileName ?? "Stamp attached"} This stamp is applied next to your signature on the contract. ) : ( { e.preventDefault(); setDragging(true); }} onDragLeave={() => setDragging(false)} onDrop={(e) => { e.preventDefault(); setDragging(false); readFile(e.dataTransfer.files?.[0]); }} style={{ borderColor: dragging ? "var(--mantine-color-edr-green-6)" : undefined, borderStyle: "dashed", backgroundColor: dragging ? "var(--mantine-color-edr-green-0)" : undefined, cursor: "pointer", }} > Upload company stamp {description} Drop an image here or click to browse — PNG or JPG, up to {MAX_STAMP_MB} MB. )} {error && ( {error} )} ); }