fix(companies): format JSON description in modal
- Added formatDescription helper to parse JSON and display as formatted list - Shows tagline, stores, employees, motto etc as labeled fields - Falls back to plain text if not JSON
This commit is contained in:
parent
16012b701a
commit
e47c25fac8
1 changed files with 30 additions and 1 deletions
|
|
@ -28,6 +28,33 @@ const companyDateFormatter = new Intl.DateTimeFormat("en-US", {
|
||||||
timeZone: "UTC",
|
timeZone: "UTC",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Helper to format description (handles JSON or plain text)
|
||||||
|
const formatDescription = (description: string | undefined) => {
|
||||||
|
if (!description) return null
|
||||||
|
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(description)
|
||||||
|
if (typeof parsed === 'object' && parsed !== null) {
|
||||||
|
return (
|
||||||
|
<dl className="space-y-2">
|
||||||
|
{Object.entries(parsed).map(([key, value]) => (
|
||||||
|
<div key={key} className="flex flex-col">
|
||||||
|
<dt className="text-xs text-muted-foreground capitalize">
|
||||||
|
{key.replace(/([A-Z])/g, ' $1').replace(/_/g, ' ')}
|
||||||
|
</dt>
|
||||||
|
<dd className="text-sm">{String(value)}</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Not JSON, return as plain text
|
||||||
|
}
|
||||||
|
|
||||||
|
return <p className="text-sm mt-1">{description}</p>
|
||||||
|
}
|
||||||
|
|
||||||
export default function AdminCompaniesPage() {
|
export default function AdminCompaniesPage() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [companies, setCompanies] = useState<AdminCompany[]>([])
|
const [companies, setCompanies] = useState<AdminCompany[]>([])
|
||||||
|
|
@ -418,7 +445,9 @@ export default function AdminCompaniesPage() {
|
||||||
{selectedCompany.description && (
|
{selectedCompany.description && (
|
||||||
<div>
|
<div>
|
||||||
<Label className="text-muted-foreground text-xs">Description</Label>
|
<Label className="text-muted-foreground text-xs">Description</Label>
|
||||||
<p className="text-sm mt-1">{selectedCompany.description}</p>
|
<div className="mt-1">
|
||||||
|
{formatDescription(selectedCompany.description)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue