mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
fixes on the file uploader
This commit is contained in:
@@ -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[] = [
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user