Try fix
This commit is contained in:
parent
81f20afcb6
commit
4d929ddd96
1 changed files with 14 additions and 5 deletions
|
@ -8,6 +8,7 @@ import { useForm } from 'react-hook-form';
|
||||||
import Button from './Button';
|
import Button from './Button';
|
||||||
import Input from './Input';
|
import Input from './Input';
|
||||||
import ToHTML from './ToHTML';
|
import ToHTML from './ToHTML';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
type PuzzleData = {
|
type PuzzleData = {
|
||||||
answer: string;
|
answer: string;
|
||||||
|
@ -16,7 +17,8 @@ type PuzzleData = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type Granted = {
|
type Granted = {
|
||||||
[key: string]: number;
|
tries: number;
|
||||||
|
score?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
||||||
|
@ -24,6 +26,8 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [granted, setGranted] = useState<Granted | null>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
|
@ -57,8 +61,8 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok || res.status === 406) {
|
||||||
alert('Réponse correcte !');
|
setGranted(await res.json());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +80,7 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
encType="multipart/form-data"
|
encType="multipart/form-data"
|
||||||
>
|
>
|
||||||
<div className="flex flex-col space-x-0 sm:flex-row sm:space-x-6">
|
<div className="flex flex-col items-center justify-center space-x-0 sm:flex-row sm:space-x-6">
|
||||||
<Input
|
<Input
|
||||||
className="w-full"
|
className="w-full"
|
||||||
label="Réponse"
|
label="Réponse"
|
||||||
|
@ -85,7 +89,12 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
||||||
required
|
required
|
||||||
{...register('answer')}
|
{...register('answer')}
|
||||||
/>
|
/>
|
||||||
|
{granted && (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<p className="text-sm text-muted">Tentatives actuelles : {granted.tries}</p>
|
||||||
|
{granted.score && <p className="text-sm text-muted">Score : {granted.score}</p>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{/* <Input
|
{/* <Input
|
||||||
className="h-16 w-full sm:w-1/3"
|
className="h-16 w-full sm:w-1/3"
|
||||||
label="Code"
|
label="Code"
|
||||||
|
|
Loading…
Add table
Reference in a new issue