🚀 Initial commit: Versão atual do TrackSteel APP
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { useAtribuicoes } from '@/hooks/useAtribuicoes';
|
||||
|
||||
interface AtribuicaoEditModalProps {
|
||||
atribuicao: any;
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function AtribuicaoEditModal({ atribuicao, isOpen, onClose }: AtribuicaoEditModalProps) {
|
||||
const { updateAtribuicao, updateUserAbbrev, canManage } = useAtribuicoes();
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
user_abbrev: '',
|
||||
attribution: '',
|
||||
frequency: '',
|
||||
method: '',
|
||||
client: '',
|
||||
importance: '',
|
||||
duration: ''
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (atribuicao) {
|
||||
setFormData({
|
||||
user_abbrev: atribuicao.user_abbrev || '',
|
||||
attribution: atribuicao.attribution || '',
|
||||
frequency: atribuicao.frequency || '',
|
||||
method: atribuicao.method || '',
|
||||
client: atribuicao.client || '',
|
||||
importance: atribuicao.importance || '',
|
||||
duration: atribuicao.duration || ''
|
||||
});
|
||||
}
|
||||
}, [atribuicao]);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!atribuicao) return;
|
||||
|
||||
// Atualizar identificação se mudou
|
||||
if (formData.user_abbrev !== atribuicao.user_abbrev) {
|
||||
await updateUserAbbrev(atribuicao.user_id, formData.user_abbrev);
|
||||
}
|
||||
|
||||
// Atualizar atribuição
|
||||
await updateAtribuicao(atribuicao.id, {
|
||||
attribution: formData.attribution,
|
||||
frequency: formData.frequency as any,
|
||||
method: formData.method as any,
|
||||
client: formData.client as any,
|
||||
importance: formData.importance as any,
|
||||
duration: formData.duration as any
|
||||
});
|
||||
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Editar Atribuição</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Usuário</Label>
|
||||
<Input value={atribuicao?.user_name || ''} disabled />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Identificação (3 letras)</Label>
|
||||
<Input
|
||||
value={formData.user_abbrev}
|
||||
onChange={(e) => setFormData({ ...formData, user_abbrev: e.target.value.toUpperCase().substring(0, 3) })}
|
||||
maxLength={3}
|
||||
disabled={!canManage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Atribuição</Label>
|
||||
<Textarea
|
||||
value={formData.attribution}
|
||||
onChange={(e) => setFormData({ ...formData, attribution: e.target.value })}
|
||||
maxLength={300}
|
||||
disabled={!canManage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label>Frequência</Label>
|
||||
<Select
|
||||
value={formData.frequency}
|
||||
onValueChange={(value) => setFormData({ ...formData, frequency: value })}
|
||||
disabled={!canManage}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="horaria">Horária</SelectItem>
|
||||
<SelectItem value="2xdia">2x ao dia</SelectItem>
|
||||
<SelectItem value="diaria">Diária</SelectItem>
|
||||
<SelectItem value="2xsemanal">2x semanal</SelectItem>
|
||||
<SelectItem value="semanal">Semanal</SelectItem>
|
||||
<SelectItem value="quinzenal">Quinzenal</SelectItem>
|
||||
<SelectItem value="mensal">Mensal</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Método</Label>
|
||||
<Select
|
||||
value={formData.method}
|
||||
onValueChange={(value) => setFormData({ ...formData, method: value })}
|
||||
disabled={!canManage}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="impresso">Impresso</SelectItem>
|
||||
<SelectItem value="sistema">Sistema</SelectItem>
|
||||
<SelectItem value="sistema-impresso">Sistema/Impresso</SelectItem>
|
||||
<SelectItem value="email">E-mail</SelectItem>
|
||||
<SelectItem value="verbal">Verbal</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Cliente</Label>
|
||||
<Select
|
||||
value={formData.client}
|
||||
onValueChange={(value) => setFormData({ ...formData, client: value })}
|
||||
disabled={!canManage}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="interno">Interno</SelectItem>
|
||||
<SelectItem value="processo">Processo</SelectItem>
|
||||
<SelectItem value="obra">Obra</SelectItem>
|
||||
<SelectItem value="contrato">Contrato</SelectItem>
|
||||
<SelectItem value="geral">Geral</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Grau de Importância</Label>
|
||||
<Select
|
||||
value={formData.importance}
|
||||
onValueChange={(value) => setFormData({ ...formData, importance: value })}
|
||||
disabled={!canManage}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="essencial">Essencial</SelectItem>
|
||||
<SelectItem value="estrategico">Estratégico</SelectItem>
|
||||
<SelectItem value="suporte">Suporte</SelectItem>
|
||||
<SelectItem value="informativo">Informativo</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Duração</Label>
|
||||
<Select
|
||||
value={formData.duration}
|
||||
onValueChange={(value) => setFormData({ ...formData, duration: value })}
|
||||
disabled={!canManage}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="<=1 hora">≤ 1 hora</SelectItem>
|
||||
<SelectItem value="2 horas">2 horas</SelectItem>
|
||||
<SelectItem value="4 horas">4 horas</SelectItem>
|
||||
<SelectItem value="8 horas">8 horas</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4 justify-end pt-4">
|
||||
<Button variant="outline" onClick={onClose}>
|
||||
Cancelar
|
||||
</Button>
|
||||
{canManage && (
|
||||
<Button onClick={handleSave}>
|
||||
Salvar Alterações
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { useAtribuicoes } from '@/hooks/useAtribuicoes';
|
||||
import { useMobileResponsive } from '@/hooks/useMobileResponsive';
|
||||
import { Trash2 } from 'lucide-react';
|
||||
|
||||
interface AtribuicaoTemp {
|
||||
attribution: string;
|
||||
frequency: string;
|
||||
method: string;
|
||||
client: string;
|
||||
importance: string;
|
||||
duration: string;
|
||||
}
|
||||
|
||||
export function AtribuicoesForm() {
|
||||
const { users, createAtribuicao, canManage } = useAtribuicoes();
|
||||
const { isMobile } = useMobileResponsive();
|
||||
|
||||
const [selectedUserId, setSelectedUserId] = useState('');
|
||||
const [userAbbrev, setUserAbbrev] = useState('');
|
||||
const [atribuicoes, setAtribuicoes] = useState<AtribuicaoTemp[]>([]);
|
||||
|
||||
// Form state
|
||||
const [formData, setFormData] = useState({
|
||||
attribution: '',
|
||||
frequency: '',
|
||||
method: '',
|
||||
client: '',
|
||||
importance: '',
|
||||
duration: ''
|
||||
});
|
||||
|
||||
const selectedUser = users.find(u => u.id === selectedUserId);
|
||||
|
||||
// Gerar abreviação automática quando usuário é selecionado
|
||||
useEffect(() => {
|
||||
if (selectedUser && !userAbbrev) {
|
||||
const names = selectedUser.full_name?.split(' ') || [];
|
||||
let abbrev = '';
|
||||
|
||||
if (names.length >= 2) {
|
||||
abbrev = names[0].charAt(0) + names[1].charAt(0) + names[0].charAt(1);
|
||||
} else if (names.length === 1) {
|
||||
abbrev = names[0].substring(0, 3);
|
||||
}
|
||||
|
||||
setUserAbbrev(abbrev.toUpperCase());
|
||||
}
|
||||
}, [selectedUser, userAbbrev]);
|
||||
|
||||
const handleAddAtribuicao = () => {
|
||||
if (!formData.attribution || !formData.frequency || !formData.method ||
|
||||
!formData.client || !formData.importance || !formData.duration) {
|
||||
return;
|
||||
}
|
||||
|
||||
setAtribuicoes([...atribuicoes, { ...formData }]);
|
||||
setFormData({
|
||||
attribution: '',
|
||||
frequency: '',
|
||||
method: '',
|
||||
client: '',
|
||||
importance: '',
|
||||
duration: ''
|
||||
});
|
||||
};
|
||||
|
||||
const handleRemoveAtribuicao = (index: number) => {
|
||||
setAtribuicoes(atribuicoes.filter((_, i) => i !== index));
|
||||
};
|
||||
|
||||
const handleSaveAll = async () => {
|
||||
if (!selectedUserId || !userAbbrev || atribuicoes.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const attr of atribuicoes) {
|
||||
await createAtribuicao({
|
||||
user_id: selectedUserId,
|
||||
user_abbrev: userAbbrev,
|
||||
attribution: attr.attribution,
|
||||
frequency: attr.frequency as any,
|
||||
method: attr.method as any,
|
||||
client: attr.client as any,
|
||||
importance: attr.importance as any,
|
||||
duration: attr.duration as any
|
||||
});
|
||||
}
|
||||
|
||||
// Reset form
|
||||
setSelectedUserId('');
|
||||
setUserAbbrev('');
|
||||
setAtribuicoes([]);
|
||||
};
|
||||
|
||||
if (!canManage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Formulário de Cadastro */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Adicionar Atribuição</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
{/* Seleção de Usuário */}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<Label>Selecionar Usuário</Label>
|
||||
<Select value={selectedUserId} onValueChange={(value) => {
|
||||
setSelectedUserId(value);
|
||||
setUserAbbrev('');
|
||||
setAtribuicoes([]);
|
||||
}}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="-- Selecione um usuário --" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{users.map((user) => (
|
||||
<SelectItem key={user.id} value={user.id}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Avatar className="h-6 w-6">
|
||||
<AvatarImage src={user.profile_image_url} />
|
||||
<AvatarFallback className="text-xs">
|
||||
{user.full_name?.charAt(0) || 'U'}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<span>{user.full_name} ({user.email})</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{selectedUser && (
|
||||
<div>
|
||||
<Label>Identificação (3 letras)</Label>
|
||||
<Input
|
||||
value={userAbbrev}
|
||||
onChange={(e) => setUserAbbrev(e.target.value.toUpperCase().substring(0, 3))}
|
||||
placeholder="Ex: JOS"
|
||||
maxLength={3}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{selectedUserId && (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div className="col-span-full">
|
||||
<Label>Atribuição</Label>
|
||||
<Textarea
|
||||
value={formData.attribution}
|
||||
onChange={(e) => setFormData({ ...formData, attribution: e.target.value })}
|
||||
placeholder="Descrição da atribuição..."
|
||||
maxLength={300}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Frequência</Label>
|
||||
<Select value={formData.frequency} onValueChange={(value) => setFormData({ ...formData, frequency: value })}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Selecione..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="horaria">Horária</SelectItem>
|
||||
<SelectItem value="2xdia">2x ao dia</SelectItem>
|
||||
<SelectItem value="diaria">Diária</SelectItem>
|
||||
<SelectItem value="2xsemanal">2x semanal</SelectItem>
|
||||
<SelectItem value="semanal">Semanal</SelectItem>
|
||||
<SelectItem value="quinzenal">Quinzenal</SelectItem>
|
||||
<SelectItem value="mensal">Mensal</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Método</Label>
|
||||
<Select value={formData.method} onValueChange={(value) => setFormData({ ...formData, method: value })}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Selecione..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="impresso">Impresso</SelectItem>
|
||||
<SelectItem value="sistema">Sistema</SelectItem>
|
||||
<SelectItem value="sistema-impresso">Sistema/Impresso</SelectItem>
|
||||
<SelectItem value="email">E-mail</SelectItem>
|
||||
<SelectItem value="verbal">Verbal</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Cliente</Label>
|
||||
<Select value={formData.client} onValueChange={(value) => setFormData({ ...formData, client: value })}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Selecione..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="interno">Interno</SelectItem>
|
||||
<SelectItem value="processo">Processo</SelectItem>
|
||||
<SelectItem value="obra">Obra</SelectItem>
|
||||
<SelectItem value="contrato">Contrato</SelectItem>
|
||||
<SelectItem value="geral">Geral</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Grau de Importância</Label>
|
||||
<Select value={formData.importance} onValueChange={(value) => setFormData({ ...formData, importance: value })}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Selecione..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="essencial">Essencial</SelectItem>
|
||||
<SelectItem value="estrategico">Estratégico</SelectItem>
|
||||
<SelectItem value="suporte">Suporte</SelectItem>
|
||||
<SelectItem value="informativo">Informativo</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Label>Duração</Label>
|
||||
<Select value={formData.duration} onValueChange={(value) => setFormData({ ...formData, duration: value })}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Selecione..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="<=1 hora">≤ 1 hora</SelectItem>
|
||||
<SelectItem value="2 horas">2 horas</SelectItem>
|
||||
<SelectItem value="4 horas">4 horas</SelectItem>
|
||||
<SelectItem value="8 horas">8 horas</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selectedUserId && (
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={handleAddAtribuicao} disabled={!formData.attribution || !formData.frequency}>
|
||||
Adicionar Atribuição
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Lista de Atribuições Temporárias */}
|
||||
{atribuicoes.length > 0 && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex justify-between items-center">
|
||||
<CardTitle>
|
||||
Atribuições para {selectedUser?.full_name}
|
||||
</CardTitle>
|
||||
<Button onClick={handleSaveAll} variant="default">
|
||||
Salvar Todas Atribuições
|
||||
</Button>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
{atribuicoes.map((attr, index) => (
|
||||
<div key={index} className="flex justify-between items-start p-4 border rounded-lg">
|
||||
<div className="flex-1 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-6 gap-2 text-sm">
|
||||
<div>
|
||||
<strong>Atribuição:</strong>
|
||||
<p className="break-words">{attr.attribution}</p>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Frequência:</strong>
|
||||
<p>{attr.frequency}</p>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Método:</strong>
|
||||
<p>{attr.method}</p>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Cliente:</strong>
|
||||
<p>{attr.client}</p>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Importância:</strong>
|
||||
<p>{attr.importance}</p>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Duração:</strong>
|
||||
<p>{attr.duration}</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => handleRemoveAtribuicao(index)}
|
||||
className="text-red-600 hover:text-red-700 ml-2"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Printer } from 'lucide-react';
|
||||
import { Atribuicao } from '@/hooks/useAtribuicoes';
|
||||
import { format } from 'date-fns';
|
||||
import { ptBR } from 'date-fns/locale';
|
||||
|
||||
interface AtribuicoesPrintModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
atribuicoes: Atribuicao[];
|
||||
}
|
||||
|
||||
export function AtribuicoesPrintModal({ isOpen, onClose, atribuicoes }: AtribuicoesPrintModalProps) {
|
||||
const [selectedUserId, setSelectedUserId] = useState<string>('');
|
||||
|
||||
// Obter lista única de usuários
|
||||
const uniqueUsers = Array.from(
|
||||
new Map(atribuicoes.map(attr => [attr.user_id, { id: attr.user_id, name: attr.user_name }]))
|
||||
.values()
|
||||
);
|
||||
|
||||
const handlePrint = () => {
|
||||
if (!selectedUserId) return;
|
||||
|
||||
// Filtrar atribuições do usuário selecionado
|
||||
const userAtribuicoes = atribuicoes.filter(attr => attr.user_id === selectedUserId);
|
||||
const selectedUser = uniqueUsers.find(user => user.id === selectedUserId);
|
||||
|
||||
if (!selectedUser || userAtribuicoes.length === 0) return;
|
||||
|
||||
const getImportanceBadgeStyle = (importancia: string) => {
|
||||
switch (importancia) {
|
||||
case 'essencial':
|
||||
return 'bg-red-100 text-red-800';
|
||||
case 'estrategico':
|
||||
return 'bg-blue-100 text-blue-800';
|
||||
case 'suporte':
|
||||
return 'bg-gray-100 text-gray-800';
|
||||
case 'informativo':
|
||||
return 'bg-green-100 text-green-800';
|
||||
default:
|
||||
return 'bg-gray-100 text-gray-800';
|
||||
}
|
||||
};
|
||||
|
||||
const printContent = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Relatório de Atribuições</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
@media print {
|
||||
body {
|
||||
-webkit-print-color-adjust: exact;
|
||||
color-adjust: exact;
|
||||
}
|
||||
.print-container {
|
||||
box-shadow: none;
|
||||
margin: 0;
|
||||
max-width: 100%;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
.no-print {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-100 p-4 sm:p-6">
|
||||
<div class="print-container max-w-6xl mx-auto bg-white rounded-xl shadow-lg overflow-hidden">
|
||||
<header class="bg-gray-100 text-gray-800 p-4 md:p-5 border-b border-gray-200">
|
||||
<h1 class="text-xl md:text-2xl font-bold">Relatório de Atribuições de ${selectedUser.name}</h1>
|
||||
<p class="text-gray-600 text-sm">Lista de atribuições para o usuário selecionado.</p>
|
||||
</header>
|
||||
|
||||
<main class="p-4 md:p-6">
|
||||
<div class="overflow-x-auto rounded-lg border border-gray-200">
|
||||
<table class="min-w-full divide-y divide-gray-200 text-sm">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col" class="px-4 py-3 text-left text-xs font-bold text-gray-600 uppercase tracking-wider">Atribuição</th>
|
||||
<th scope="col" class="px-4 py-3 text-left text-xs font-bold text-gray-600 uppercase tracking-wider">Frequência</th>
|
||||
<th scope="col" class="px-4 py-3 text-left text-xs font-bold text-gray-600 uppercase tracking-wider">Método</th>
|
||||
<th scope="col" class="px-4 py-3 text-left text-xs font-bold text-gray-600 uppercase tracking-wider">Cliente</th>
|
||||
<th scope="col" class="px-4 py-3 text-center text-xs font-bold text-gray-600 uppercase tracking-wider">Importância</th>
|
||||
<th scope="col" class="px-4 py-3 text-left text-xs font-bold text-gray-600 uppercase tracking-wider">Duração</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
${userAtribuicoes.map((attr, index) => `
|
||||
<tr${index % 2 === 1 ? ' class="hover:bg-gray-50"' : ''}>
|
||||
<td class="px-4 py-3 align-top text-gray-700" style="white-space: normal;">${attr.attribution}</td>
|
||||
<td class="px-4 py-3 align-top whitespace-nowrap text-gray-700">${attr.frequency}</td>
|
||||
<td class="px-4 py-3 align-top whitespace-nowrap text-gray-700">${attr.method}</td>
|
||||
<td class="px-4 py-3 align-top whitespace-nowrap text-gray-700">${attr.client}</td>
|
||||
<td class="px-4 py-3 align-top whitespace-nowrap text-center">
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getImportanceBadgeStyle(attr.importance)}">
|
||||
${attr.importance}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-4 py-3 align-top whitespace-nowrap text-gray-700">${attr.duration}</td>
|
||||
</tr>
|
||||
`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="text-center text-xs text-gray-400 p-3 bg-gray-50 border-t">
|
||||
<p>Relatório gerado em: ${format(new Date(), 'dd/MM/yyyy', { locale: ptBR })}</p>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
const printWindow = window.open('', '_blank');
|
||||
if (!printWindow) return;
|
||||
|
||||
printWindow.document.write(printContent);
|
||||
printWindow.document.close();
|
||||
|
||||
printWindow.onload = () => {
|
||||
setTimeout(() => {
|
||||
printWindow.print();
|
||||
printWindow.close();
|
||||
}, 500);
|
||||
};
|
||||
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Printer className="h-5 w-5" />
|
||||
Imprimir Atribuições
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Selecionar Usuário:</label>
|
||||
<Select value={selectedUserId} onValueChange={setSelectedUserId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Escolha um usuário..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{uniqueUsers.map((user) => (
|
||||
<SelectItem key={user.id} value={user.id}>
|
||||
{user.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end gap-2 pt-4">
|
||||
<Button variant="outline" onClick={onClose}>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handlePrint}
|
||||
disabled={!selectedUserId}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<Printer className="h-4 w-4" />
|
||||
Imprimir
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { ResponsiveTable } from '@/components/responsive/ResponsiveTable';
|
||||
import { TableCell } from '@/components/ui/table';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { useAtribuicoes } from '@/hooks/useAtribuicoes';
|
||||
import { useMobileResponsive } from '@/hooks/useMobileResponsive';
|
||||
import { Edit, Trash2, Search, AlertCircle, Printer } from 'lucide-react';
|
||||
import { AtribuicaoEditModal } from './AtribuicaoEditModal';
|
||||
import { AtribuicoesPrintModal } from './AtribuicoesPrintModal';
|
||||
|
||||
export function AtribuicoesTable() {
|
||||
const { atribuicoes, canManage, deleteAtribuicao, loading } = useAtribuicoes();
|
||||
const { isMobile } = useMobileResponsive();
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [editingAtribuicao, setEditingAtribuicao] = useState<any>(null);
|
||||
const [showPrintModal, setShowPrintModal] = useState(false);
|
||||
|
||||
const filteredAtribuicoes = atribuicoes.filter(attr =>
|
||||
attr.user_name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
attr.attribution.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
attr.user_abbrev.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
|
||||
console.log('📊 AtribuicoesTable render:', {
|
||||
atribuicoesTotal: atribuicoes.length,
|
||||
filteredCount: filteredAtribuicoes.length,
|
||||
loading,
|
||||
searchTerm
|
||||
});
|
||||
|
||||
const getImportanceBadgeColor = (importancia: string) => {
|
||||
switch (importancia) {
|
||||
case 'essencial': return 'destructive';
|
||||
case 'estrategico': return 'default';
|
||||
case 'suporte': return 'secondary';
|
||||
case 'informativo': return 'outline';
|
||||
default: return 'outline';
|
||||
}
|
||||
};
|
||||
|
||||
const headers = [
|
||||
'Usuário',
|
||||
'ID',
|
||||
'Atribuição',
|
||||
'Frequência',
|
||||
'Método',
|
||||
'Cliente',
|
||||
'Importância',
|
||||
'Duração',
|
||||
...(canManage ? ['Ações'] : [])
|
||||
];
|
||||
|
||||
const renderRow = (attr: any, index: number) => (
|
||||
<>
|
||||
{/* Coluna Usuário - 18% da largura */}
|
||||
<TableCell className="w-[18%] min-w-[180px] p-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<Avatar className="h-10 w-10 flex-shrink-0">
|
||||
<AvatarImage src={attr.user_photo} />
|
||||
<AvatarFallback className="text-sm font-medium">
|
||||
{attr.user_name.charAt(0)}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="font-medium text-sm truncate">{attr.user_name}</p>
|
||||
<p className="text-xs text-muted-foreground truncate">{attr.user_email}</p>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna ID - 4% da largura */}
|
||||
<TableCell className="w-[4%] min-w-[50px] p-3">
|
||||
<Badge variant="outline" className="text-xs font-medium">{attr.user_abbrev}</Badge>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna Atribuição - 35% da largura com fonte menor */}
|
||||
<TableCell className="w-[35%] min-w-[350px] p-3">
|
||||
<div className="assignment-cell text-xs leading-relaxed max-h-[4.5rem] overflow-hidden">
|
||||
<p className="break-words whitespace-normal line-clamp-4" title={attr.attribution}>
|
||||
{attr.attribution}
|
||||
</p>
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna Frequência - 7% da largura, centralizada */}
|
||||
<TableCell className="w-[7%] min-w-[70px] p-3 text-center">
|
||||
<span className="text-sm text-muted-foreground">{attr.frequency}</span>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna Método - 7% da largura */}
|
||||
<TableCell className="w-[7%] min-w-[70px] p-3">
|
||||
<span className="text-sm text-muted-foreground">{attr.method}</span>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna Cliente - 7% da largura */}
|
||||
<TableCell className="w-[7%] min-w-[70px] p-3">
|
||||
<span className="text-sm text-muted-foreground">{attr.client}</span>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna Importância - 9% da largura, centralizada */}
|
||||
<TableCell className="w-[9%] min-w-[90px] p-3 text-center">
|
||||
<Badge
|
||||
variant={getImportanceBadgeColor(attr.importance)}
|
||||
className="importance-tag text-xs px-2 py-1 rounded-full whitespace-nowrap"
|
||||
>
|
||||
{attr.importance}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna Duração - 7% da largura, centralizada */}
|
||||
<TableCell className="w-[7%] min-w-[70px] p-3 text-center">
|
||||
<span className="text-sm text-muted-foreground">{attr.duration}</span>
|
||||
</TableCell>
|
||||
|
||||
{/* Coluna Ações - 6% da largura, centralizada */}
|
||||
{canManage && (
|
||||
<TableCell className="w-[6%] min-w-[80px] p-3 text-center">
|
||||
<div className="flex items-center justify-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setEditingAtribuicao(attr)}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<Edit className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (confirm('Tem certeza que deseja excluir esta atribuição?')) {
|
||||
deleteAtribuicao(attr.id);
|
||||
}
|
||||
}}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-red-500 transition-colors"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
const renderMobileCard = (attr: any) => (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Avatar className="h-8 w-8">
|
||||
<AvatarImage src={attr.user_photo} />
|
||||
<AvatarFallback className="text-xs">
|
||||
{attr.user_name.charAt(0)}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div>
|
||||
<p className="font-medium text-sm">{attr.user_name}</p>
|
||||
<Badge variant="outline" className="text-xs">{attr.user_abbrev}</Badge>
|
||||
</div>
|
||||
</div>
|
||||
<Badge variant={getImportanceBadgeColor(attr.importance)}>
|
||||
{attr.importance}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-sm font-medium">Atribuição:</p>
|
||||
<p className="text-sm text-muted-foreground">{attr.attribution}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-2 text-xs">
|
||||
<div>
|
||||
<span className="font-medium">Frequência:</span> {attr.frequency}
|
||||
</div>
|
||||
<div>
|
||||
<span className="font-medium">Método:</span> {attr.method}
|
||||
</div>
|
||||
<div>
|
||||
<span className="font-medium">Cliente:</span> {attr.client}
|
||||
</div>
|
||||
<div>
|
||||
<span className="font-medium">Duração:</span> {attr.duration}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{canManage && (
|
||||
<div className="flex gap-2 pt-2 border-t">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setEditingAtribuicao(attr)}
|
||||
className="flex-1"
|
||||
>
|
||||
<Edit className="h-4 w-4 mr-1" />
|
||||
Editar
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
if (confirm('Tem certeza que deseja excluir esta atribuição?')) {
|
||||
deleteAtribuicao(attr.id);
|
||||
}
|
||||
}}
|
||||
className="flex-1 text-red-600 hover:text-red-700"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-1" />
|
||||
Excluir
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>
|
||||
{canManage ? 'Todas as Atribuições' : 'Minhas Atribuições'}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center justify-center p-8">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
||||
<span className="ml-2">Carregando atribuições...</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between">
|
||||
<CardTitle>
|
||||
{canManage ? 'Todas as Atribuições' : 'Minhas Atribuições'}
|
||||
{atribuicoes.length > 0 && (
|
||||
<span className="text-sm font-normal text-muted-foreground ml-2">
|
||||
({atribuicoes.length} {atribuicoes.length === 1 ? 'atribuição' : 'atribuições'})
|
||||
</span>
|
||||
)}
|
||||
</CardTitle>
|
||||
<div className="flex flex-col sm:flex-row gap-2 w-full sm:w-auto">
|
||||
{atribuicoes.length > 0 && (
|
||||
<>
|
||||
<Button
|
||||
onClick={() => setShowPrintModal(true)}
|
||||
variant="outline"
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<Printer className="h-4 w-4" />
|
||||
Imprimir
|
||||
</Button>
|
||||
<div className="relative w-full sm:w-auto">
|
||||
<Search className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Buscar por usuário, atribuição ou ID..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="pl-9 w-full sm:w-80"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{atribuicoes.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center p-8 text-center">
|
||||
<AlertCircle className="h-12 w-12 text-muted-foreground mb-4" />
|
||||
<h3 className="text-lg font-semibold mb-2">Nenhuma atribuição encontrada</h3>
|
||||
<p className="text-muted-foreground mb-4">
|
||||
Ainda não há atribuições cadastradas no sistema.
|
||||
</p>
|
||||
{canManage && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Use a aba "Cadastro" para criar a primeira atribuição.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<ResponsiveTable
|
||||
headers={headers}
|
||||
data={filteredAtribuicoes}
|
||||
renderRow={renderRow}
|
||||
renderMobileCard={renderMobileCard}
|
||||
emptyMessage={
|
||||
filteredAtribuicoes.length === 0 && searchTerm
|
||||
? `Nenhuma atribuição encontrada para "${searchTerm}"`
|
||||
: "Nenhuma atribuição encontrada"
|
||||
}
|
||||
loading={false}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{editingAtribuicao && (
|
||||
<AtribuicaoEditModal
|
||||
atribuicao={editingAtribuicao}
|
||||
isOpen={!!editingAtribuicao}
|
||||
onClose={() => setEditingAtribuicao(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<AtribuicoesPrintModal
|
||||
isOpen={showPrintModal}
|
||||
onClose={() => setShowPrintModal(false)}
|
||||
atribuicoes={filteredAtribuicoes}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user