feat: add settings page
This commit is contained in:
parent
6ce98e6dae
commit
cad384b52c
41
app/routes/admin/settings.tsx
Normal file
41
app/routes/admin/settings.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
import type { Route } from './+types/settings';
|
||||
import { Card } from '~/components/ui/card';
|
||||
import { PageHeader } from '~/components/ui/page-header';
|
||||
import { SettingToggle } from '~/components/settings/setting-toggle';
|
||||
import { SETTING_TOGGLES } from '~/data/settings/constants';
|
||||
import { useAdminData } from '~/hooks/admin/use-admin-data';
|
||||
import { getErrorMessage } from '~/lib/errors';
|
||||
import { updateSetting } from '~/services/settings';
|
||||
import type { ActionResult } from '~/types/action';
|
||||
import type { SettingKey } from '~/types/settings';
|
||||
|
||||
const SETTING_KEYS = new Set<string>(SETTING_TOGGLES.map((setting) => setting.key));
|
||||
|
||||
export async function clientAction({ request }: Route.ClientActionArgs): Promise<ActionResult> {
|
||||
const formData = await request.formData();
|
||||
const key = String(formData.get('key'));
|
||||
if (!SETTING_KEYS.has(key)) return { ok: false, error: 'Unknown setting' };
|
||||
try {
|
||||
await updateSetting(key as SettingKey, formData.get('value') === 'true');
|
||||
return { ok: true, intent: 'update', message: 'Setting saved' };
|
||||
} catch (error) {
|
||||
return { ok: false, error: getErrorMessage(error) };
|
||||
}
|
||||
}
|
||||
|
||||
export default function SettingsPage() {
|
||||
const { settings } = useAdminData();
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-6'>
|
||||
<PageHeader title='Settings' description='Branding options for projects and their AR pages.' />
|
||||
<Card className='flex max-w-2xl flex-col divide-y divide-border-divider px-5'>
|
||||
{SETTING_TOGGLES.map((setting) => (
|
||||
<div key={setting.key} className='py-4'>
|
||||
<SettingToggle setting={setting} value={settings[setting.key]} />
|
||||
</div>
|
||||
))}
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user