Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
- Nouvelle entité InterimAgency (table interim_agencies, API lecture seule) - Sélecteur agence conditionnel dans les formulaires création employé et ajout contrat - Affichage "Intérim (NomAgence)" sur la liste employés et l'historique contrat - Date de fin obligatoire côté frontend pour CDD et INTERIM (aligné backend) - Renommage "Types d'absence" → "Types de statut" (sidebar, page, titre) - Renommage en-tête "Absence" → "Statut" sur les vues jour heures et conducteurs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
109 lines
3.7 KiB
TypeScript
109 lines
3.7 KiB
TypeScript
import type { Employee } from '~/services/dto/employee'
|
|
import { CONTRACT_TYPES } from '~/services/dto/contract'
|
|
import { getEmployee } from '~/services/employees'
|
|
|
|
export const useEmployeeDetailPage = () => {
|
|
const route = useRoute()
|
|
const employee = ref<Employee | null>(null)
|
|
const isLoading = ref(false)
|
|
const activeTab = ref<'contract' | 'leave' | 'rtt' | 'mileage' | 'formation' | 'bonus' | 'observation'>('contract')
|
|
|
|
const showLeaveTab = computed(() => employee.value?.currentContractNature !== 'INTERIM')
|
|
const showRttTab = computed(() => employee.value?.contract?.type !== CONTRACT_TYPES.FORFAIT)
|
|
const employeeContractWorkLabel = computed(() => {
|
|
const contract = employee.value?.contract
|
|
if (!contract) return '-'
|
|
if (contract.type === CONTRACT_TYPES.FORFAIT) return 'Forfait'
|
|
if (contract.weeklyHours !== null && contract.weeklyHours !== undefined) return `${contract.weeklyHours} heures`
|
|
return contract.name || '-'
|
|
})
|
|
|
|
const loadEmployee = async () => {
|
|
const idParam = Array.isArray(route.params.id) ? route.params.id[0] : route.params.id
|
|
const employeeId = Number(idParam)
|
|
if (!Number.isInteger(employeeId) || employeeId <= 0) {
|
|
return
|
|
}
|
|
|
|
isLoading.value = true
|
|
try {
|
|
employee.value = await getEmployee(employeeId)
|
|
|
|
if (!showLeaveTab.value && activeTab.value === 'leave') {
|
|
activeTab.value = 'contract'
|
|
}
|
|
if (!showRttTab.value && activeTab.value === 'rtt') {
|
|
activeTab.value = 'contract'
|
|
}
|
|
|
|
leave.resetLoaded()
|
|
rtt.resetLoaded()
|
|
mileage.resetLoaded()
|
|
formation.resetLoaded()
|
|
bonus.resetLoaded()
|
|
observation.resetLoaded()
|
|
|
|
if (activeTab.value === 'leave' && showLeaveTab.value) {
|
|
await leave.loadLeaveData()
|
|
} else if (activeTab.value === 'rtt' && showRttTab.value) {
|
|
await rtt.loadRttData()
|
|
} else if (activeTab.value === 'mileage') {
|
|
await mileage.loadMileageData()
|
|
} else if (activeTab.value === 'formation') {
|
|
await formation.loadFormationData()
|
|
} else if (activeTab.value === 'bonus') {
|
|
await bonus.loadBonusData()
|
|
} else if (activeTab.value === 'observation') {
|
|
await observation.loadObservationData()
|
|
}
|
|
} finally {
|
|
isLoading.value = false
|
|
}
|
|
}
|
|
|
|
const contract = useEmployeeContract(employee, loadEmployee)
|
|
const leave = useEmployeeLeave(employee, loadEmployee)
|
|
const rtt = useEmployeeRtt(employee, loadEmployee)
|
|
const mileage = useEmployeeMileage(employee, loadEmployee)
|
|
const formation = useEmployeeFormation(employee, loadEmployee)
|
|
const bonus = useEmployeeBonus(employee, loadEmployee)
|
|
const observation = useEmployeeObservation(employee, loadEmployee)
|
|
|
|
watch(activeTab, (tab) => {
|
|
if (tab === 'leave' && !leave.leaveDataLoaded.value && showLeaveTab.value) {
|
|
leave.loadLeaveData()
|
|
} else if (tab === 'rtt' && !rtt.rttDataLoaded.value && showRttTab.value) {
|
|
rtt.loadRttData()
|
|
} else if (tab === 'mileage' && !mileage.mileageDataLoaded.value) {
|
|
mileage.loadMileageData()
|
|
} else if (tab === 'formation' && !formation.formationDataLoaded.value) {
|
|
formation.loadFormationData()
|
|
} else if (tab === 'bonus' && !bonus.bonusDataLoaded.value) {
|
|
bonus.loadBonusData()
|
|
} else if (tab === 'observation' && !observation.observationDataLoaded.value) {
|
|
observation.loadObservationData()
|
|
}
|
|
})
|
|
|
|
onMounted(async () => {
|
|
await Promise.all([contract.loadContracts(), contract.loadInterimAgencies()])
|
|
await loadEmployee()
|
|
})
|
|
|
|
return {
|
|
employee,
|
|
isLoading,
|
|
activeTab,
|
|
showLeaveTab,
|
|
showRttTab,
|
|
employeeContractWorkLabel,
|
|
...contract,
|
|
...leave,
|
|
...rtt,
|
|
...mileage,
|
|
...formation,
|
|
...bonus,
|
|
...observation
|
|
}
|
|
}
|