Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x | // src/services/uploadsApi.ts
import {api} from './api';
// ============================================================================
// Types
// ============================================================================
/** Workflow state for an investor-submitted document. */
export type UploadStatus = 'pending_review' | 'accepted' | 'rejected' | 'discarded';
/** A row from the document_types catalog. */
export interface DocumentType {
documentTypeId: number;
code: string;
label: string;
description: string | null;
allowedMimeTypes: string[];
maxSizeBytes: number;
requiresReview: boolean;
isActive: boolean;
sortOrder: number;
}
/**
* One investor-submitted document. The current* fields are denormalised
* from the latest 'uploaded' event for fast list rendering.
*/
export interface InvestorUpload {
documentId: number;
investorId: number;
documentTypeId: number;
documentTypeCode: string;
documentTypeLabel: string;
status: UploadStatus;
createdAt: string;
updatedAt: string;
currentFilename: string | null;
currentMimeType: string | null;
currentSizeBytes: number | null;
currentUploadedAt: string | null;
/** Latest admin reason on rejection — empty otherwise. */
latestNote: string | null;
}
export interface DocumentTypesResponse {
types: DocumentType[];
}
export interface UploadsResponse {
documents: InvestorUpload[];
}
export interface UploadResponse {
document: InvestorUpload;
}
export interface UploadDocumentArgs {
documentTypeId: number;
file: File;
}
// ============================================================================
// API Endpoints
// ============================================================================
export const uploadsApi = api.injectEndpoints({
endpoints: (builder) => ({
/** Active document types for the upload-form dropdown. */
listDocumentTypes: builder.query<DocumentTypesResponse, void>({
query: () => '/document-types',
transformResponse: (response: {data: DocumentTypesResponse}) => response.data,
providesTags: ['DocumentType']
}),
/** All uploads for the authenticated investor. */
listMyUploads: builder.query<UploadsResponse, void>({
query: () => '/investor/uploads',
transformResponse: (response: {data: UploadsResponse}) => response.data,
providesTags: ['InvestorUpload']
}),
/** Upload a new (or replacement-after-rejection) document. */
uploadDocument: builder.mutation<UploadResponse, UploadDocumentArgs>({
query: ({documentTypeId, file}) => {
const form = new FormData();
form.append('documentTypeId', String(documentTypeId));
form.append('file', file, file.name);
return {
url: '/investor/uploads',
method: 'POST',
body: form
};
},
transformResponse: (response: {data: UploadResponse}) => response.data,
invalidatesTags: ['InvestorUpload']
}),
/** Discard a pending or rejected document. */
discardUpload: builder.mutation<void, number>({
query: (documentId) => ({
url: `/investor/uploads/${String(documentId)}`,
method: 'DELETE'
}),
invalidatesTags: ['InvestorUpload']
}),
/** Download the current file for an upload as a blob. */
downloadUpload: builder.mutation<Blob, number>({
query: (documentId) => ({
url: `/investor/uploads/${String(documentId)}/file`,
method: 'GET',
responseHandler: (response) => response.blob(),
cache: 'no-store'
})
})
})
});
export const {
useListDocumentTypesQuery,
useListMyUploadsQuery,
useUploadDocumentMutation,
useDiscardUploadMutation,
useDownloadUploadMutation
} = uploadsApi;
// ============================================================================
// Helpers
// ============================================================================
export const UPLOAD_STATUS_LABELS: Record<UploadStatus, string> = {
pending_review: 'Pending Review',
accepted: 'Accepted',
rejected: 'Action Required',
discarded: 'Discarded'
};
/**
* Format a byte count as a short human-readable string. Used for the
* upload list row's size column.
*/
export function formatBytes(bytes: number | null): string {
Iif (bytes === null || bytes <= 0) return '—';
const units = ['B', 'KB', 'MB', 'GB'];
let value = bytes;
let unitIndex = 0;
while (value >= 1024 && unitIndex < units.length - 1) {
value /= 1024;
unitIndex += 1;
}
const decimals = unitIndex === 0 ? 0 : 1;
return `${value.toFixed(decimals)} ${units[unitIndex]}`;
}
|