diff --git a/src/frontend/src/components/GenerateBasemap.jsx b/src/frontend/src/components/GenerateBasemap.jsx index a576d331c7..d1091de09b 100644 --- a/src/frontend/src/components/GenerateBasemap.jsx +++ b/src/frontend/src/components/GenerateBasemap.jsx @@ -15,6 +15,7 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI const [selectedTileSource, setSelectedTileSource] = useState(null); const [selectedOutputFormat, setSelectedOutputFormat] = useState(null); const [tmsUrl, setTmsUrl] = useState(''); + const [error, setError] = useState([]); const modalStyle = (theme) => ({ width: '90vw', // Responsive modal width using vw @@ -51,6 +52,35 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI setTmsUrl(e.target.value); }; + const generateProjectTilesValidation = () => { + const currentError = []; + if (!selectedTileSource) { + currentError.push('selectedTileSource'); + } + if (!selectedOutputFormat) { + currentError.push('selectedOutputFormat'); + } + if (!tmsUrl && selectedTileSource === 'tms') { + currentError.push('tmsUrl'); + } + setError(currentError); + return currentError; + }; + + const generateProjectTiles = () => { + const currentErrors = generateProjectTilesValidation(); + if (currentErrors.length === 0) { + dispatch( + GenerateProjectTiles( + `${ + import.meta.env.VITE_API_URL + }/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`, + decodedId, + ), + ); + } + }; + return ( - {/* Output Format Dropdown */} - - - - Select Output Format - - { - setSelectedOutputFormat(e.target.value); - }} - > - {environment.tileOutputFormats?.map((form) => ( - - {form.label} - - ))} - - - + + {/* Output Format Dropdown */} + + + + Select Output Format + + { + setSelectedOutputFormat(e.target.value); + }} + > + {environment.tileOutputFormats?.map((form) => ( + + {form.label} + + ))} + + + {error.includes('selectedOutputFormat') && ( +

Output Format is Required.

+ )} +
- {/* Tile Source Dropdown or TMS URL Input */} - - - - Select Tile Source - - - {environment.baseMapProviders?.map((form) => ( - - {form.label} - - ))} - - {selectedTileSource === 'tms' && ( - + {/* Tile Source Dropdown or TMS URL Input */} + + + + Select Tile Source + + + {environment.baseMapProviders?.map((form) => ( + + {form.label} + + ))} + + + {error.includes('selectedTileSource') && ( +

Tile Source is Required.

+ )} +
+ {selectedTileSource === 'tms' && ( + + - )} -
-
- - {/* Generate Button */} - - { - // Check if 'tms' is selected and tmsUrl is not empty - if (selectedTileSource === 'tms' && !tmsUrl) { - // Handle error, TMS URL is required - console.log('TMS URL is required'); - return; - } + {error.includes('tmsUrl') &&

Tile Source is Required.

} +
+ )} + +
+ {/* Generate Button */} +
+ generateProjectTiles()} + > + Generate + +
- dispatch( - GenerateProjectTiles( - `${ - import.meta.env.VITE_API_URL - }/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`, - decodedId, - ), - ); - }} - > - Generate - - - - {/* Refresh Button */} - - { - getTilesList(); - }} - > - Refresh - + {/* Refresh Button */} +
+ { + getTilesList(); + }} + > + Refresh + +
+
+
{/* Table Content */}