From 5fce761b938dff32797142fb30322e6207636cf2 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Sat, 4 Apr 2026 19:02:22 +0000 Subject: [PATCH] removed raw fetch from property drawer --- .../your-projects/live/PropertyDrawer.tsx | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/app/portfolio/[slug]/(portfolio)/your-projects/live/PropertyDrawer.tsx b/src/app/portfolio/[slug]/(portfolio)/your-projects/live/PropertyDrawer.tsx index dec0cba..6dc83ef 100644 --- a/src/app/portfolio/[slug]/(portfolio)/your-projects/live/PropertyDrawer.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/your-projects/live/PropertyDrawer.tsx @@ -1,7 +1,7 @@ "use client"; -import { useQuery } from "@tanstack/react-query"; -import { useRef, useState } from "react"; +import { useQuery, useMutation } from "@tanstack/react-query"; +import { useRef } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { FileDown, @@ -57,12 +57,10 @@ function formatDate(iso: string): string { // Individual document row // ----------------------------------------------------------------------- function DocumentRow({ doc }: { doc: PropertyDocument }) { - const [signing, setSigning] = useState(false); const label = DOC_TYPE_LABELS[doc.docType] ?? doc.docType; - async function handleDownload() { - setSigning(true); - try { + const { mutate: download, isPending: signing } = useMutation({ + mutationFn: async () => { const res = await fetch("/api/sign-document-url", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -70,17 +68,12 @@ function DocumentRow({ doc }: { doc: PropertyDocument }) { }); if (!res.ok) throw new Error("Failed to get signed URL"); const data = await res.json(); - window.open(data.url, "_blank"); - } catch { - // Fallback: construct raw S3 URL - window.open( - `https://${doc.s3FileBucket}.s3.amazonaws.com/${doc.s3FileKey}`, - "_blank", - ); - } finally { - setSigning(false); - } - } + return data.url as string; + }, + onSuccess: (url) => { + window.open(url, "_blank"); + }, + }); return ( download()} disabled={signing} className="shrink-0 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-brandblue text-white text-xs font-medium hover:bg-brandblue/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed" >