Show name status in operator customer profile

This commit is contained in:
Yera All
2026-04-08 15:35:37 +05:00
parent 6f25de1f62
commit 5d192621b0
4 changed files with 73 additions and 6 deletions
+33 -2
View File
@@ -47,6 +47,7 @@ const state = {
draft: '',
saving: false,
error: '',
flash: '',
},
},
telegram: {
@@ -1074,15 +1075,40 @@ function emptyCustomerSpotlightMarkup(title, description) {
`;
}
function customerProfileNameEditorMarkup(customer) {
function customerProfileVoiceNameContext(liveCalls = []) {
const latestCall = latestItemByTime(liveCalls, ['last_transition_at', 'ended_at', 'connected_at', 'started_at', 'updated_at']);
if (!latestCall) {
return {
statusMeta: null,
sourceLabel: '',
};
}
const voiceContext = voiceSummaryForItem(latestCall) || latestCall || {};
return {
statusMeta: voiceCustomerNameStatusMeta(voiceContext?.customer_name_status),
sourceLabel: formatVoiceCustomerNameSource(voiceContext?.customer_name_source),
};
}
function customerProfileNameEditorMarkup(customer, context = {}) {
const editor = state.customers.nameEditor;
const isOpen = editor.open && editor.customerId === customer.customer_id;
const statusMeta = context.statusMeta || null;
const sourceLabel = String(context.sourceLabel || '').trim();
const flash = editor.flash && editor.customerId === customer.customer_id ? editor.flash : '';
const statusText = editor.error || (editor.saving ? 'Сохраняем имя клиента...' : 'Имя сохранится в профиле клиента и voice-контуре.');
return `
<div class="customer-profile-name-row">
<div class="customer-profile-name-stack">
<h3>${escapeHtml(customer.display_name || 'Без имени')}</h3>
<p>${escapeHtml(customerLeadCompany(customer))}</p>
${(statusMeta || sourceLabel || flash) ? `
<div class="customer-profile-name-meta">
${statusMeta ? `<span class="micro-badge ${escapeHtml(statusMeta.className)}">${escapeHtml(statusMeta.shortLabel)}</span>` : ''}
${sourceLabel ? `<span class="customer-profile-name-note">Источник: ${escapeHtml(sourceLabel)}</span>` : ''}
${flash ? `<span class="customer-profile-name-flash">${escapeHtml(flash)}</span>` : ''}
</div>
` : ''}
</div>
<button class="btn ghost customer-profile-name-trigger" type="button" data-customer-action="edit-name">
${isOpen ? 'Редактирование имени' : 'Изменить имя'}
@@ -1128,6 +1154,7 @@ function customerSpotlightMarkup(customer, options = {}) {
const liveCalls = Array.isArray(historyPayload?.live_calls)
? historyPayload.live_calls
: customerLiveCalls(customer);
const profileNameContext = customerProfileVoiceNameContext(liveCalls);
const historyEvents = Array.isArray(historyPayload?.history) && historyPayload.history.length
? historyPayload.history
: buildCustomerHistoryEvents(customer);
@@ -1203,7 +1230,7 @@ function customerSpotlightMarkup(customer, options = {}) {
<div class="customer-profile-avatar">${escapeHtml(customerInitials(customer.display_name))}</div>
<div class="customer-profile-copy">
<div class="customer-profile-kicker">Клиент ${escapeHtml(customer.customer_id)}</div>
${customerProfileNameEditorMarkup(customer)}
${customerProfileNameEditorMarkup(customer, profileNameContext)}
</div>
<div class="customer-profile-badges">
<span class="${source.className}">${escapeHtml(source.label)}</span>
@@ -1420,6 +1447,7 @@ function selectCustomer(customerId) {
state.customers.nameEditor.draft = '';
state.customers.nameEditor.saving = false;
state.customers.nameEditor.error = '';
state.customers.nameEditor.flash = '';
}
state.customers.selectedCustomerId = customerId || '';
if (customerId) {
@@ -4188,6 +4216,7 @@ function openCustomerProfileNameEditor(customerId = state.customers.selectedCust
state.customers.nameEditor.draft = customer.display_name || '';
state.customers.nameEditor.saving = false;
state.customers.nameEditor.error = '';
state.customers.nameEditor.flash = '';
renderCustomerSpotlight();
}
@@ -4354,6 +4383,7 @@ async function saveCustomerProfileName() {
renderCustomerSpotlight();
try {
const savedName = await persistCustomerDisplayName({ customerId, displayName });
state.customers.nameEditor.flash = 'Сохранено';
closeCustomerProfileNameEditor();
log('Имя клиента обновлено из профиля', { customer_id: customerId, name: savedName });
} catch (err) {
@@ -6394,6 +6424,7 @@ function handleCustomerProfileNameInput(event) {
return;
}
state.customers.nameEditor.draft = input.value || '';
state.customers.nameEditor.flash = '';
if (!state.customers.nameEditor.error) {
return;
}