Files
redefined-designs/frontend/src/admin/Settings.tsx
T
bermudalamb 7df897c0fd
Linting / lint (pull_request) Successful in 1m49s
SonarQube Analysis / sonarqube (pull_request) Failing after 17m57s
feat(admin): give the customer emails a tab of their own (#135)
The six email templates lived at the bottom of the Settings tab, under the cart-expiry card and inside a 720px wrapper. Finding them took knowing they were there — "Settings" reads as app configuration and the only thing visible on that tab was a 480px card about cart expiry. Reaching them, the editor was then crushed: EmailTemplateEditor splits a markdown pane and a rendered preview side by side, and 720px left each half under 350px, so the preview showed the email at a width nothing like how it will be read and the markdown toolbar wrapped.

Emails is now its own tab, between Customers and Settings, with no width cap. Within it the email types are a left vertical rail rather than a strip across the top: six labels wrapped on narrower displays, and stacking them is what leaves the editor the width the split needs. Settings keeps the cart-expiry card and nothing else.

The Default/Customised tag comes off the labels. Six antd tags stacked down a rail stop it being scannable, so a customised template gets a dot and the state in full moves into the editor beside the Restore default button that acts on it. The dot carries aria-label="Customised" so the word stays in the tab's accessible name and the state is not conveyed by a mark alone.

Emails owns the fetch it inherited from Settings, and adds a Spin over it. templates starts empty, so the gap before the request lands would otherwise render an empty rail that reads as "there are no emails to edit".

Closes #135
2026-08-23 08:01:42 -05:00

47 lines
1.6 KiB
TypeScript

import { useEffect, useState } from 'react';
import Form from 'antd/es/form';
import InputNumber from 'antd/es/input-number';
import Button from 'antd/es/button';
import Typography from 'antd/es/typography';
import message from 'antd/es/message';
import Card from 'antd/es/card';
import { fetchAdminSettings, updateAdminSettings } from './adminSettingsApi';
const { Title, Text } = Typography;
export default function Settings() {
const [form] = Form.useForm();
const [loading, setLoading] = useState(true);
useEffect(() => {
fetchAdminSettings()
.then(s => {
form.setFieldsValue({ cartExpiryHours: s.cartExpiryHours });
})
// A rejection here used to leave the form spinning indefinitely.
.catch(() => message.error('Could not load settings'))
.finally(() => setLoading(false));
}, [form]);
async function handleSave() {
const values = await form.validateFields();
await updateAdminSettings(values);
message.success('Settings saved');
}
return (
<Card style={{ maxWidth: 480 }}>
<Title level={4}>Cart Settings</Title>
<Text type="secondary">
How long an item stays reserved in a customer's cart before it's automatically released back to available inventory.
</Text>
<Form form={form} layout="vertical" style={{ marginTop: 16 }} disabled={loading}>
<Form.Item name="cartExpiryHours" label="Cart expiry (hours)" rules={[{ required: true }]}>
<InputNumber min={0.5} step={0.5} style={{ width: '100%' }} />
</Form.Item>
<Button type="primary" onClick={handleSave} loading={loading}>Save</Button>
</Form>
</Card>
);
}