Generateurv2/frontend/components/exos/ExoPrinterForm.jsx

103 lines
2.8 KiB
React
Raw Normal View History

2022-05-18 10:15:54 +02:00
import { useEffect, useRef, useState } from "react";
import useFocus from "../../hooks/useFocus.hook.jsx";
import { csvGen } from "../../requests/requests.exos.js";
import styles from "../../styles/exos/ExoPrinterForm.module.scss";
import { parseClassName } from "../../utils/utils.js";
import StepExemple from "./StepExemple.jsx";
import StepOptions from "./StepOptions.jsx";
export default function ExoPrinterForm({ step }) {
const [options, setOptions] = useState({
pages: 5,
serie: 10,
name: "",
});
const pageChange = (num) => {
setOptions({
...options,
pages: num,
});
};
const serieChange = (num) => {
setOptions({
...options,
serie: num,
});
};
const ref = useRef();
useEffect(() => {
if (ref.current != null) ref.current.focus();
}, []);
return (
<>
<div className={styles["exo-input-container"]}>
{" "}
<input
type="text"
name="fich_name"
className={"exo-input " /* (error.error == true && " input-error") */}
placeholder="Nom du fichier..."
value={options.name}
onChange={(e) => {
setOptions({ ...options, name: e.target.value });
}}
tabIndex="-1"
ref={ref}
onKeyUp={(e) => {
if (e.code == "Enter") {
csvGen(
step.id_code,
options.name !== "" ? options.name : "untitled"
);
}
}}
2022-06-11 23:39:03 +02:00
disabled= {!step.isCsv}
2022-05-18 10:15:54 +02:00
/>
</div>
<div className={styles["option--ex"]}>
2022-06-11 23:39:03 +02:00
<div>
{step.exemple.data && (
<p className="margint-p0 fontw-800">
Exemples ({step.exemple.type && step.exemple.type})
</p>
)}
{step.exemple.data &&
step.exemple.data.slice(0, 3).map((ex, i) => {
return (
<p
key={i}
className={"marginl-p5" + " small-text " + styles.exemple}
title={ex.calcul}
>
{ex.calcul}
</p>
);
})}
{step.exemple.data && <p className="marginl-p5 margint-p2">...</p>}
{!step.exemple.data && <p>Exemples indisponibles</p>}
</div>
2022-05-18 10:15:54 +02:00
</div>
<div className={styles["btn-container"]}>
<button
2022-06-11 23:39:03 +02:00
className={parseClassName([
"exo-btn",
!step.isCsv ? styles["btn-disabled"] : undefined,
])}
2022-05-18 10:15:54 +02:00
onClick={(e) => {
e.preventDefault;
csvGen(
step.id_code,
options.name !== "" ? options.name : "untitled"
);
}}
2022-06-11 23:39:03 +02:00
disabled={!step.isCsv}
2022-05-18 10:15:54 +02:00
>
2022-06-11 23:39:03 +02:00
{step.isCsv ? "Télécharger" : "Téléchargement indisponible"}
2022-05-18 10:15:54 +02:00
</button>
</div>
</>
);
}