chore: show dates

This commit is contained in:
Rodolfo Ruiz
2025-09-04 21:25:30 -06:00
parent aa62b06c23
commit f42d08c091
2 changed files with 23 additions and 2 deletions

View File

@@ -25,6 +25,23 @@ function extractTenantId(token) {
return '';
}
function formatDateSafe(value) {
if (!value) return '—';
// Accept Date instance, ISO string, or numeric timestamp
const d = value instanceof Date ? value : new Date(value);
if (Number.isNaN(d.getTime())) return '—';
// Treat placeholder/default dates as empty
const year = d.getUTCFullYear();
if (year <= 1971) return '—';
return new Intl.DateTimeFormat(undefined, {
year: 'numeric',
month: 'short',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
}).format(d);
}
export default function AddOrEditCategoryForm({ onAdd, initialData, onCancel, materials: materialsProp = [], initialMaterialNames = [] }) {
const { user } = useAuth();
const token = user?.thalosToken || localStorage.getItem('thalosToken');
@@ -349,9 +366,9 @@ const tagLabelById = useMemo(() => {
{form._Id || form.id ? (
<Box sx={{ display: 'grid', gridTemplateColumns: { xs: '1fr', md: '1fr 1fr' }, gap: 2, mt: 2 }}>
<TextField label="Created At" value={form.createdAt ? new Date(form.createdAt).toLocaleString() : '—'} InputProps={{ readOnly: true }} fullWidth />
<TextField label="Created At" value={formatDateSafe(form.createdAt)} InputProps={{ readOnly: true }} fullWidth />
<TextField label="Created By" value={form.createdBy ?? '—'} InputProps={{ readOnly: true }} fullWidth />
<TextField label="Updated At" value={form.updatedAt ? new Date(form.updatedAt).toLocaleString() : '—'} InputProps={{ readOnly: true }} fullWidth />
<TextField label="Updated At" value={formatDateSafe(form.updatedAt)} InputProps={{ readOnly: true }} fullWidth />
<TextField label="Updated By" value={form.updatedBy ?? '—'} InputProps={{ readOnly: true }} fullWidth />
</Box>
) : null}

View File

@@ -84,6 +84,10 @@ export default function Categories() {
materialNames: typeof r.material === 'string'
? r.material.split(',').map(s => s.trim()).filter(Boolean)
: Array.isArray(r.material) ? r.material : [],
createdAt: r.createdAt ?? null,
createdBy: r.createdBy ?? null,
updatedAt: r.updatedAt ?? null,
updatedBy: r.updatedBy ?? null,
});
setOpen(true);
};