-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
isaoud
committed
Oct 15, 2023
1 parent
aeafecf
commit 7240e2d
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { InputProps } from '../../../interfaces/Forms/Input.interface'; | ||
|
||
const Select = ({ label, name, value, onChange, className = '', required = false, disabled }: InputProps):JSX.Element => { | ||
const [images, setImages] = useState([]); | ||
|
||
useEffect(() => { | ||
|
||
fetch('/http://localhost:3000/dockerhub/tags?image=node') | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
if (data && data.images) { | ||
setImages(data.images); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('Erreur lors de la récupération des images :', error); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{label && <label className="font-semibold text-sm text-gray-600 pb-1 block">{label}</label>} | ||
<select | ||
name={name} | ||
value={value} | ||
onChange={onChange} | ||
className={`input input-bordered w-full max-w-xs mt-1 ${className}`} | ||
required={required} | ||
disabled={disabled} | ||
> | ||
<option value="">Sélectionnez une image</option> | ||
{images.map((image) => ( | ||
<option key={image} value={image}> | ||
{image} | ||
</option> | ||
))} | ||
</select> | ||
</> | ||
); | ||
}; | ||
|
||
export default Select; |