@@ -24,12 +24,17 @@ import {
2424 DialogTitle ,
2525 DialogContent ,
2626 DialogActions ,
27+ Stack ,
28+ TextField ,
2729 Typography ,
2830 useTheme ,
2931} from "@wso2/oxygen-ui" ;
32+ import { alpha } from "@mui/material/styles" ;
3033import { FileText , Upload } from "@wso2/oxygen-ui-icons-react" ;
3134import { parseEnvContent , EnvVariable } from "../utils" ;
3235
36+ const MAX_FILE_SIZE = 1024 * 1024 ; // 1MB
37+
3338interface EnvBulkImportModalProps {
3439 open : boolean ;
3540 onClose : ( ) => void ;
@@ -43,6 +48,7 @@ export function EnvBulkImportModal({
4348} : EnvBulkImportModalProps ) {
4449 const theme = useTheme ( ) ;
4550 const [ content , setContent ] = useState ( "" ) ;
51+ const [ fileError , setFileError ] = useState < string | null > ( null ) ;
4652 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
4753
4854 // Parse content and get variables count
@@ -52,7 +58,7 @@ export function EnvBulkImportModal({
5258
5359 // Handle textarea change
5460 const handleContentChange = useCallback (
55- ( e : ChangeEvent < HTMLTextAreaElement > ) => {
61+ ( e : ChangeEvent < HTMLInputElement | HTMLTextAreaElement > ) => {
5662 setContent ( e . target . value ) ;
5763 } ,
5864 [ ]
@@ -64,7 +70,19 @@ export function EnvBulkImportModal({
6470 const file = e . target . files ?. [ 0 ] ;
6571 if ( ! file ) return ;
6672
73+ setFileError ( null ) ;
74+
75+ if ( file . size > MAX_FILE_SIZE ) {
76+ setFileError ( `File is too large. Maximum size is ${ MAX_FILE_SIZE / 1024 } KB.` ) ;
77+ e . target . value = "" ;
78+ return ;
79+ }
80+
6781 const reader = new FileReader ( ) ;
82+ reader . onerror = ( ) => {
83+ setFileError ( "Failed to read file. Please try again." ) ;
84+ e . target . value = "" ;
85+ } ;
6886 reader . onload = ( event ) => {
6987 const text = event . target ?. result ;
7088 if ( typeof text === "string" ) {
@@ -89,13 +107,15 @@ export function EnvBulkImportModal({
89107 if ( validCount > 0 ) {
90108 onImport ( parseResult . valid ) ;
91109 setContent ( "" ) ;
110+ setFileError ( null ) ;
92111 onClose ( ) ;
93112 }
94113 } , [ validCount , parseResult . valid , onImport , onClose ] ) ;
95114
96115 // Handle cancel/close
97116 const handleClose = useCallback ( ( ) => {
98117 setContent ( "" ) ;
118+ setFileError ( null ) ;
99119 onClose ( ) ;
100120 } , [ onClose ] ) ;
101121
@@ -116,32 +136,22 @@ export function EnvBulkImportModal({
116136 </ DialogTitle >
117137
118138 < DialogContent >
119- < Box display = "flex" flexDirection = "column" gap = { 2 } >
139+ < Stack spacing = { 2 } sx = { { pt : 1 } } >
120140 < Typography variant = "body2" color = "text.secondary" >
121141 Paste your .env content below or upload a file.
122142 </ Typography >
123143
124144 { /* Textarea for pasting .env content */ }
125- < Box
126- component = "textarea"
145+ < TextField
146+ multiline
147+ minRows = { 7 }
148+ fullWidth
127149 value = { content }
128150 onChange = { handleContentChange }
129151 placeholder = { `# Example format:\nAPI_KEY=your_api_key\nDATABASE_URL=postgres://...\nDEBUG="true"` }
130- sx = { {
131- width : "100%" ,
132- minHeight : 200 ,
133- padding : 1.5 ,
134- fontFamily : "monospace" ,
135- fontSize : 13 ,
136- border : `1px solid ${ theme . palette . divider } ` ,
137- borderRadius : 1 ,
138- resize : "vertical" ,
139- backgroundColor : theme . palette . background . paper ,
140- color : theme . palette . text . primary ,
141- "&:focus" : {
142- outline : "none" ,
143- borderColor : theme . palette . primary . main ,
144- } ,
152+ inputProps = { {
153+ "aria-label" : "Environment variables content" ,
154+ style : { fontFamily : "monospace" , fontSize : 13 } ,
145155 } }
146156 />
147157
@@ -150,8 +160,10 @@ export function EnvBulkImportModal({
150160 < input
151161 ref = { fileInputRef }
152162 type = "file"
163+ accept = ".env,text/plain"
153164 onChange = { handleFileUpload }
154165 style = { { display : "none" } }
166+ aria-label = "Upload environment variables file"
155167 />
156168 < Button
157169 variant = "outlined"
@@ -161,6 +173,11 @@ export function EnvBulkImportModal({
161173 >
162174 Upload .env File
163175 </ Button >
176+ { fileError && (
177+ < Typography variant = "caption" color = "error" sx = { { display : "block" , mt : 0.5 } } >
178+ { fileError }
179+ </ Typography >
180+ ) }
164181 </ Box >
165182
166183 { /* Variables count indicator */ }
@@ -178,7 +195,7 @@ export function EnvBulkImportModal({
178195 < Box
179196 sx = { {
180197 padding : 1.5 ,
181- backgroundColor : theme . palette . error . light + '20' ,
198+ backgroundColor : alpha ( theme . palette . error . light , 0.12 ) ,
182199 borderRadius : 1 ,
183200 border : `1px solid ${ theme . palette . error . light } ` ,
184201 } }
@@ -194,7 +211,7 @@ export function EnvBulkImportModal({
194211 </ Typography >
195212 </ Box >
196213 ) }
197- </ Box >
214+ </ Stack >
198215 </ DialogContent >
199216
200217 < DialogActions >
0 commit comments