frontend: Hotfix loading

This commit is contained in:
Divlo 2020-03-25 18:46:23 +01:00
parent 7d49422108
commit 96af78f967
2 changed files with 6 additions and 6 deletions

View File

@ -11,25 +11,22 @@ const FunctionForm = (props) => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const handleSubmit = (event) => { const handleSubmit = (event) => {
setIsLoading(true);
event.preventDefault(); event.preventDefault();
api.post(`/functions/${props.slug}`, inputState) api.post(`/functions/${props.slug}`, inputState)
.then((response) => { .then((response) => {
setMessage(response.data.resultHTML); setMessage(response.data.resultHTML);
setIsLoading(false);
}) })
.catch((error) => { .catch((error) => {
setMessage(error.response.data.message); setMessage(error.response.data.message);
setIsLoading(false);
}); });
setIsLoading(false);
} }
const handleChange = (event) => { const handleChange = (event) => {
const inputStateNew = { ...inputState }; const inputStateNew = { ...inputState };
inputStateNew[event.target.name] = event.target.value; inputStateNew[event.target.name] = event.target.value;
if (event.target.value !== "") {
setIsLoading(true);
} else {
setIsLoading(false);
}
setInputState(inputStateNew); setInputState(inputStateNew);
} }

View File

@ -18,13 +18,16 @@ const Register = () => {
} }
const handleSubmit = (event) => { const handleSubmit = (event) => {
setIsLoading(true);
event.preventDefault(); event.preventDefault();
api.post('/users/register', inputState) api.post('/users/register', inputState)
.then(({ data }) => { .then(({ data }) => {
setMessage(`<p class="form-success"><b>Succès:</b> ${data.result}</p>`); setMessage(`<p class="form-success"><b>Succès:</b> ${data.result}</p>`);
setIsLoading(false);
}) })
.catch((error) => { .catch((error) => {
setMessage(`<p class="form-error"><b>Erreur:</b> ${error.response.data.message}</p>`); setMessage(`<p class="form-error"><b>Erreur:</b> ${error.response.data.message}</p>`);
setIsLoading(false);
}); });
} }