mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
removed raw fetch from property drawer
This commit is contained in:
parent
06cfdf6689
commit
5fce761b93
1 changed files with 11 additions and 18 deletions
|
|
@ -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 (
|
||||
<motion.div
|
||||
|
|
@ -104,7 +97,7 @@ function DocumentRow({ doc }: { doc: PropertyDocument }) {
|
|||
|
||||
{/* Right: download button */}
|
||||
<button
|
||||
onClick={handleDownload}
|
||||
onClick={() => 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"
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue