201 lines
8.0 KiB
TypeScript
201 lines
8.0 KiB
TypeScript
import { router, useForm } from "@inertiajs/react";
|
|
import { Management, Field, control, button } from "../management/shared";
|
|
|
|
export default function Manage({
|
|
documents,
|
|
resources,
|
|
partnerships,
|
|
}: {
|
|
documents: { id: string; file_name: string }[];
|
|
resources: { id: number; title: string; published: boolean }[];
|
|
partnerships: {
|
|
id: number;
|
|
title: string;
|
|
sector: string;
|
|
province: string;
|
|
offer: string;
|
|
seeking: string;
|
|
status: string;
|
|
}[];
|
|
}) {
|
|
const upload = useForm<{ file: File | null; publication_consent: boolean }>({
|
|
file: null,
|
|
publication_consent: false,
|
|
});
|
|
const form = useForm({
|
|
document_id: "",
|
|
title: "",
|
|
category: "",
|
|
topic: "",
|
|
source_reference: "",
|
|
legislation: false,
|
|
essential: false,
|
|
published: false,
|
|
});
|
|
return (
|
|
<Management title="Documentos públicos e Bolsa de Parcerias">
|
|
<form
|
|
className="space-y-4 rounded border p-5"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
upload.post("/management/portal-services/upload", {
|
|
forceFormData: true,
|
|
preserveScroll: true,
|
|
onSuccess: () => upload.reset(),
|
|
});
|
|
}}
|
|
>
|
|
<h2 className="text-xl font-bold">Carregar documento autorizado</h2>
|
|
<p>
|
|
PDF ou TXT, até 10 MiB. Não carregar dados privados. A publicação é feita no
|
|
catálogo abaixo.
|
|
</p>
|
|
<Field label="Ficheiro">
|
|
<input
|
|
type="file"
|
|
accept="application/pdf,text/plain"
|
|
required
|
|
onChange={(e) => upload.setData("file", e.target.files?.[0] ?? null)}
|
|
/>
|
|
</Field>
|
|
<label className="flex gap-2">
|
|
<input
|
|
type="checkbox"
|
|
required
|
|
checked={upload.data.publication_consent}
|
|
onChange={(e) => upload.setData("publication_consent", e.target.checked)}
|
|
/>
|
|
Confirmo que o ficheiro está autorizado para divulgação pública.
|
|
</label>
|
|
{Object.entries(upload.errors).map(([key, error]) => (
|
|
<p role="alert" key={key}>
|
|
{error}
|
|
</p>
|
|
))}
|
|
<button className={button} disabled={upload.processing}>
|
|
Carregar
|
|
</button>
|
|
</form>
|
|
<form
|
|
className="space-y-4 rounded border p-5"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.post("/management/portal-services/resources", {
|
|
preserveScroll: true,
|
|
onSuccess: () => form.reset(),
|
|
});
|
|
}}
|
|
>
|
|
<h2 className="text-xl font-bold">Catalogar documento</h2>
|
|
<Field label="Documento público">
|
|
<select
|
|
required
|
|
className={control}
|
|
value={form.data.document_id}
|
|
onChange={(e) => form.setData("document_id", e.target.value)}
|
|
>
|
|
<option value="">Seleccionar</option>
|
|
{documents.map((d) => (
|
|
<option value={d.id} key={d.id}>
|
|
{d.file_name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
{(["title", "category", "topic", "source_reference"] as const).map((key) => (
|
|
<Field
|
|
key={key}
|
|
label={
|
|
{
|
|
title: "Título",
|
|
category: "Categoria (ex.: Formulário)",
|
|
topic: "Tema (ex.: Incentivos)",
|
|
source_reference: "Fonte, versão e referência de autorização",
|
|
}[key]
|
|
}
|
|
>
|
|
<input
|
|
required
|
|
className={control}
|
|
value={form.data[key]}
|
|
onChange={(e) => form.setData(key, e.target.value)}
|
|
/>
|
|
</Field>
|
|
))}
|
|
{(["legislation", "essential", "published"] as const).map((key) => (
|
|
<label key={key} className="flex gap-2">
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data[key]}
|
|
onChange={(e) => form.setData(key, e.target.checked)}
|
|
/>
|
|
{
|
|
{
|
|
legislation: "Incluir em Legislação e Incentivos",
|
|
essential: "Documento essencial",
|
|
published: "Aprovar e publicar",
|
|
}[key]
|
|
}
|
|
</label>
|
|
))}
|
|
{Object.entries(form.errors).map(([key, error]) => (
|
|
<p role="alert" key={key}>
|
|
{error}
|
|
</p>
|
|
))}
|
|
<button className={button} disabled={form.processing}>
|
|
Guardar catálogo
|
|
</button>
|
|
</form>
|
|
<h2 className="text-xl font-bold">Documentos catalogados</h2>
|
|
{resources.map((r) => (
|
|
<article key={r.id} className="space-y-3 rounded border p-4">
|
|
<h3>
|
|
{r.title} — {r.published ? "Publicado" : "Retirado"}
|
|
</h3>
|
|
<button
|
|
className={button}
|
|
onClick={() =>
|
|
router.post(
|
|
`/management/portal-services/resources/${r.id}`,
|
|
{ published: !r.published },
|
|
{ preserveScroll: true },
|
|
)
|
|
}
|
|
>
|
|
{r.published ? "Retirar" : "Publicar"}
|
|
</button>
|
|
</article>
|
|
))}
|
|
<h2 className="text-xl font-bold">Propostas de parceria</h2>
|
|
{partnerships.map((p) => (
|
|
<article key={p.id} className="space-y-3 rounded border p-4">
|
|
<h3 className="font-bold">{p.title}</h3>
|
|
<p>
|
|
{p.sector} · {p.province} ·{" "}
|
|
{p.status === "published"
|
|
? "Publicado"
|
|
: p.status === "pending"
|
|
? "Pendente"
|
|
: "Retirado"}
|
|
</p>
|
|
<p className="whitespace-pre-line">Oferece: {p.offer}</p>
|
|
<p className="whitespace-pre-line">Procura: {p.seeking}</p>
|
|
<button
|
|
className={button}
|
|
onClick={() =>
|
|
router.post(
|
|
`/management/portal-services/partnerships/${p.id}`,
|
|
{ published: p.status !== "published" },
|
|
{ preserveScroll: true },
|
|
)
|
|
}
|
|
>
|
|
{p.status === "published" ? "Retirar" : "Aprovar e publicar"}
|
|
</button>
|
|
</article>
|
|
))}
|
|
</Management>
|
|
);
|
|
}
|