Skip to content

Commit d2789d9

Browse files
committed
Fix
1 parent 0449677 commit d2789d9

File tree

3 files changed

+26
-221
lines changed

3 files changed

+26
-221
lines changed

src/ui/pages/roomRequest/ViewRoomRequest.page.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export const ViewRoomRequest: React.FC = () => {
5555
const [data, setData] = useState<RoomRequestGetResponse | null>(null);
5656
const [isSubmitting, setIsSubmitting] = useState(false);
5757
const [uploadedFile, setUploadedFile] = useState<FileWithPath | null>(null);
58+
const [downloadingAttachment, setDownloadingAttachment] = useState<
59+
string | null
60+
>(null);
5861

5962
const newStatusForm = useForm<{
6063
status: RoomRequestStatus | null;
@@ -103,6 +106,8 @@ export const ViewRoomRequest: React.FC = () => {
103106
if (!filename) {
104107
return;
105108
}
109+
const attachmentKey = `${createdAt}#${status}`;
110+
setDownloadingAttachment(attachmentKey);
106111
try {
107112
const response = await api.get<{ downloadUrl: string }>(
108113
`/api/v1/roomRequests/${semesterId}/${requestId}/attachmentDownloadUrl/${createdAt}/${status}`,
@@ -115,6 +120,8 @@ export const ViewRoomRequest: React.FC = () => {
115120
color: "red",
116121
icon: <IconAlertCircle size={16} />,
117122
});
123+
} finally {
124+
setDownloadingAttachment(null);
118125
}
119126
};
120127

@@ -457,16 +464,28 @@ export const ViewRoomRequest: React.FC = () => {
457464
<Button
458465
size="xs"
459466
variant="light"
460-
leftSection={<IconDownload size={14} />}
467+
leftSection={
468+
downloadingAttachment ===
469+
`${x.createdAt}#${x.status}` ? (
470+
<Loader size={14} />
471+
) : (
472+
<IconDownload size={14} />
473+
)
474+
}
461475
onClick={() =>
462476
handleDownloadAttachment(
463477
x.createdAt,
464478
x.status,
465479
x.attachmentFilename,
466480
)
467481
}
482+
disabled={
483+
downloadingAttachment === `${x.createdAt}#${x.status}`
484+
}
468485
>
469-
{x.attachmentFilename}
486+
{downloadingAttachment === `${x.createdAt}#${x.status}`
487+
? "Downloading..."
488+
: x.attachmentFilename}
470489
</Button>
471490
)}
472491
{x.createdAt && (

src/ui/util/s3.test.ts

Lines changed: 0 additions & 212 deletions
This file was deleted.

tests/unit/s3.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import { InternalServerError } from "../../src/common/errors/index.js";
1515
// Note: We use vi.mock here instead of aws-sdk-client-mock because
1616
// getSignedUrl is a standalone function, not an S3Client command
1717
vi.mock("@aws-sdk/s3-request-presigner", () => ({
18-
getSignedUrl: vi.fn(),
18+
getSignedUrl: vi
19+
.fn()
20+
.mockResolvedValue("https://s3.amazonaws.com/bucket/key?signature=xyz"),
1921
}));
2022

2123
describe("S3 Presigned URL Functions", () => {
@@ -28,7 +30,7 @@ describe("S3 Presigned URL Functions", () => {
2830
const mockUrl = "https://s3.amazonaws.com/bucket/key?signature=xyz";
2931
const mockS3Client = new S3Client({ region: "us-east-1" });
3032

31-
vi.mocked(getSignedUrl).mockResolvedValueOnce(mockUrl);
33+
vi.mocked(getSignedUrl);
3234

3335
const result = await createPresignedPut({
3436
s3client: mockS3Client,
@@ -51,8 +53,6 @@ describe("S3 Presigned URL Functions", () => {
5153
const mockUrl = "https://s3.amazonaws.com/bucket/key?signature=abc";
5254
const mockS3Client = new S3Client({ region: "us-east-1" });
5355

54-
vi.mocked(getSignedUrl).mockResolvedValueOnce(mockUrl);
55-
5656
const result = await createPresignedPut({
5757
s3client: mockS3Client,
5858
bucketName: "test-bucket",
@@ -71,11 +71,9 @@ describe("S3 Presigned URL Functions", () => {
7171
});
7272

7373
test("creates a presigned PUT URL with MD5 hash", async () => {
74-
const mockUrl = "https://s3.amazonaws.com/bucket/key?signature=def";
74+
const mockUrl = "https://s3.amazonaws.com/bucket/key?signature=xyz";
7575
const mockS3Client = new S3Client({ region: "us-east-1" });
7676

77-
vi.mocked(getSignedUrl).mockResolvedValueOnce(mockUrl);
78-
7977
const result = await createPresignedPut({
8078
s3client: mockS3Client,
8179
bucketName: "test-bucket",

0 commit comments

Comments
 (0)