fixes on the file uploader

This commit is contained in:
estifanos
2026-07-24 08:39:31 +00:00
parent 47566dfe16
commit 4ccf27c044
2 changed files with 15 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
// ponytail: in-memory mock array, resets on reload — swap for RTK Query endpoint when backend lands. // ponytail: in-memory mock array, resets on reload — swap for RTK Query endpoint when backend lands.
import type { UploadFileInfo } from '@ema-platform/api';
export interface Vessel { export interface Vessel {
id: string; id: string;
name: string; name: string;
@@ -44,7 +46,7 @@ export interface TransferRequest {
submitted: string; submitted: string;
approvedOn?: string; approvedOn?: string;
rejectionReason?: string; rejectionReason?: string;
documentFileInfo?: unknown; documentFileInfo?: UploadFileInfo;
} }
export const MOCK_REQUESTS: TransferRequest[] = [ export const MOCK_REQUESTS: TransferRequest[] = [

View File

@@ -2,9 +2,17 @@ import { useCallback, useState } from 'react';
import { baseApi } from '../base-api'; import { baseApi } from '../base-api';
import { resolveTokenFromStorage } from '../session'; import { resolveTokenFromStorage } from '../session';
export interface UploadKeyResponse<TFileInfo = unknown> { export interface UploadFileInfo {
bucket: string;
fileName: string;
contentType: string;
originalname: string;
size: number;
}
export interface UploadKeyResponse {
fileInfo: UploadFileInfo;
presigned: string; presigned: string;
fileInfo: TFileInfo;
} }
const fileUploadApi = baseApi.injectEndpoints({ const fileUploadApi = baseApi.injectEndpoints({
@@ -65,12 +73,12 @@ export function useDocumentUpload() {
const [isUploading, setIsUploading] = useState(false); const [isUploading, setIsUploading] = useState(false);
const upload = useCallback( const upload = useCallback(
async <TFileInfo = unknown>(file: File, endpoint: string): Promise<UploadKeyResponse<TFileInfo>> => { async (file: File, endpoint: string): Promise<UploadKeyResponse> => {
setIsUploading(true); setIsUploading(true);
try { try {
const { presigned, fileInfo } = await getFileUploadKey({ endpoint, file }).unwrap(); const { presigned, fileInfo } = await getFileUploadKey({ endpoint, file }).unwrap();
await uploadToPresigned(file, presigned); await uploadToPresigned(file, presigned);
return { presigned, fileInfo: fileInfo as TFileInfo }; return { presigned, fileInfo };
} finally { } finally {
setIsUploading(false); setIsUploading(false);
} }