add share page options enable filtering and enforce theme

This commit is contained in:
Francis Cao committed 2026-05-07 13:24:45 -07:00
1 parent 5ccfb6d0a5
commit 9b099408c2
75 files changed
+450 -172

No files matched your search

+56 -19
View File
@@ -1,6 +1,16 @@
import { Button, Column, Form, FormField, FormSubmitButton, Row, TextField } from '@umami/react-zen';
import {
Button,
Column,
Form,
FormField,
FormSubmitButton,
Row,
Switch,
TextField,
} from '@umami/react-zen';
import { useState } from 'react';
import { useApi, useMessages, useModified } from '@/components/hooks';
import { ThemeModeSelector } from '@/components/input/ThemeModeSelector';
export function SimpleShareCreateForm({
createPath,
@@ -15,15 +25,19 @@ export function SimpleShareCreateForm({
const { touch } = useModified();
const { t, labels, getErrorMessage } = useMessages();
const [isPending, setIsPending] = useState(false);
const [error, setError] = useState<unknown>(null);
const [error, setError] = useState<any>(null);
const handleSubmit = async (data: { name: string }) => {
const handleSubmit = async (data: { name: string; allowFilter?: boolean; theme?: string }) => {
setIsPending(true);
setError(null);
try {
await post(createPath, {
name: data.name,
parameters: {
allowFilter: data.allowFilter ?? true,
theme: data.theme === 'system' ? undefined : data.theme,
},
});
touch('shares');
@@ -36,22 +50,45 @@ export function SimpleShareCreateForm({
};
return (
<Form onSubmit={handleSubmit} error={getErrorMessage(error)} defaultValues={{ name: '' }}>
<Column gap="4">
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
<TextField autoComplete="off" autoFocus />
</FormField>
<Row justifyContent="flex-end" gap="3">
{onCancel && (
<Button isDisabled={isPending} onPress={onCancel}>
{t(labels.cancel)}
</Button>
)}
<FormSubmitButton variant="primary" isDisabled={isPending}>
{t(labels.add)}
</FormSubmitButton>
</Row>
</Column>
<Form
onSubmit={handleSubmit}
error={getErrorMessage(error)}
defaultValues={{ name: '', allowFilter: true, theme: 'system' }}
>
{({ watch, setValue }) => (
<Column gap="4">
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
<TextField autoComplete="off" autoFocus />
</FormField>
<Row gap="6">
<FormField label={t(labels.filters)} name="allowFilter">
<Switch
isSelected={watch('allowFilter')}
onChange={value => setValue('allowFilter', value, { shouldDirty: true })}
>
{t(labels.filtersEnabled)}
</Switch>
</FormField>
<FormField label={t(labels.theme)} name="theme">
<ThemeModeSelector
value={watch('theme')}
includeSystem
onChange={value => setValue('theme', value, { shouldDirty: true })}
/>
</FormField>
</Row>
<Row justifyContent="flex-end" gap="3">
{onCancel && (
<Button isDisabled={isPending} onPress={onCancel}>
{t(labels.cancel)}
</Button>
)}
<FormSubmitButton variant="primary" isDisabled={isPending}>
{t(labels.add)}
</FormSubmitButton>
</Row>
</Column>
)}
</Form>
);
}
+50 -21
View File
@@ -7,10 +7,12 @@ import {
Label,
Loading,
Row,
Switch,
TextField,
} from '@umami/react-zen';
import { useEffect, useState } from 'react';
import { useApi, useConfig, useMessages, useModified } from '@/components/hooks';
import { ThemeModeSelector } from '@/components/input/ThemeModeSelector';
export function SimpleShareEditForm({
shareId,
@@ -49,7 +51,7 @@ export function SimpleShareEditForm({
loadShare();
}, [get, modified, shareId]);
const handleSubmit = async (data: { name: string }) => {
const handleSubmit = async (data: { name: string; allowFilter?: boolean; theme?: string }) => {
setIsPending(true);
setError(null);
@@ -57,7 +59,11 @@ export function SimpleShareEditForm({
await post(`/share/id/${shareId}`, {
name: data.name,
slug: share.slug,
parameters: share.parameters || {},
parameters: {
...(share.parameters || {}),
allowFilter: data.allowFilter ?? true,
theme: data.theme === 'system' ? undefined : data.theme,
},
});
touch('shares');
@@ -78,27 +84,50 @@ export function SimpleShareEditForm({
<Form
onSubmit={handleSubmit}
error={getErrorMessage(error)}
defaultValues={{ name: share?.name || '' }}
defaultValues={{
name: share?.name || '',
allowFilter: share?.parameters?.allowFilter ?? true,
theme: share?.parameters?.theme || 'system',
}}
>
<Column gap="6">
<Column>
<Label>{t(labels.shareUrl)}</Label>
<TextField value={getUrl(share?.slug || '')} isReadOnly allowCopy />
{({ watch, setValue }) => (
<Column gap="6">
<Column>
<Label>{t(labels.shareUrl)}</Label>
<TextField value={getUrl(share?.slug || '')} isReadOnly allowCopy />
</Column>
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
<TextField autoComplete="off" autoFocus />
</FormField>
<Row gap="6">
<FormField label={t(labels.filters)} name="allowFilter">
<Switch
isSelected={watch('allowFilter')}
onChange={value => setValue('allowFilter', value, { shouldDirty: true })}
>
{t(labels.filtersEnabled)}
</Switch>
</FormField>
<FormField label={t(labels.theme)} name="theme">
<ThemeModeSelector
value={watch('theme')}
includeSystem
onChange={value => setValue('theme', value, { shouldDirty: true })}
/>
</FormField>
</Row>
<Row justifyContent="flex-end" paddingTop="3" gap="3">
{onClose && (
<Button isDisabled={isPending} onPress={onClose}>
{t(labels.cancel)}
</Button>
)}
<FormSubmitButton variant="primary" isDisabled={isPending}>
{t(labels.save)}
</FormSubmitButton>
</Row>
</Column>
<FormField label={t(labels.name)} name="name" rules={{ required: t(labels.required) }}>
<TextField autoComplete="off" autoFocus />
</FormField>
<Row justifyContent="flex-end" paddingTop="3" gap="3">
{onClose && (
<Button isDisabled={isPending} onPress={onClose}>
{t(labels.cancel)}
</Button>
)}
<FormSubmitButton variant="primary" isDisabled={isPending}>
{t(labels.save)}
</FormSubmitButton>
</Row>
</Column>
)}
</Form>
);
}