summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-07-21 02:55:28 +0000
committerjoonhoekim <26rote@gmail.com>2025-07-21 02:55:28 +0000
commit89de030f3fc74f4d665517ad62141328d1702e5a (patch)
tree046b3fdfa2471e0443fdc82b00a8594482d40194 /lib
parentd8e0c42836690ddbf91b9a78d487993b22669f81 (diff)
(deprecated) 기존 rfq 첨부파일 다운로드 오류 수정
Diffstat (limited to 'lib')
-rw-r--r--lib/rfqs/table/attachment-rfq-sheet.tsx37
1 files changed, 18 insertions, 19 deletions
diff --git a/lib/rfqs/table/attachment-rfq-sheet.tsx b/lib/rfqs/table/attachment-rfq-sheet.tsx
index 75235b32..fdfb5e9a 100644
--- a/lib/rfqs/table/attachment-rfq-sheet.tsx
+++ b/lib/rfqs/table/attachment-rfq-sheet.tsx
@@ -24,7 +24,7 @@ import {
FormMessage,
FormDescription
} from "@/components/ui/form"
-import { Trash2, Plus, Loader, Download, X, Eye, AlertCircle } from "lucide-react"
+import { Loader, Download, X, Eye, AlertCircle } from "lucide-react"
import { useToast } from "@/hooks/use-toast"
import { Badge } from "@/components/ui/badge"
@@ -45,15 +45,15 @@ import {
FileListInfo,
FileListItem,
FileListName,
- FileListSize,
} from "@/components/ui/file-list"
import prettyBytes from "pretty-bytes"
import { processRfqAttachments } from "../service"
-import { format } from "path"
import { formatDate } from "@/lib/utils"
import { RfqType } from "../validations"
import { RfqWithItemCount } from "@/db/schema/rfq"
+import { quickDownload } from "@/lib/file-download"
+import { type FileRejection } from "react-dropzone"
const MAX_FILE_SIZE = 6e8 // 600MB
@@ -116,7 +116,7 @@ export function RfqAttachmentsSheet({
const { toast } = useToast()
const [isPending, startUpdate] = React.useTransition()
const rfqId = rfq?.rfqId ?? 0;
-
+
// 편집 가능 여부 확인 - DRAFT 상태일 때만 편집 가능
const isEditable = rfq?.status === "DRAFT";
@@ -167,7 +167,7 @@ export function RfqAttachmentsSheet({
async function onSubmit(data: AttachmentsFormValues) {
// 편집 불가능한 상태에서는 제출 방지
if (!isEditable) return;
-
+
startUpdate(async () => {
try {
const removedExistingIds = findRemovedExistingIds(data)
@@ -225,10 +225,10 @@ export function RfqAttachmentsSheet({
}
/** 드롭존에서 파일 거부(에러) */
- function handleDropRejected(fileRejections: any[]) {
+ function handleDropRejected(fileRejections: FileRejection[]) {
// 편집 불가능한 상태에서는 무시
if (!isEditable) return;
-
+
fileRejections.forEach((rej) => {
toast({
variant: "destructive",
@@ -245,8 +245,8 @@ export function RfqAttachmentsSheet({
<SheetTitle className="flex items-center gap-2">
{isEditable ? "Manage Attachments" : "View Attachments"}
{rfq?.status && (
- <Badge
- variant={rfq.status === "DRAFT" ? "outline" : "secondary"}
+ <Badge
+ variant={rfq.status === "DRAFT" ? "outline" : "secondary"}
className="ml-1"
>
{rfq.status}
@@ -298,15 +298,14 @@ export function RfqAttachmentsSheet({
<div className="flex items-center gap-2">
{/* 1) Download button (if filePath) */}
{field.filePath && (
- <a
- href={`/api/rfq-download?path=${encodeURIComponent(field.filePath)}`}
- download={field.fileName}
- className="text-sm"
+ <Button
+ variant="ghost"
+ size="icon"
+ type="button"
+ onClick={() => quickDownload(field.filePath, field.fileName)}
>
- <Button variant="ghost" size="icon" type="button">
- <Download className="h-4 w-4" />
- </Button>
- </a>
+ <Download className="h-4 w-4" />
+ </Button>
)}
{/* 2) Remove button - 편집 가능할 때만 표시 */}
{isEditable && (
@@ -413,8 +412,8 @@ export function RfqAttachmentsSheet({
</Button>
</SheetClose>
{isEditable && (
- <Button
- type="submit"
+ <Button
+ type="submit"
disabled={isPending || (form.getValues().newUploads.length === 0 && defaultAttachments.length === form.getValues().existing.length)}
>
{isPending && <Loader className="mr-2 h-4 w-4 animate-spin" />}