eletrotupi / tcc/ commit / 40e7d68

frontend: generate badge's variants instead of custom colors

Pedro Lucas Porcellis porcellis@eletrotupi.com · 5 months ago 40e7d6808dc6d3a3623b2019857817f0f78a1ef3 Browse files
Parents f630302
Changed files
1
Additions
+5
Deletions
-5
frontend/lib/utils/time.ts
1 1
import { format, isToday, isYesterday } from 'date-fns';
2 2
import { ptBR } from 'date-fns/locale';
3 3

4 4
type TimeBadgeVariant = 'morning' | 'afternoon' | 'night' | 'latenight';
5 5

6 -
export const TIME_BADGES: Record<TimeBadgeVariant, { label: string; backgroundColor: string; color: string }> = {
7 -
  morning:   { label: 'Manhã',     backgroundColor: '#dcfce7', color: '#16a34a' },
8 -
  afternoon: { label: 'Tarde',     backgroundColor: '#f1f5f9', color: '#475569' },
9 -
  night:     { label: 'Noite',     backgroundColor: '#dbeafe', color: '#1d4ed8' },
10 -
  latenight: { label: 'Madrugada', backgroundColor: '#f3e8ff', color: '#7e22ce' },
6 +
export const TIME_BADGES: Record<TimeBadgeVariant, { label: string; variant: string; }> = {
7 +
  morning:   { label: 'Manhã',     variant: "green" },
8 +
  afternoon: { label: 'Tarde',     variant: "orange" },
9 +
  night:     { label: 'Noite',     variant: "blue" },
10 +
  latenight: { label: 'Madrugada', variant: "purple" },
11 11
};
12 12

13 13
export const getTimeBadge = (date: Date) => {
14 14
  const h = date.getHours();
15 15
  if (h >= 6  && h < 12) return TIME_BADGES.morning;
21 21
export const formatMoment = (date: Date): string => {
22 22
  if (isToday(date))     return `Hoje às ${format(date, "HH'h'mm")}`;
23 23
  if (isYesterday(date)) return `Ontem às ${format(date, "HH'h'mm")}`;
24 24
  return format(date, "d 'de' MMM 'às' HH'h'mm", { locale: ptBR });
25 25
}