Skip to content

Commit

Permalink
Add Select component | logic to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
isaoud committed Oct 15, 2023
1 parent aeafecf commit 7240e2d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions front/src/views/atoms/forms/Select.atom.tsx
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;

0 comments on commit 7240e2d

Please sign in to comment.