feat(offers): complete phase five operational controls in QA
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { Head } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { profileJson } from '@/lib/profile-json';
|
||||
import { createOperationKey } from '@/lib/operation-key';
|
||||
export default function OfferReport({ offerId }: { offerId: number }) {
|
||||
const [key] = useState(createOperationKey);
|
||||
const [reason, setReason] = useState('');
|
||||
const [confirm, setConfirm] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [sent, setSent] = useState(false);
|
||||
const [message, setMessage] = useState('');
|
||||
async function submit() {
|
||||
setBusy(true);
|
||||
try {
|
||||
const result = await profileJson(
|
||||
`/minhas-oportunidades/ofertas/${offerId}/denuncias`,
|
||||
{ client_key: key, reason, confirm },
|
||||
);
|
||||
setSent(true);
|
||||
setMessage(`Denúncia registada. Referência: ${result.id}.`);
|
||||
} catch (error) {
|
||||
setMessage(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: 'Não foi possível registar a denúncia.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<main className="mx-auto w-full max-w-2xl space-y-5 p-4">
|
||||
<Head title="Denunciar oferta" />
|
||||
<h1 className="text-2xl font-semibold">Denunciar oferta</h1>
|
||||
<p>
|
||||
Explique os factos que justificam a denúncia. A equipa
|
||||
responsável irá analisá-la em privado.
|
||||
</p>
|
||||
<form
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
void submit();
|
||||
}}
|
||||
className="space-y-4"
|
||||
>
|
||||
<fieldset disabled={busy || sent} className="space-y-4">
|
||||
<label className="block">
|
||||
Fundamento
|
||||
<textarea
|
||||
className="mt-2 block w-full rounded border p-3"
|
||||
required
|
||||
minLength={20}
|
||||
maxLength={2000}
|
||||
value={reason}
|
||||
onChange={(event) => setReason(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={confirm}
|
||||
onChange={(event) =>
|
||||
setConfirm(event.target.checked)
|
||||
}
|
||||
/>
|
||||
Confirmo o envio destes factos para análise da equipa.
|
||||
</label>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded border px-4 py-2"
|
||||
disabled={!confirm || reason.trim().length < 20}
|
||||
>
|
||||
Registar denúncia
|
||||
</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
<p role="status">{message}</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user