refactor: enhance customer creation code

This commit is contained in:
Abdalhamid Alhamad
2025-01-13 16:42:27 +03:00
parent 221f3bae4f
commit 5aa3d3774d
6 changed files with 70 additions and 66 deletions

View File

@ -1,15 +1,10 @@
import React, { useState } from 'react';
import {
Box,
Button,
CircularProgress,
Alert
} from '@mui/material';
import { CloudUpload as CloudUploadIcon } from '@mui/icons-material';
import { documentApi } from '../../api/client';
import { DocumentType } from '../../types/document';
import { ApiError } from '../../types/api';
import { Alert, Box, Button, CircularProgress } from '@mui/material';
import { AxiosError } from 'axios';
import React, { useState } from 'react';
import { documentApi } from '../../api/client';
import { ApiError } from '../../types/api';
import { DocumentType } from '../../types/document';
interface DocumentUploadProps {
onUploadSuccess: (documentId: string) => void;
@ -41,7 +36,7 @@ export const DocumentUpload = ({ onUploadSuccess, documentType, label }: Documen
if (err instanceof AxiosError && err.response?.data) {
const apiError = err.response.data as ApiError;
const messages = Array.isArray(apiError.message)
? apiError.message.map(m => `${m.field}: ${m.message}`).join('\n')
? apiError.message.map((m) => `${m.field}: ${m.message}`).join('\n')
: apiError.message;
setError(messages);
} else {
@ -52,17 +47,18 @@ export const DocumentUpload = ({ onUploadSuccess, documentType, label }: Documen
}
};
const now = new Date();
return (
<Box>
<input
accept="image/*,.pdf"
style={{ display: 'none' }}
id={`upload-${documentType}`}
id={`upload-${documentType}-${now.getTime()}`}
type="file"
onChange={handleFileChange}
disabled={loading}
/>
<label htmlFor={`upload-${documentType}`}>
<label htmlFor={`upload-${documentType}-${now.getTime()}`}>
<Button
variant="outlined"
component="span"