@@ -2,7 +2,6 @@ import { HiOutlineTrash } from "react-icons/hi";
22import styled from "styled-components" ;
33import { useState , useEffect } from "react" ;
44import { getFieldTranslationByNames } from "../../../../services/Utility" ;
5- import DOMPurify from "dompurify" ;
65
76const Container = styled . div `
87 display: flex;
@@ -22,18 +21,6 @@ const NationCard = styled.div`
2221 }
2322` ;
2423
25- const BankCard = styled . div `
26- width: 240px;
27- @media (min-width: 1500px) {
28- width: 185px;
29- }
30- @media (min-width: 1920px) {
31- width: 240px;
32- }
33- input {
34- opacity: 0;
35- }
36- ` ;
3724
3825const Image = styled . div `
3926 position: relative;
@@ -107,7 +94,7 @@ const UploadCards = ({ setImageError, setNationImageURL }) => {
10794 const [ nationImage , setNationImage ] = useState ( null ) ;
10895 const [ imageError , setImageErrorState ] = useState ( false ) ; // State for image upload error
10996 const [ previewUrl , setPreviewUrl ] = useState ( null ) ;
110- useEffect ( ( ) => {
97+ useEffect ( ( ) => {
11198 if ( ! nationImage ) {
11299 setPreviewUrl ( null ) ;
113100 return ;
@@ -120,21 +107,23 @@ const UploadCards = ({ setImageError, setNationImageURL }) => {
120107 URL . revokeObjectURL ( url ) ;
121108 } ;
122109 } , [ nationImage ] ) ;
110+
123111 const handleNationImageChange = ( e ) => {
124112 const file = e . target . files && e . target . files [ 0 ] ;
125- if ( file ) {
113+
114+ if ( file && file . type . startsWith ( "image/" ) ) {
126115 setNationImage ( file ) ;
127116 setNationImageURL ( file ) ;
128- setImageErrorState ( false ) ; // Clear the error when a file is selected
117+ setImageErrorState ( false ) ;
129118 } else {
130- setImageErrorState ( true ) ; // Set the error if no file is selected
119+ setImageErrorState ( true ) ;
120+ if ( file ) alert ( "Please upload a valid image file." ) ;
131121 }
132122 } ;
133-
134123 const handleDeleteClick = ( ) => {
135124 setNationImage ( null ) ;
136125 setNationImageURL ( null ) ;
137- setImageErrorState ( true ) ; // Set the error when the image is deleted
126+ setImageErrorState ( true ) ;
138127 } ;
139128
140129 return (
@@ -161,7 +150,7 @@ const UploadCards = ({ setImageError, setNationImageURL }) => {
161150 // codeql[js/xss-through-dom]: previewUrl is safe (from File API / trusted source)
162151 }
163152
164- < img src = { previewUrl } alt = "nation card" />
153+ < img src = { previewUrl || "" } alt = "nation card" />
165154 </ Image >
166155 ) }
167156 </ UploadWrapper >
0 commit comments