1+ import React , { useState } from 'react' ;
2+ import { Box , Card , CardContent , CardHeader , Typography , Divider , Link , Grid , Paper } from '@mui/material' ;
3+ import FileUpload from './FileUpload' ;
4+
5+ const DocumentUpload = ( ) => {
6+ const [ uploadedDocument , setUploadedDocument ] = useState ( null ) ;
7+ const [ uploadedTemplate , setUploadedTemplate ] = useState ( null ) ;
8+ const [ uploadedUserFile , setUploadedUserFile ] = useState ( null ) ;
9+
10+ const handleDocumentUpload = ( fileData ) => {
11+ console . log ( 'Document uploaded:' , fileData ) ;
12+ setUploadedDocument ( fileData ) ;
13+ } ;
14+
15+ const handleTemplateUpload = ( fileData ) => {
16+ console . log ( 'Template uploaded:' , fileData ) ;
17+ setUploadedTemplate ( fileData ) ;
18+ } ;
19+
20+ const handleUserFileUpload = ( fileData ) => {
21+ console . log ( 'User file uploaded:' , fileData ) ;
22+ setUploadedUserFile ( fileData ) ;
23+ } ;
24+
25+ const renderUploadedFile = ( fileData , title ) => {
26+ if ( ! fileData ) return null ;
27+
28+ return (
29+ < Paper elevation = { 2 } sx = { { p : 2 , mb : 2 , bgcolor : 'background.paper' } } >
30+ < Typography variant = "subtitle1" fontWeight = "bold" > { title } </ Typography >
31+ < Typography variant = "body2" > File name: { fileData . original_filename } </ Typography >
32+ < Typography variant = "body2" > Size: { Math . round ( fileData . bytes / 1024 ) } KB</ Typography >
33+ < Typography variant = "body2" > Type: { fileData . format || 'Document' } </ Typography >
34+ < Typography variant = "body2" >
35+ URL: < Link href = { fileData . secure_url } target = "_blank" rel = "noopener" > { fileData . secure_url } </ Link >
36+ </ Typography >
37+
38+ { fileData . resource_type === 'image' && (
39+ < Box sx = { { mt : 2 , textAlign : 'center' } } >
40+ < img
41+ src = { fileData . secure_url }
42+ alt = { fileData . original_filename }
43+ style = { { maxWidth : '100%' , maxHeight : '200px' } }
44+ />
45+ </ Box >
46+ ) }
47+ </ Paper >
48+ ) ;
49+ } ;
50+
51+ return (
52+ < Card >
53+ < CardHeader title = "Document Upload" />
54+ < Divider />
55+ < CardContent >
56+ < Grid container spacing = { 3 } >
57+ < Grid item xs = { 12 } md = { 4 } >
58+ < Box >
59+ < Typography variant = "h6" > Case Documents</ Typography >
60+ < Typography variant = "body2" color = "text.secondary" paragraph >
61+ Upload documents related to legal cases.
62+ Supported formats: PDF, DOC, DOCX
63+ </ Typography >
64+ < FileUpload
65+ onUploadComplete = { handleDocumentUpload }
66+ uploadType = "document"
67+ buttonText = "Select Case Document"
68+ allowedFormats = { [ 'pdf' , 'doc' , 'docx' ] }
69+ />
70+ { renderUploadedFile ( uploadedDocument , 'Uploaded Case Document' ) }
71+ </ Box >
72+ </ Grid >
73+
74+ < Grid item xs = { 12 } md = { 4 } >
75+ < Box >
76+ < Typography variant = "h6" > Document Templates</ Typography >
77+ < Typography variant = "body2" color = "text.secondary" paragraph >
78+ Upload document templates for generating legal documents.
79+ Supported formats: DOC, DOCX, TXT, HTML
80+ </ Typography >
81+ < FileUpload
82+ onUploadComplete = { handleTemplateUpload }
83+ uploadType = "template"
84+ buttonText = "Select Template"
85+ allowedFormats = { [ 'doc' , 'docx' , 'txt' , 'html' ] }
86+ />
87+ { renderUploadedFile ( uploadedTemplate , 'Uploaded Template' ) }
88+ </ Box >
89+ </ Grid >
90+
91+ < Grid item xs = { 12 } md = { 4 } >
92+ < Box >
93+ < Typography variant = "h6" > User Files</ Typography >
94+ < Typography variant = "body2" color = "text.secondary" paragraph >
95+ Upload general files and images.
96+ Supported formats: PDF, DOC, DOCX, JPG, JPEG, PNG
97+ </ Typography >
98+ < FileUpload
99+ onUploadComplete = { handleUserFileUpload }
100+ uploadType = "user"
101+ buttonText = "Select File"
102+ allowedFormats = { [ 'pdf' , 'doc' , 'docx' , 'jpg' , 'jpeg' , 'png' ] }
103+ />
104+ { renderUploadedFile ( uploadedUserFile , 'Uploaded User File' ) }
105+ </ Box >
106+ </ Grid >
107+ </ Grid >
108+ </ CardContent >
109+ </ Card >
110+ ) ;
111+ } ;
112+
113+ export default DocumentUpload ;
0 commit comments