import { Fragment, useState, useEffect } from 'react'; import Loader from '../Loader'; import htmlParser from 'html-react-parser'; import dynamic from 'next/dynamic'; import api from '../../utils/api'; import fr from 'date-fns/locale/fr'; import { registerLocale } from "react-datepicker"; import date from 'date-and-time'; import "react-datepicker/dist/react-datepicker.css"; registerLocale('fr', fr); const FunctionForm = (props) => { const [inputState, setInputState] = useState({}); const [message, setMessage] = useState(""); const [isLoading, setIsLoading] = useState(false); // inputState par défaut useEffect(() => { const inputStateNew = { ...inputState }; props.inputsArray.forEach((input) => { if (input.type === "select" && input.options.length > 0) { inputStateNew[input.name] = input.options[0].value; } }); setInputState(inputStateNew); }, []); const handleSubmit = (event) => { setIsLoading(true); event.preventDefault(); api.post(`/functions/${props.slug}`, inputState) .then((response) => { setMessage(response.data.resultHTML); setIsLoading(false); }) .catch((error) => { setMessage(error.response.data.message); setIsLoading(false); }); } const handleChange = (event) => { const inputStateNew = { ...inputState }; inputStateNew[event.target.name] = event.target.value; setInputState(inputStateNew); } if (props.inputsArray.length <= 0) { return (
La fonction n'est pas encore disponible.