Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
cf9f908f6c
commit
61111bedb7
@@ -47,6 +47,59 @@ function PleadingNewPage() {
|
||||
const [docName, setDocName] = useState("Pleading");
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
// Attorney signature (loaded from profile)
|
||||
const [includeSignature, setIncludeSignature] = useState(true);
|
||||
const [sigBlock, setSigBlock] = useState("");
|
||||
const [sigImagePath, setSigImagePath] = useState<string>("");
|
||||
const [sigImageBytes, setSigImageBytes] = useState<Uint8Array | null>(null);
|
||||
const [sigImageDataUrl, setSigImageDataUrl] = useState<string>("");
|
||||
const [sigImageType, setSigImageType] = useState<"png" | "jpg" | "jpeg">("png");
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
(async () => {
|
||||
const { data } = await supabase
|
||||
.from("profiles")
|
||||
.select("*")
|
||||
.eq("id", user.id)
|
||||
.maybeSingle();
|
||||
if (!data) return;
|
||||
const d = data as any;
|
||||
setSigBlock(d.signature_block ?? "");
|
||||
setSigImagePath(d.signature_image_path ?? "");
|
||||
if (d.signature_image_path) {
|
||||
try {
|
||||
const url = supabase.storage
|
||||
.from("avatars")
|
||||
.getPublicUrl(d.signature_image_path).data.publicUrl;
|
||||
const res = await fetch(url);
|
||||
const blob = await res.blob();
|
||||
const buf = new Uint8Array(await blob.arrayBuffer());
|
||||
setSigImageBytes(buf);
|
||||
// Build a data URL for the PDF generator
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => setSigImageDataUrl(String(reader.result || ""));
|
||||
reader.readAsDataURL(blob);
|
||||
const ext = (d.signature_image_path.split(".").pop() || "png").toLowerCase();
|
||||
setSigImageType(ext === "jpg" || ext === "jpeg" ? "jpg" : "png");
|
||||
} catch {
|
||||
// Ignore – signature image is optional
|
||||
}
|
||||
}
|
||||
})();
|
||||
}, [user?.id]);
|
||||
|
||||
const buildSignature = (): PleadingSignature | undefined => {
|
||||
if (!includeSignature) return undefined;
|
||||
if (!sigBlock.trim() && !sigImageBytes) return undefined;
|
||||
return {
|
||||
block: sigBlock,
|
||||
imageBytes: sigImageBytes ?? undefined,
|
||||
imageDataUrl: sigImageDataUrl || undefined,
|
||||
imageType: sigImageType,
|
||||
};
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!from) return;
|
||||
(async () => {
|
||||
|
||||
Reference in New Issue
Block a user