mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 21:59:40 +00:00
refactor: enhance customer creation code
This commit is contained in:
@ -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"
|
||||
|
Reference in New Issue
Block a user