Add pages with fields, a field schema and the screens to edit them
This commit is contained in:
1 parent
ce1a8a1370
commit
517039b625
19 files changed
+660
-13
No files matched your search
@@ -0,0 +1,68 @@
|
||||
<script setup lang="ts">
|
||||
import { api, boot, useForm } from '../api';
|
||||
import FormFields, { type Field } from '../components/FormFields.vue';
|
||||
import Link from '../components/Link.vue';
|
||||
import { t } from '../i18n';
|
||||
import { flash, navigate } from '../state';
|
||||
|
||||
const props = defineProps<{
|
||||
page: {
|
||||
slug: string; title: string; meta_description: string; defined: boolean; fields: Field[];
|
||||
content: Record<string, any> | null; body: string | null; is_published: boolean | null;
|
||||
};
|
||||
}>();
|
||||
|
||||
const page = props.page;
|
||||
const form = useForm({
|
||||
title: page.title,
|
||||
meta_description: page.meta_description ?? '',
|
||||
...(page.defined ? { content: { ...page.content } } : { body: page.body ?? '', is_published: page.is_published ?? false }),
|
||||
} as Record<string, any>);
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
if (await form.send('put', `${boot.base}/pages/${page.slug}`)) {
|
||||
flash(t('Saved.'));
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(): Promise<void> {
|
||||
if (!window.confirm(t('Are you sure?'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
await api.delete(`${boot.base}/pages/${page.slug}`);
|
||||
void navigate(`${boot.base}/pages`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mb-6 flex items-center justify-between gap-3">
|
||||
<h1 class="font-display text-2xl font-bold">{{ page.title }}</h1>
|
||||
<Link :href="boot.base + '/pages'" class="m-btn m-btn-secondary">{{ t('Back') }}</Link>
|
||||
</div>
|
||||
<form class="m-card max-w-3xl space-y-5 p-5" @submit.prevent="submit">
|
||||
<div>
|
||||
<label for="title" class="m-label">{{ t('Title') }}</label>
|
||||
<input id="title" v-model="form.values.title" required maxlength="255" class="m-input" />
|
||||
<p v-if="form.errors.title" class="m-error">{{ form.errors.title }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label for="meta" class="m-label">{{ t('Description for search engines') }}</label>
|
||||
<input id="meta" v-model="form.values.meta_description" maxlength="255" class="m-input" />
|
||||
<p v-if="form.errors.meta_description" class="m-error">{{ form.errors.meta_description }}</p>
|
||||
</div>
|
||||
<FormFields v-if="page.defined" :fields="page.fields" :values="form.values.content" :errors="form.errors" prefix="content." />
|
||||
<template v-else>
|
||||
<div>
|
||||
<label for="body" class="m-label">{{ t('Text (Markdown)') }}</label>
|
||||
<textarea id="body" v-model="form.values.body" rows="14" class="m-input font-mono" />
|
||||
<p v-if="form.errors.body" class="m-error">{{ form.errors.body }}</p>
|
||||
</div>
|
||||
<label class="flex items-center gap-2 text-sm"><input v-model="form.values.is_published" type="checkbox" /> {{ t('Publish') }}</label>
|
||||
</template>
|
||||
<div class="flex gap-3">
|
||||
<button type="submit" class="m-btn m-btn-primary" :disabled="form.busy">{{ form.busy ? t('Saving…') : t('Save') }}</button>
|
||||
<button v-if="!page.defined" type="button" class="m-btn m-btn-danger" @click="remove">{{ t('Delete') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
Reference in new issue
Block a user