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.
import type { UploadFileInfo } from '@ema-platform/api';
export interface Vessel {
id: string;
name: string;
@@ -44,7 +46,7 @@ export interface TransferRequest {
submitted: string;
approvedOn?: string;
rejectionReason?: string;
documentFileInfo?: unknown;
documentFileInfo?: UploadFileInfo;
}
export const MOCK_REQUESTS: TransferRequest[] = [

View File

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