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 Input from './Input';
|
||||
import ToHTML from './ToHTML';
|
||||
import { useState } from 'react';
|
||||
|
||||
type PuzzleData = {
|
||||
answer: string;
|
||||
|
@ -16,7 +17,8 @@ type PuzzleData = {
|
|||
};
|
||||
|
||||
type Granted = {
|
||||
[key: string]: number;
|
||||
tries: number;
|
||||
score?: number;
|
||||
};
|
||||
|
||||
export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
||||
|
@ -24,6 +26,8 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
|||
notFound();
|
||||
}
|
||||
|
||||
const [granted, setGranted] = useState<Granted | null>(null);
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
|
@ -57,8 +61,8 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
|||
}
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
alert('Réponse correcte !');
|
||||
if (res.ok || res.status === 406) {
|
||||
setGranted(await res.json());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +80,7 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
|||
onSubmit={handleSubmit(onSubmit)}
|
||||
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
|
||||
className="w-full"
|
||||
label="Réponse"
|
||||
|
@ -85,7 +89,12 @@ export default function Puzzle({ puzzle }: { puzzle: PuzzleType }) {
|
|||
required
|
||||
{...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
|
||||
className="h-16 w-full sm:w-1/3"
|
||||
label="Code"
|
||||
|
|
Loading…
Add table
Reference in a new issue