mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
feat(vessel-transfer): add document upload functionality to transfer requests
This commit is contained in:
@@ -44,6 +44,7 @@ export interface TransferRequest {
|
||||
submitted: string;
|
||||
approvedOn?: string;
|
||||
rejectionReason?: string;
|
||||
documentFileInfo?: unknown;
|
||||
}
|
||||
|
||||
export const MOCK_REQUESTS: TransferRequest[] = [
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from '@mantine/core';
|
||||
import { IconArrowLeft, IconArrowRight, IconCheck, IconInfoCircle, IconUpload } from '@tabler/icons-react';
|
||||
import { notify } from '@ema-platform/ui';
|
||||
import { isStorageUploadError, useDocumentUpload } from '@ema-platform/api';
|
||||
import { addTransferRequest, MOCK_VESSELS, TRANSFER_REASONS } from '../mock';
|
||||
import { useAppSelector } from '../../../store/hooks';
|
||||
|
||||
@@ -45,22 +46,31 @@ export function VesselTransferApplicationPage() {
|
||||
const [reason, setReason] = useState<string | null>(null);
|
||||
const [document, setDocument] = useState<File | null>(null);
|
||||
|
||||
const { upload, isUploading } = useDocumentUpload();
|
||||
|
||||
const step0Ok = !!vessel;
|
||||
const step1Ok = !!newOwnerName && !!newOwnerIdOrTin && !!newOwnerPhone
|
||||
&& EMAIL_RE.test(newOwnerEmail) && !!newOwnerAddress;
|
||||
const step2Ok = !!reason && !!document;
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!vessel || !reason) return;
|
||||
addTransferRequest({
|
||||
vesselName: vessel.name,
|
||||
vesselRegNo: vessel.regNo,
|
||||
currentOwner,
|
||||
newOwnerName,
|
||||
reason: reason as (typeof TRANSFER_REASONS)[number],
|
||||
});
|
||||
notify.success('Transfer request submitted. SMS and email confirmation sent.');
|
||||
navigate('/vessel-transfers');
|
||||
const handleSubmit = async () => {
|
||||
if (!vessel || !reason || !document) return;
|
||||
try {
|
||||
const { fileInfo } = await upload(document, '/documents/get-file-upload-key');
|
||||
addTransferRequest({
|
||||
vesselName: vessel.name,
|
||||
vesselRegNo: vessel.regNo,
|
||||
currentOwner,
|
||||
newOwnerName,
|
||||
reason: reason as (typeof TRANSFER_REASONS)[number],
|
||||
documentFileInfo: fileInfo,
|
||||
});
|
||||
notify.success('Transfer request submitted. SMS and email confirmation sent.');
|
||||
navigate('/vessel-transfers');
|
||||
} catch (error) {
|
||||
const tooLarge = isStorageUploadError(error) && error.message === 'STORAGE_UPLOAD_TOO_LARGE';
|
||||
notify.error(tooLarge ? 'File is too large to upload.' : 'Failed to upload document. Please try again.');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -189,7 +199,7 @@ export function VesselTransferApplicationPage() {
|
||||
Next
|
||||
</Button>
|
||||
) : (
|
||||
<Button color="teal" leftSection={<IconCheck size={14} />} onClick={handleSubmit}>
|
||||
<Button color="teal" leftSection={<IconCheck size={14} />} onClick={handleSubmit} loading={isUploading}>
|
||||
Submit Request
|
||||
</Button>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user