95 lines
3.4 KiB
TypeScript
95 lines
3.4 KiB
TypeScript
import { Link, useForm } from '@inertiajs/react';
|
|
import { Management, Field, button, control } from '../management/shared';
|
|
type Content = { body: string; image_resource_id: number | null };
|
|
export default function ArticleEditor({
|
|
resource,
|
|
content,
|
|
images,
|
|
revisions,
|
|
}: {
|
|
resource: { id: number; title: string; metadata_version: number };
|
|
content: Content | null;
|
|
images: { id: number; title: string }[];
|
|
revisions: {
|
|
revision_no: number;
|
|
change_type: string;
|
|
created_at: string;
|
|
}[];
|
|
}) {
|
|
const form = useForm({
|
|
body: content?.body ?? '',
|
|
image_resource_id: content?.image_resource_id
|
|
? String(content.image_resource_id)
|
|
: '',
|
|
metadata_version: resource.metadata_version,
|
|
});
|
|
return (
|
|
<Management title={`Editar artigo — ${resource.title}`}>
|
|
<p>
|
|
O original permanece intacto na biblioteca. Guardar o corpo
|
|
retira a publicação até à sua ação expressa no acervo.
|
|
</p>
|
|
<form
|
|
className="max-w-3xl space-y-5"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.put(
|
|
`/management/portal-services/resources/${resource.id}/article`,
|
|
);
|
|
}}
|
|
>
|
|
<Field label="Corpo do artigo" error={form.errors.body}>
|
|
<textarea
|
|
className={control}
|
|
rows={16}
|
|
value={form.data.body}
|
|
onChange={(e) => form.setData('body', e.target.value)}
|
|
/>
|
|
<p>
|
|
Texto simples. Separe os parágrafos com uma linha em
|
|
branco.
|
|
</p>
|
|
</Field>
|
|
<Field
|
|
label="Imagem da biblioteca"
|
|
error={form.errors.image_resource_id}
|
|
>
|
|
<select
|
|
className={control}
|
|
value={form.data.image_resource_id}
|
|
onChange={(e) =>
|
|
form.setData('image_resource_id', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Sem imagem</option>
|
|
{images.map((i) => (
|
|
<option key={i.id} value={i.id}>
|
|
{i.title}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<button className={button} disabled={form.processing}>
|
|
Guardar artigo como rascunho
|
|
</button>{' '}
|
|
<Link className="underline" href="/management/portal-services">
|
|
Voltar ao acervo
|
|
</Link>
|
|
</form>
|
|
<h2>Histórico</h2>
|
|
<ul>
|
|
{revisions.map((r) => (
|
|
<li key={r.revision_no}>
|
|
Revisão {r.revision_no} · {r.change_type} ·{' '}
|
|
{r.created_at}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<p>
|
|
Título, descrição, autor e fonte são editados em Editar
|
|
metadados no acervo.
|
|
</p>
|
|
</Management>
|
|
);
|
|
}
|