diff --git a/api/assets/functions/main/convertDistance.js b/api/assets/functions/main/convertDistance.js index 1eccbf1..9c5acbe 100644 --- a/api/assets/functions/main/convertDistance.js +++ b/api/assets/functions/main/convertDistance.js @@ -21,7 +21,7 @@ function convertDistance(firstValue, unitFirstValue, unitFinalValue) { const result = firstValue * Math.pow(10, difference); return { result, - resultHTML: `
Conversion de longueur : ${formatNumberResult(firstValue)} ${unitFirstValue} = ${formatNumberResult(result)} ${unitFinalValue}
` + resultHTML: `${formatNumberResult(firstValue)} ${unitFirstValue} = ${formatNumberResult(result)} ${unitFinalValue}
` }; } return false; @@ -37,7 +37,7 @@ module.exports = convertDistanceOutput = ({ res, next }, argsObject) => { } // Si ce n'est pas un nombre - number = parseInt(number); + number = parseFloat(number); if (isNaN(number)) { return errorHandling(next, { message: "Veuillez rentré un nombre valide.", statusCode: 400 }); } diff --git a/api/assets/functions/main/convertTemperature.js b/api/assets/functions/main/convertTemperature.js index 9feb0bd..bb4b59e 100644 --- a/api/assets/functions/main/convertTemperature.js +++ b/api/assets/functions/main/convertTemperature.js @@ -22,7 +22,7 @@ function convertTemperature(degree, unit) { } return { result: temperatureValue, - resultHTML: `${formatNumberResult(temperatureValue)} ${unit}
` + resultHTML: `${formatNumberResult(degree)} ${(unit === '°C') ? "°F" : "°C"} = ${formatNumberResult(temperatureValue)} ${unit}
` }; } @@ -31,12 +31,12 @@ module.exports = convertTemperatureOutput = ({ res, next }, argsObject) => { let { degree, unitToConvert } = argsObject; // S'il n'y a pas les champs obligatoire - if (!(degree && unit)) { + if (!(degree && unitToConvert)) { return errorHandling(next, requiredFields); } // Si ce n'est pas un nombre - degree = parseInt(degree); + degree = parseFloat(degree); if (isNaN(degree)) { return errorHandling(next, { message: "Veuillez rentré un nombre valide.", statusCode: 400 }); } diff --git a/website/components/EditFormFunction.js b/website/components/EditFormFunction.js index 875fb01..913d7c1 100644 --- a/website/components/EditFormFunction.js +++ b/website/components/EditFormFunction.js @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, Fragment } from 'react'; import api from '../utils/api'; import 'notyf/notyf.min.css'; @@ -12,11 +12,30 @@ const EditFormFunction = (props) => { setInputsArray(newInputsArray); } - const handleChangeInput = (event) => { + const addOption = (event) => { const newInputsArray = [...inputsArray]; - const index = event.target.id.split('-')[1]; - const inputObject = newInputsArray[index]; + const index = event.target.id.split('-')[1]; + const inputObject = newInputsArray[index]; + inputObject.options.push({ name: "", value: "" }); + setInputsArray(newInputsArray); + } + + const handleChangeOption = (inputIndex, optionIndex, event) => { + const newInputsArray = [...inputsArray]; + const inputObject = newInputsArray[inputIndex]; + const optionObject = inputObject.options[optionIndex]; + optionObject[event.target.name] = event.target.value; + setInputsArray(newInputsArray); + } + + const handleChangeInput = (event) => { + const newInputsArray = [...inputsArray]; + const index = event.target.id.split('-')[1]; + const inputObject = newInputsArray[index]; inputObject[event.target.name] = event.target.value; + if (event.target.value === "select") { + inputObject.options = []; + } setInputsArray(newInputsArray); } @@ -39,11 +58,19 @@ const EditFormFunction = (props) => { const handleRemoveInput = (event) => { const newInputsArray = [...inputsArray]; - const index = event.target.id.split('-')[1]; + const index = event.target.id.split('-')[1]; newInputsArray.splice(index, 1); setInputsArray(newInputsArray); } + const handleRemoveOption = (inputIndex, optionIndex) => { + const newInputsArray = [...inputsArray]; + const inputObject = newInputsArray[inputIndex]; + const optionsArray = inputObject.options; + optionsArray.splice(optionIndex, 1); + setInputsArray(newInputsArray); + } + return (Erreur, l'input n'est pas valide...