modulo usuarios
This commit is contained in:
@@ -331,7 +331,7 @@ function DashboardPage({ user, setUser }) {
|
||||
onStartInspection={setActiveInspection}
|
||||
/>
|
||||
) : activeTab === 'inspections' ? (
|
||||
<InspectionsTab inspections={inspections} user={user} />
|
||||
<InspectionsTab inspections={inspections} user={user} onUpdate={loadData} />
|
||||
) : activeTab === 'settings' ? (
|
||||
<SettingsTab user={user} />
|
||||
) : activeTab === 'users' ? (
|
||||
@@ -996,17 +996,25 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
{user.role === 'admin' && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setSelectedChecklist(checklist)
|
||||
setShowQuestionsModal(true)
|
||||
}}
|
||||
className="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition"
|
||||
>
|
||||
Gestionar Preguntas
|
||||
</button>
|
||||
<>
|
||||
<button
|
||||
onClick={() => {
|
||||
setSelectedChecklist(checklist)
|
||||
setShowQuestionsModal(true)
|
||||
}}
|
||||
className="px-4 py-2 bg-gradient-to-r from-purple-600 to-indigo-600 text-white rounded-lg hover:from-purple-700 hover:to-indigo-700 transition-all transform hover:scale-105 shadow-lg"
|
||||
>
|
||||
Gestionar Preguntas
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onStartInspection(checklist)}
|
||||
className="px-4 py-2 bg-gradient-to-r from-green-500 to-emerald-500 text-white rounded-lg hover:from-green-600 hover:to-emerald-600 transition-all transform hover:scale-105 shadow-lg"
|
||||
>
|
||||
Nueva Inspección
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{user.role === 'mechanic' && (
|
||||
{(user.role === 'mechanic' || user.role === 'mecanico') && (
|
||||
<button
|
||||
onClick={() => onStartInspection(checklist)}
|
||||
className="px-4 py-2 bg-gradient-to-r from-green-500 to-emerald-500 text-white rounded-lg hover:from-green-600 hover:to-emerald-600 transition-all transform hover:scale-105 shadow-lg"
|
||||
@@ -1153,9 +1161,10 @@ function ChecklistsTab({ checklists, user, onChecklistCreated, onStartInspection
|
||||
)
|
||||
}
|
||||
|
||||
function InspectionDetailModal({ inspection, onClose }) {
|
||||
function InspectionDetailModal({ inspection, user, onClose, onUpdate }) {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [inspectionDetail, setInspectionDetail] = useState(null)
|
||||
const [isInactivating, setIsInactivating] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const loadInspectionDetails = async () => {
|
||||
@@ -1419,19 +1428,55 @@ function InspectionDetailModal({ inspection, onClose }) {
|
||||
|
||||
{/* Footer */}
|
||||
<div className="border-t p-4 bg-gray-50">
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="w-full px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition"
|
||||
>
|
||||
Cerrar
|
||||
</button>
|
||||
<div className="flex gap-3">
|
||||
{user?.role === 'admin' && (
|
||||
<>
|
||||
<button
|
||||
onClick={async () => {
|
||||
if (confirm('¿Deseas inactivar esta inspección?')) {
|
||||
setIsInactivating(true)
|
||||
try {
|
||||
const token = localStorage.getItem('token')
|
||||
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||
const response = await fetch(`${API_URL}/api/inspections/${inspection.id}/deactivate`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
})
|
||||
if (response.ok) {
|
||||
alert('Inspección inactivada correctamente')
|
||||
onUpdate && onUpdate()
|
||||
onClose()
|
||||
} else {
|
||||
alert('Error al inactivar la inspección')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
alert('Error al inactivar la inspección')
|
||||
}
|
||||
setIsInactivating(false)
|
||||
}
|
||||
}}
|
||||
disabled={isInactivating}
|
||||
className="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition disabled:opacity-50"
|
||||
>
|
||||
{isInactivating ? 'Inactivando...' : 'Inactivar'}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="flex-1 px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition"
|
||||
>
|
||||
Cerrar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function InspectionsTab({ inspections, user }) {
|
||||
function InspectionsTab({ inspections, user, onUpdate }) {
|
||||
const [selectedInspection, setSelectedInspection] = useState(null)
|
||||
|
||||
if (inspections.length === 0) {
|
||||
@@ -1494,7 +1539,9 @@ function InspectionsTab({ inspections, user }) {
|
||||
{selectedInspection && (
|
||||
<InspectionDetailModal
|
||||
inspection={selectedInspection}
|
||||
user={user}
|
||||
onClose={() => setSelectedInspection(null)}
|
||||
onUpdate={onUpdate}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user