2025-09-15 21:29:07 +00:00
|
|
|
|
import React, { useState } from 'react'
|
|
|
|
|
|
import { FaTimes, FaSave, FaExclamationTriangle } from 'react-icons/fa'
|
|
|
|
|
|
import { PmWorkCenter, WorkCenterStatusEnum, CriticalityLevelEnum } from '../../../types/pm'
|
|
|
|
|
|
import { getCriticalityLevelText, getWorkCenterStatusText } from '../../../utils/erp'
|
2025-09-15 09:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
interface StatusUpdateModalProps {
|
2025-09-15 21:29:07 +00:00
|
|
|
|
isOpen: boolean
|
|
|
|
|
|
onClose: () => void
|
|
|
|
|
|
onSave: (updatedWorkCenters: PmWorkCenter[]) => void
|
|
|
|
|
|
selectedWorkCenters: PmWorkCenter[]
|
2025-09-15 09:31:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const StatusUpdateModal: React.FC<StatusUpdateModalProps> = ({
|
|
|
|
|
|
isOpen,
|
|
|
|
|
|
onClose,
|
|
|
|
|
|
onSave,
|
|
|
|
|
|
selectedWorkCenters,
|
|
|
|
|
|
}) => {
|
2025-09-15 21:29:07 +00:00
|
|
|
|
const [newStatus, setNewStatus] = useState<WorkCenterStatusEnum>(WorkCenterStatusEnum.Operational)
|
2025-09-15 09:31:47 +00:00
|
|
|
|
const [newCriticality, setNewCriticality] = useState<CriticalityLevelEnum>(
|
2025-09-15 21:29:07 +00:00
|
|
|
|
CriticalityLevelEnum.Medium,
|
|
|
|
|
|
)
|
|
|
|
|
|
const [updateStatus, setUpdateStatus] = useState(true)
|
|
|
|
|
|
const [updateCriticality, setUpdateCriticality] = useState(false)
|
|
|
|
|
|
const [reason, setReason] = useState('')
|
2025-09-15 09:31:47 +00:00
|
|
|
|
|
2025-09-15 21:29:07 +00:00
|
|
|
|
if (!isOpen) return null
|
2025-09-15 09:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
const handleSave = () => {
|
|
|
|
|
|
const updatedWorkCenters = selectedWorkCenters.map((workCenter) => ({
|
|
|
|
|
|
...workCenter,
|
|
|
|
|
|
status: updateStatus ? newStatus : workCenter.status,
|
|
|
|
|
|
criticality: updateCriticality ? newCriticality : workCenter.criticality,
|
|
|
|
|
|
lastModificationTime: new Date(),
|
2025-09-15 21:29:07 +00:00
|
|
|
|
}))
|
2025-09-15 09:31:47 +00:00
|
|
|
|
|
2025-09-15 21:29:07 +00:00
|
|
|
|
onSave(updatedWorkCenters)
|
|
|
|
|
|
onClose()
|
|
|
|
|
|
}
|
2025-09-15 09:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
const isStatusCritical =
|
|
|
|
|
|
newStatus === WorkCenterStatusEnum.OutOfOrder ||
|
2025-09-15 21:29:07 +00:00
|
|
|
|
newStatus === WorkCenterStatusEnum.UnderMaintenance
|
2025-09-15 09:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
|
|
|
|
|
<div className="bg-white rounded-lg w-full max-w-2xl mx-4 max-h-[90vh] overflow-y-auto">
|
|
|
|
|
|
{/* Header */}
|
|
|
|
|
|
<div className="flex items-center justify-between p-4 border-b border-gray-200">
|
|
|
|
|
|
<h2 className="text-lg font-semibold text-gray-900">
|
|
|
|
|
|
Durum Güncelle ({selectedWorkCenters.length} iş merkezi)
|
|
|
|
|
|
</h2>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<button onClick={onClose} className="p-1 hover:bg-gray-100 rounded-lg transition-colors">
|
2025-09-15 09:31:47 +00:00
|
|
|
|
<FaTimes className="w-4 h-4 text-gray-500" />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Content */}
|
|
|
|
|
|
<div className="p-4 space-y-4">
|
|
|
|
|
|
{/* Selected WorkCenter List */}
|
|
|
|
|
|
<div>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<h3 className="text-base font-medium text-gray-900 mb-2">Seçili İş Merkezleri</h3>
|
2025-09-15 09:31:47 +00:00
|
|
|
|
<div className="max-h-28 overflow-y-auto bg-gray-50 rounded-lg p-2">
|
|
|
|
|
|
{selectedWorkCenters.map((workCenter) => (
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<div key={workCenter.id} className="flex items-center justify-between py-0.5">
|
2025-09-15 09:31:47 +00:00
|
|
|
|
<span className="text-sm text-gray-700">
|
|
|
|
|
|
{workCenter.code} - {workCenter.name}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
|
|
<span className="text-xs text-gray-500">
|
|
|
|
|
|
Mevcut: {getWorkCenterStatusText(workCenter.status)}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span className="text-xs text-gray-500">
|
|
|
|
|
|
{getCriticalityLevelText(workCenter.criticality)}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Status Update Options */}
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
|
<div className="flex items-center space-x-3">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
id="updateStatus"
|
|
|
|
|
|
checked={updateStatus}
|
|
|
|
|
|
onChange={(e) => setUpdateStatus(e.target.checked)}
|
|
|
|
|
|
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
|
|
|
|
|
/>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<label htmlFor="updateStatus" className="text-sm font-medium text-gray-700">
|
2025-09-15 09:31:47 +00:00
|
|
|
|
Operasyonel durumu güncelle
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{updateStatus && (
|
|
|
|
|
|
<div>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<label className="block text-sm font-medium text-gray-700 mb-2">Yeni Durum</label>
|
2025-09-15 09:31:47 +00:00
|
|
|
|
<select
|
|
|
|
|
|
value={newStatus}
|
2025-09-15 21:29:07 +00:00
|
|
|
|
onChange={(e) => setNewStatus(e.target.value as WorkCenterStatusEnum)}
|
2025-09-15 09:31:47 +00:00
|
|
|
|
className="w-full px-3 py-1.5 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
|
|
|
|
|
>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<option value={WorkCenterStatusEnum.Operational}>Operasyonel</option>
|
|
|
|
|
|
<option value={WorkCenterStatusEnum.UnderMaintenance}>Bakımda</option>
|
|
|
|
|
|
<option value={WorkCenterStatusEnum.OutOfOrder}>Arızalı</option>
|
2025-09-15 09:31:47 +00:00
|
|
|
|
<option value={WorkCenterStatusEnum.Retired}>Emekli</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
{isStatusCritical && (
|
|
|
|
|
|
<div className="mt-2 p-2 bg-yellow-50 border border-yellow-200 rounded-lg">
|
|
|
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
|
|
<FaExclamationTriangle className="w-4 h-4 text-yellow-600" />
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<span className="text-sm text-yellow-800 font-medium">Dikkat!</span>
|
2025-09-15 09:31:47 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-sm text-yellow-700 mt-1">
|
2025-09-15 21:29:07 +00:00
|
|
|
|
Bu durum değişikliği iş merkezinin üretim kapasitesini etkileyebilir.
|
2025-09-15 09:31:47 +00:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center space-x-3">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
id="updateCriticality"
|
|
|
|
|
|
checked={updateCriticality}
|
|
|
|
|
|
onChange={(e) => setUpdateCriticality(e.target.checked)}
|
|
|
|
|
|
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
|
|
|
|
|
/>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<label htmlFor="updateCriticality" className="text-sm font-medium text-gray-700">
|
2025-09-15 09:31:47 +00:00
|
|
|
|
Kritiklik seviyesini güncelle
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{updateCriticality && (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
|
|
|
|
Yeni Kritiklik Seviyesi
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={newCriticality}
|
2025-09-15 21:29:07 +00:00
|
|
|
|
onChange={(e) => setNewCriticality(e.target.value as CriticalityLevelEnum)}
|
2025-09-15 09:31:47 +00:00
|
|
|
|
className="w-full px-3 py-1.5 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
|
|
|
|
|
>
|
|
|
|
|
|
<option value={CriticalityLevelEnum.Low}>Düşük</option>
|
|
|
|
|
|
<option value={CriticalityLevelEnum.Medium}>Orta</option>
|
|
|
|
|
|
<option value={CriticalityLevelEnum.High}>Yüksek</option>
|
|
|
|
|
|
<option value={CriticalityLevelEnum.Critical}>Kritik</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Reason */}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
|
|
|
|
Değişiklik Nedeni
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<textarea
|
|
|
|
|
|
value={reason}
|
|
|
|
|
|
onChange={(e) => setReason(e.target.value)}
|
|
|
|
|
|
rows={2}
|
|
|
|
|
|
className="w-full px-3 py-1.5 text-sm border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
|
|
|
|
|
placeholder="Durum değişikliğinin nedenini açıklayın..."
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Summary */}
|
|
|
|
|
|
<div className="bg-blue-50 border border-blue-200 rounded-lg p-3">
|
|
|
|
|
|
<h4 className="font-medium text-blue-900 mb-2">Değişiklik Özeti</h4>
|
|
|
|
|
|
<div className="text-sm text-blue-800 space-y-1">
|
|
|
|
|
|
<p>• {selectedWorkCenters.length} iş merkezi güncellenecek</p>
|
|
|
|
|
|
{updateStatus && (
|
2025-09-15 21:29:07 +00:00
|
|
|
|
<p>• Durum "{getWorkCenterStatusText(newStatus)}" olarak değiştirilecek</p>
|
2025-09-15 09:31:47 +00:00
|
|
|
|
)}
|
|
|
|
|
|
{updateCriticality && (
|
|
|
|
|
|
<p>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
• Kritiklik seviyesi "{getCriticalityLevelText(newCriticality)}" olarak
|
2025-09-15 09:31:47 +00:00
|
|
|
|
değiştirilecek
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Footer */}
|
|
|
|
|
|
<div className="flex items-center justify-end space-x-2 p-4 border-t border-gray-200">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
|
className="px-3 py-1.5 text-sm text-gray-600 border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
İptal
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={handleSave}
|
|
|
|
|
|
disabled={!updateStatus && !updateCriticality}
|
|
|
|
|
|
className="flex items-center space-x-2 px-3 py-1.5 text-sm bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
<FaSave className="w-4 h-4" />
|
|
|
|
|
|
<span>Durumu Güncelle</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-09-15 21:29:07 +00:00
|
|
|
|
)
|
|
|
|
|
|
}
|
2025-09-15 09:31:47 +00:00
|
|
|
|
|
2025-09-15 21:29:07 +00:00
|
|
|
|
export default StatusUpdateModal
|