fix(dashboard): normalize legacy customer profile data
This commit is contained in:
+14
-2
@@ -1127,13 +1127,24 @@ const kinds = {
|
||||
}
|
||||
function withDefaults(kind, body) {
|
||||
if (kind === 'customers') {
|
||||
const source = body && typeof body === 'object' ? body : {}
|
||||
const value = {
|
||||
name: '', company: '', country: '', channel: 'telegram', email: '', phone: '',
|
||||
telegram: '', products: [], tags: [], source: 'telegram', stage: 'new',
|
||||
intentScore: 0, intentLevel: 'low', sentiment: 'neutral', riskLevel: 'none',
|
||||
valueLevel: 'D', isKey: false, ownerId: null,
|
||||
aiProfile: { summary: '', keyPoints: [], nextActions: [] },
|
||||
...body,
|
||||
...source,
|
||||
products: Array.isArray(source.products) ? source.products : [],
|
||||
tags: Array.isArray(source.tags) ? source.tags : [],
|
||||
aiProfile: {
|
||||
summary: '',
|
||||
keyPoints: [],
|
||||
nextActions: [],
|
||||
...(source.aiProfile && typeof source.aiProfile === 'object' ? source.aiProfile : {}),
|
||||
keyPoints: Array.isArray(source.aiProfile?.keyPoints) ? source.aiProfile.keyPoints : [],
|
||||
nextActions: Array.isArray(source.aiProfile?.nextActions) ? source.aiProfile.nextActions : [],
|
||||
},
|
||||
}
|
||||
return {
|
||||
...value,
|
||||
@@ -4493,7 +4504,8 @@ async function businessDataset(tenantId) {
|
||||
|
||||
app.get('/api/dashboard/overview', async (req, res) => {
|
||||
const data = await businessDataset(req.auth.tenantId)
|
||||
const { customers, conversations, tasks, risks, opportunities, messages, responseTimes, users, repliesByOwner, adoptions } = data
|
||||
const { conversations, tasks, risks, opportunities, messages, responseTimes, users, repliesByOwner, adoptions } = data
|
||||
const customers = data.customers.map((customer) => withDefaults('customers', customer))
|
||||
const unread = conversations.reduce((n, x) => n + Number(x.unreadCount || 0), 0)
|
||||
const today = dateKey()
|
||||
const won = opportunities.filter((item) => item.stage === 'won').length
|
||||
|
||||
@@ -235,7 +235,7 @@ export function DashboardPage() {
|
||||
<CountryFlag code={c.country} withName={false} />
|
||||
</div>
|
||||
<p className="mt-0.5 truncate text-xs text-muted-foreground">
|
||||
{c.products[0] ?? '—'} · 建议:{c.aiProfile.nextActions[0] ?? '跟进'}
|
||||
{c.products?.[0] ?? '—'} · 建议:{c.aiProfile?.nextActions?.[0] ?? '跟进'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 flex-col items-end gap-1">
|
||||
|
||||
Reference in New Issue
Block a user