|
| 1 | +import type { ReactNode } from "react"; |
| 2 | +import { |
| 3 | + Dialog, |
| 4 | + DialogContent, |
| 5 | + DialogHeader, |
| 6 | + DialogTitle, |
| 7 | +} from "@/components/ui/dialog"; |
| 8 | +import { Badge } from "@/components/ui/badge"; |
| 9 | +import { Button } from "@/components/ui/button"; |
| 10 | +import type { Student } from "@/types/student"; |
| 11 | +import { formatBrazilianDate } from "@/utils/formatDate"; |
| 12 | +import { statusColors, statusLabels } from "@/types/student"; |
| 13 | + |
| 14 | +interface StudentInfoModalProps { |
| 15 | + open: boolean; |
| 16 | + onOpenChange: (open: boolean) => void; |
| 17 | + student: Student | null; |
| 18 | +} |
| 19 | + |
| 20 | +export function StudentInfoModal({ open, onOpenChange, student }: StudentInfoModalProps) { |
| 21 | + if (!student) return null; |
| 22 | + |
| 23 | + const extra = student.extra_data || {}; |
| 24 | + const source = extra.source || "Não identificado"; |
| 25 | + const paytData = extra.payt || {}; |
| 26 | + const utms = paytData.utms || {}; |
| 27 | + |
| 28 | + // Customer details (from direct customer object, payt nested customer, or fallback fields) |
| 29 | + const customer = extra.customer || paytData.customer || {}; |
| 30 | + const customerDoc = customer.doc || extra.doc || customer.cpf || customer.cnpj; |
| 31 | + const customerUrl = customer.url; |
| 32 | + const customerCode = customer.code || paytData.customer_code || extra.customer_code; |
| 33 | + |
| 34 | + // Transaction details |
| 35 | + const transactionId = paytData.transaction_id || extra.transaction_id; |
| 36 | + const paymentMethod = paytData.payment_method || extra.payment_method; |
| 37 | + const sellerId = paytData.seller_id; |
| 38 | + const chatwootContact = extra.chatwoot_contact_id; |
| 39 | + const chatwootConv = extra.chatwoot_conversation_id; |
| 40 | + |
| 41 | + // Filter out common keys for the additional data section |
| 42 | + const knownKeys = ["source", "full_name", "payt", "customer", "chatwoot_contact_id", "chatwoot_conversation_id", "transaction_id", "payment_method", "customer_code", "doc"]; |
| 43 | + const otherKeys = Object.keys(extra).filter(key => !knownKeys.includes(key)); |
| 44 | + |
| 45 | + return ( |
| 46 | + <Dialog open={open} onOpenChange={onOpenChange}> |
| 47 | + <DialogContent className="sm:max-w-md max-h-[85vh] overflow-y-auto p-4 gap-3"> |
| 48 | + <DialogHeader className="pb-2 border-b"> |
| 49 | + <DialogTitle className="flex items-center gap-1.5 text-base font-bold"> |
| 50 | + <i className="ri-information-line text-primary text-lg" /> |
| 51 | + Ficha do Aluno |
| 52 | + </DialogTitle> |
| 53 | + </DialogHeader> |
| 54 | + |
| 55 | + <div className="space-y-4 text-xs"> |
| 56 | + {/* Aluno Header */} |
| 57 | + <div className="flex items-center justify-between bg-muted/30 p-2.5 rounded-lg border"> |
| 58 | + <div className="min-w-0"> |
| 59 | + <h3 className="font-bold text-sm truncate text-foreground">{student.name}</h3> |
| 60 | + <p className="text-muted-foreground text-xs truncate">{student.email}</p> |
| 61 | + </div> |
| 62 | + <Badge variant="secondary" className={`text-[10px] py-0 px-1.5 font-medium ${statusColors[student.status]}`}> |
| 63 | + {statusLabels[student.status]} |
| 64 | + </Badge> |
| 65 | + </div> |
| 66 | + |
| 67 | + {/* Dados Pessoais / Cadastro */} |
| 68 | + <div className="space-y-1.5"> |
| 69 | + <h4 className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">Dados Pessoais & Contato</h4> |
| 70 | + <div className="grid grid-cols-2 gap-x-4 gap-y-1.5 bg-muted/10 p-2.5 rounded-lg border"> |
| 71 | + <DataRow label="Telefone" value={student.phone || customer.phone || "Não informado"} /> |
| 72 | + <DataRow label="CPF/CNPJ" value={customerDoc || "Não informado"} /> |
| 73 | + <DataRow label="Cadastro" value={formatBrazilianDate(student.createdAt)} /> |
| 74 | + <DataRow |
| 75 | + label="Origem" |
| 76 | + value={ |
| 77 | + <span className="capitalize font-semibold text-primary"> |
| 78 | + {source} |
| 79 | + </span> |
| 80 | + } |
| 81 | + /> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + |
| 85 | + {/* Dados de Venda / Checkout */} |
| 86 | + {(transactionId || customerCode || sellerId || paymentMethod || customerUrl) && ( |
| 87 | + <div className="space-y-1.5"> |
| 88 | + <div className="flex justify-between items-center"> |
| 89 | + <h4 className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">Informações da Venda</h4> |
| 90 | + {customerUrl && ( |
| 91 | + <a |
| 92 | + href={customerUrl} |
| 93 | + target="_blank" |
| 94 | + rel="noopener noreferrer" |
| 95 | + className="text-[10px] text-primary hover:underline flex items-center gap-0.5" |
| 96 | + > |
| 97 | + Ver na plataforma <i className="ri-external-link-line text-[9px]" /> |
| 98 | + </a> |
| 99 | + )} |
| 100 | + </div> |
| 101 | + <div className="grid grid-cols-1 gap-y-1.5 bg-muted/10 p-2.5 rounded-lg border"> |
| 102 | + {transactionId && <DataRow label="ID Transação" value={transactionId} isMono />} |
| 103 | + {customerCode && <DataRow label="Cód. Cliente" value={customerCode} isMono />} |
| 104 | + {sellerId && <DataRow label="ID Seller" value={sellerId} isMono />} |
| 105 | + {paymentMethod && <DataRow label="Método Pgto" value={paymentMethod} className="capitalize" />} |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + )} |
| 109 | + |
| 110 | + {/* UTMs */} |
| 111 | + {Object.values(utms).some(val => val) && ( |
| 112 | + <div className="space-y-1.5"> |
| 113 | + <h4 className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">Parâmetros de Campanha (UTM)</h4> |
| 114 | + <div className="grid grid-cols-2 gap-1 bg-muted/10 p-2 rounded-lg border"> |
| 115 | + {Object.entries(utms).map(([key, val]) => { |
| 116 | + if (!val) return null; |
| 117 | + return ( |
| 118 | + <div key={key} className="flex justify-between items-center py-0.5 border-b border-dashed border-muted last:border-0"> |
| 119 | + <span className="text-muted-foreground text-[10px] uppercase font-mono">{key}:</span> |
| 120 | + <span className="font-semibold text-foreground truncate max-w-[120px]" title={String(val)}> |
| 121 | + {renderValue(val)} |
| 122 | + </span> |
| 123 | + </div> |
| 124 | + ); |
| 125 | + })} |
| 126 | + </div> |
| 127 | + </div> |
| 128 | + )} |
| 129 | + |
| 130 | + {/* Integrações */} |
| 131 | + {(chatwootContact || chatwootConv) && ( |
| 132 | + <div className="space-y-1.5"> |
| 133 | + <h4 className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">Integrações de Chat</h4> |
| 134 | + <div className="grid grid-cols-2 gap-x-4 gap-y-1.5 bg-muted/10 p-2.5 rounded-lg border"> |
| 135 | + {chatwootContact && <DataRow label="Chatwoot Contato" value={chatwootContact} isMono />} |
| 136 | + {chatwootConv && <DataRow label="Chatwoot Conversa" value={chatwootConv} isMono />} |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + )} |
| 140 | + |
| 141 | + {/* Dados Adicionais Raw JSON */} |
| 142 | + {otherKeys.length > 0 && ( |
| 143 | + <div className="space-y-1"> |
| 144 | + <h4 className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">Outros Metadados</h4> |
| 145 | + <pre className="text-[10px] font-mono bg-muted/40 p-2 rounded border overflow-x-auto max-h-[100px] leading-tight"> |
| 146 | + {JSON.stringify( |
| 147 | + otherKeys.reduce((acc, key) => ({ ...acc, [key]: extra[key] }), {}), |
| 148 | + null, |
| 149 | + 2 |
| 150 | + )} |
| 151 | + </pre> |
| 152 | + </div> |
| 153 | + )} |
| 154 | + |
| 155 | + {/* Close Action */} |
| 156 | + <div className="flex justify-end pt-1"> |
| 157 | + <Button variant="outline" size="sm" onClick={() => onOpenChange(false)} className="w-full sm:w-auto h-8 text-xs"> |
| 158 | + Fechar |
| 159 | + </Button> |
| 160 | + </div> |
| 161 | + </div> |
| 162 | + </DialogContent> |
| 163 | + </Dialog> |
| 164 | + ); |
| 165 | +} |
| 166 | + |
| 167 | +function renderValue(val: any): ReactNode { |
| 168 | + if (typeof val === "string" && (val.startsWith("http://") || val.startsWith("https://"))) { |
| 169 | + return ( |
| 170 | + <a |
| 171 | + href={val} |
| 172 | + target="_blank" |
| 173 | + rel="noopener noreferrer" |
| 174 | + className="text-primary hover:underline inline-flex items-center gap-0.5 font-semibold" |
| 175 | + title={val} |
| 176 | + > |
| 177 | + Link <i className="ri-external-link-line text-[10px]" /> |
| 178 | + </a> |
| 179 | + ); |
| 180 | + } |
| 181 | + return val; |
| 182 | +} |
| 183 | + |
| 184 | +interface DataRowProps { |
| 185 | + label: string; |
| 186 | + value: ReactNode; |
| 187 | + isMono?: boolean; |
| 188 | + className?: string; |
| 189 | +} |
| 190 | + |
| 191 | +function DataRow({ label, value, isMono = false, className = "" }: DataRowProps) { |
| 192 | + return ( |
| 193 | + <div className="flex justify-between items-center py-0.5 border-b border-dashed border-muted last:border-0 min-w-0"> |
| 194 | + <span className="text-muted-foreground shrink-0 pr-2">{label}:</span> |
| 195 | + <span className={`font-medium text-foreground truncate max-w-[200px] ${isMono ? "font-mono text-[11px]" : ""} ${className}`} title={typeof value === 'string' ? value : undefined}> |
| 196 | + {renderValue(value)} |
| 197 | + </span> |
| 198 | + </div> |
| 199 | + ); |
| 200 | +} |
0 commit comments