Clean seller metadata display names
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 40s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 40s
This commit is contained in:
26
src/displayFormatters.ts
Normal file
26
src/displayFormatters.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
const SMALL_WORDS = new Set(['da', 'de', 'do', 'das', 'dos', 'e']);
|
||||
|
||||
export const removeTrailingSellerId = (value: string) => {
|
||||
return value.replace(/\s*#\d+\s*$/, '').trim();
|
||||
};
|
||||
|
||||
export const formatDisplayName = (value: string) => {
|
||||
const normalized = String(value || '').replace(/\s+/g, ' ').trim();
|
||||
if (!normalized) return '';
|
||||
|
||||
const withoutSellerId = removeTrailingSellerId(normalized);
|
||||
const withoutNumericPrefix = withoutSellerId.replace(/^\[\d+\]\s*/, '').trim();
|
||||
const isUppercaseName = /[A-ZÁÀÂÃÉÈÊÍÏÓÔÕÖÚÇÑ]/.test(withoutNumericPrefix) &&
|
||||
withoutNumericPrefix === withoutNumericPrefix.toUpperCase();
|
||||
|
||||
if (!isUppercaseName) return withoutNumericPrefix;
|
||||
|
||||
return withoutNumericPrefix
|
||||
.toLocaleLowerCase('pt-BR')
|
||||
.split(' ')
|
||||
.map((word, index) => {
|
||||
if (index > 0 && SMALL_WORDS.has(word)) return word;
|
||||
return word.charAt(0).toLocaleUpperCase('pt-BR') + word.slice(1);
|
||||
})
|
||||
.join(' ');
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContaine
|
||||
import DateRangePicker from '../components/DateRangePicker';
|
||||
import type { ClientDetailsAnalytics, DateRange, OrderData } from '../types';
|
||||
import { fetchClientDetailsAnalytics } from '../dataService';
|
||||
import { formatDisplayName, removeTrailingSellerId } from '../displayFormatters';
|
||||
|
||||
type CustomTooltipProps = {
|
||||
active?: boolean;
|
||||
@@ -27,14 +28,11 @@ const CustomTooltip = ({ active, payload, label }: CustomTooltipProps) => {
|
||||
};
|
||||
|
||||
const getOrderMetadata = (order: OrderData) => {
|
||||
const seller = [
|
||||
order.nome_vendedor,
|
||||
order.id_vendedor ? `#${order.id_vendedor}` : ''
|
||||
].filter(Boolean).join(' ');
|
||||
const sellerName = formatDisplayName(removeTrailingSellerId(order.nome_vendedor || ''));
|
||||
|
||||
return [
|
||||
order.cliente_nome_fantasia ? `Fantasia: ${order.cliente_nome_fantasia}` : '',
|
||||
seller ? `Vendedor: ${seller}` : '',
|
||||
order.cliente_nome_fantasia ? `Fantasia: ${formatDisplayName(order.cliente_nome_fantasia)}` : '',
|
||||
sellerName ? `Vendedor: ${sellerName}` : '',
|
||||
order.marketplace ? `Marketplace: ${order.marketplace}` : '',
|
||||
order.canal_venda ? `Canal: ${order.canal_venda}` : '',
|
||||
order.numero_ecommerce ? `E-commerce: ${order.numero_ecommerce}` : ''
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { ClientAnalyticsItem, ClientFilterOptions, ClientMetadataFilters, D
|
||||
import { fetchClientAnalytics, fetchClientFilterOptions, fetchRfmAnalytics, getCachedClientAnalytics, getCachedClientFilterOptions, getCachedRfmAnalytics } from '../dataService';
|
||||
import { endOfLocalDay, formatDateParam, parseLocalDateInput, rangeForDay, rangeForLastDays, rangeForPreviousDay, startOfLocalDay } from '../dateRanges';
|
||||
import type { ClientSortOption, ClientSummary } from '../analytics/clients';
|
||||
import { formatDisplayName, removeTrailingSellerId } from '../displayFormatters';
|
||||
|
||||
const clientTypeStyles: Record<string, string> = {
|
||||
'Sem análise': 'border-zinc-600/30 bg-zinc-600/15 text-zinc-300',
|
||||
@@ -318,8 +319,7 @@ const Clients = () => {
|
||||
};
|
||||
|
||||
const getSellerOptionLabel = (seller: ClientFilterOptions['sellers'][number]) => {
|
||||
if (seller.id && seller.name && seller.id !== seller.name) return `${seller.name} (${seller.id})`;
|
||||
return seller.name || seller.id;
|
||||
return formatDisplayName(removeTrailingSellerId(seller.name || seller.id));
|
||||
};
|
||||
|
||||
const marketplaceOptions = useMemo(() => {
|
||||
|
||||
Reference in New Issue
Block a user