further improvements for the mobile admin
This commit is contained in:
@@ -18,7 +18,6 @@ type FormState = {
|
||||
eventTypeId: number | null;
|
||||
description: string;
|
||||
location: string;
|
||||
enableBranding: boolean;
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
@@ -27,7 +26,7 @@ export default function MobileEventFormPage() {
|
||||
const slug = slugParam ?? null;
|
||||
const isEdit = Boolean(slug);
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation('management');
|
||||
const { t } = useTranslation(['management', 'common']);
|
||||
|
||||
const [form, setForm] = React.useState<FormState>({
|
||||
name: '',
|
||||
@@ -35,7 +34,6 @@ export default function MobileEventFormPage() {
|
||||
eventTypeId: null,
|
||||
description: '',
|
||||
location: '',
|
||||
enableBranding: false,
|
||||
published: false,
|
||||
});
|
||||
const [eventTypes, setEventTypes] = React.useState<TenantEventType[]>([]);
|
||||
@@ -56,7 +54,6 @@ export default function MobileEventFormPage() {
|
||||
eventTypeId: data.event_type_id ?? data.event_type?.id ?? null,
|
||||
description: typeof data.description === 'string' ? data.description : '',
|
||||
location: resolveLocation(data),
|
||||
enableBranding: Boolean((data.settings as Record<string, unknown>)?.branding_allowed ?? true),
|
||||
published: data.status === 'published',
|
||||
});
|
||||
setError(null);
|
||||
@@ -98,24 +95,24 @@ export default function MobileEventFormPage() {
|
||||
event_date: form.date || undefined,
|
||||
event_type_id: form.eventTypeId ?? undefined,
|
||||
status: form.published ? 'published' : 'draft',
|
||||
settings: { branding_allowed: form.enableBranding, location: form.location },
|
||||
settings: { location: form.location },
|
||||
});
|
||||
navigate(adminPath(`/mobile/events/${slug}`));
|
||||
} else {
|
||||
const payload = {
|
||||
name: form.name || 'Event',
|
||||
name: form.name || t('eventForm.fields.name.fallback', 'Event'),
|
||||
slug: `${Date.now()}`,
|
||||
event_type_id: form.eventTypeId ?? undefined,
|
||||
event_date: form.date || undefined,
|
||||
status: form.published ? 'published' : 'draft' as const,
|
||||
settings: { branding_allowed: form.enableBranding, location: form.location },
|
||||
status: (form.published ? 'published' : 'draft') as const,
|
||||
settings: { location: form.location },
|
||||
};
|
||||
const { event } = await createEvent(payload as any);
|
||||
navigate(adminPath(`/mobile/events/${event.slug}`));
|
||||
}
|
||||
} catch (err) {
|
||||
if (!isAuthError(err)) {
|
||||
setError(getApiErrorMessage(err, t('events.errors.saveFailed', 'Event konnte nicht gespeichert werden.')));
|
||||
setError(getApiErrorMessage(err, t('eventForm.errors.saveFailed', 'Event could not be saved.')));
|
||||
}
|
||||
} finally {
|
||||
setSaving(false);
|
||||
@@ -125,7 +122,7 @@ export default function MobileEventFormPage() {
|
||||
return (
|
||||
<MobileShell
|
||||
activeTab="home"
|
||||
title={isEdit ? t('events.form.editTitle', 'Edit Event') : t('events.form.createTitle', 'Create New Event')}
|
||||
title={isEdit ? t('eventForm.titles.edit', 'Edit event') : t('eventForm.titles.create', 'Create event')}
|
||||
onBack={() => navigate(-1)}
|
||||
>
|
||||
{error ? (
|
||||
@@ -137,17 +134,17 @@ export default function MobileEventFormPage() {
|
||||
) : null}
|
||||
|
||||
<MobileCard space="$3">
|
||||
<Field label={t('events.form.name', 'Event Name')}>
|
||||
<Field label={t('eventForm.fields.name.label', 'Event name')}>
|
||||
<input
|
||||
type="text"
|
||||
value={form.name}
|
||||
onChange={(e) => setForm((prev) => ({ ...prev, name: e.target.value }))}
|
||||
placeholder="e.g., Smith Wedding"
|
||||
placeholder={t('eventForm.fields.name.placeholder', 'e.g. Summer Party 2025')}
|
||||
style={inputStyle}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label={t('events.form.date', 'Date & Time')}>
|
||||
<Field label={t('eventForm.fields.date.label', 'Date & time')}>
|
||||
<XStack alignItems="center" space="$2">
|
||||
<input
|
||||
type="datetime-local"
|
||||
@@ -180,46 +177,28 @@ export default function MobileEventFormPage() {
|
||||
)}
|
||||
</Field>
|
||||
|
||||
<Field label={t('events.form.description', 'Optional Details')}>
|
||||
<Field label={t('eventForm.fields.description.label', 'Optional details')}>
|
||||
<textarea
|
||||
value={form.description}
|
||||
onChange={(e) => setForm((prev) => ({ ...prev, description: e.target.value }))}
|
||||
placeholder={t('events.form.descriptionPlaceholder', 'Description')}
|
||||
placeholder={t('eventForm.fields.description.placeholder', 'Description')}
|
||||
style={{ ...inputStyle, minHeight: 96 }}
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label={t('events.form.location', 'Location')}>
|
||||
<Field label={t('eventForm.fields.location.label', 'Location')}>
|
||||
<XStack alignItems="center" space="$2">
|
||||
<input
|
||||
type="text"
|
||||
value={form.location}
|
||||
onChange={(e) => setForm((prev) => ({ ...prev, location: e.target.value }))}
|
||||
placeholder={t('events.form.locationPlaceholder', 'Location')}
|
||||
placeholder={t('eventForm.fields.location.placeholder', 'Location')}
|
||||
style={{ ...inputStyle, flex: 1 }}
|
||||
/>
|
||||
<MapPin size={16} color="#9ca3af" />
|
||||
</XStack>
|
||||
</Field>
|
||||
|
||||
<Field label={t('events.form.enableBranding', 'Enable Branding & Moderation')}>
|
||||
<XStack alignItems="center" space="$2">
|
||||
<Switch
|
||||
checked={form.enableBranding}
|
||||
onCheckedChange={(checked) =>
|
||||
setForm((prev) => ({ ...prev, enableBranding: Boolean(checked) }))
|
||||
}
|
||||
size="$3"
|
||||
aria-label={t('events.form.enableBranding', 'Enable Branding & Moderation')}
|
||||
>
|
||||
<Switch.Thumb />
|
||||
</Switch>
|
||||
<Text fontSize="$sm" color="#111827">
|
||||
{form.enableBranding ? t('common.enabled', 'Enabled') : t('common.disabled', 'Disabled')}
|
||||
</Text>
|
||||
</XStack>
|
||||
</Field>
|
||||
|
||||
<Field label={t('eventForm.fields.publish.label', 'Publish immediately')}>
|
||||
<XStack alignItems="center" space="$2">
|
||||
<Switch
|
||||
@@ -233,7 +212,7 @@ export default function MobileEventFormPage() {
|
||||
<Switch.Thumb />
|
||||
</Switch>
|
||||
<Text fontSize="$sm" color="#111827">
|
||||
{form.published ? t('common.enabled', 'Enabled') : t('common.disabled', 'Disabled')}
|
||||
{form.published ? t('common:states.enabled', 'Enabled') : t('common:states.disabled', 'Disabled')}
|
||||
</Text>
|
||||
</XStack>
|
||||
<Text fontSize="$xs" color="#6b7280">{t('eventForm.fields.publish.help', 'Enable if guests should see the event right away. You can change the status later.')}</Text>
|
||||
@@ -254,10 +233,19 @@ export default function MobileEventFormPage() {
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
{t('events.form.saveDraft', 'Save as Draft')}
|
||||
{t('eventForm.actions.saveDraft', 'Save as draft')}
|
||||
</button>
|
||||
) : null}
|
||||
<CTAButton label={saving ? t('events.form.saving', 'Saving...') : isEdit ? t('events.form.update', 'Update Event') : t('events.form.create', 'Create Event')} onPress={() => handleSubmit()} />
|
||||
<CTAButton
|
||||
label={
|
||||
saving
|
||||
? t('eventForm.actions.saving', 'Saving…')
|
||||
: isEdit
|
||||
? t('eventForm.actions.update', 'Update event')
|
||||
: t('eventForm.actions.create', 'Create event')
|
||||
}
|
||||
onPress={() => handleSubmit()}
|
||||
/>
|
||||
</YStack>
|
||||
</MobileShell>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user