feat(employee) : wire contract phase into detail page composable
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { Employee } from '~/services/dto/employee'
|
import type { Employee } from '~/services/dto/employee'
|
||||||
import { CONTRACT_TYPES } from '~/services/dto/contract'
|
import { CONTRACT_TYPES } from '~/services/dto/contract'
|
||||||
import { getEmployee } from '~/services/employees'
|
import { getEmployee } from '~/services/employees'
|
||||||
|
import { useEmployeeContractPhase } from '~/composables/useEmployeeContractPhase'
|
||||||
|
|
||||||
export const useEmployeeDetailPage = () => {
|
export const useEmployeeDetailPage = () => {
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@@ -8,9 +9,11 @@ export const useEmployeeDetailPage = () => {
|
|||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
const activeTab = ref<'contract' | 'leave' | 'rtt' | 'mileage' | 'formation' | 'bonus' | 'observation'>('contract')
|
const activeTab = ref<'contract' | 'leave' | 'rtt' | 'mileage' | 'formation' | 'bonus' | 'observation'>('contract')
|
||||||
|
|
||||||
|
const phase = useEmployeeContractPhase(employee)
|
||||||
|
|
||||||
const showLeaveTab = computed(() => employee.value?.currentContractNature !== 'INTERIM')
|
const showLeaveTab = computed(() => employee.value?.currentContractNature !== 'INTERIM')
|
||||||
const showRttTab = computed(() => employee.value?.contract?.type !== CONTRACT_TYPES.FORFAIT)
|
const showRttTab = computed(() => phase.selectedPhase.value?.contractType !== CONTRACT_TYPES.FORFAIT)
|
||||||
const isForfait = computed(() => employee.value?.contract?.type === CONTRACT_TYPES.FORFAIT)
|
const isForfait = computed(() => phase.selectedPhase.value?.contractType === CONTRACT_TYPES.FORFAIT)
|
||||||
const employeeContractWorkLabel = computed(() => {
|
const employeeContractWorkLabel = computed(() => {
|
||||||
const contract = employee.value?.contract
|
const contract = employee.value?.contract
|
||||||
if (!contract) return '-'
|
if (!contract) return '-'
|
||||||
@@ -29,6 +32,7 @@ export const useEmployeeDetailPage = () => {
|
|||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
try {
|
try {
|
||||||
employee.value = await getEmployee(employeeId)
|
employee.value = await getEmployee(employeeId)
|
||||||
|
phase.resetToCurrent()
|
||||||
|
|
||||||
if (!showLeaveTab.value && activeTab.value === 'leave') {
|
if (!showLeaveTab.value && activeTab.value === 'leave') {
|
||||||
activeTab.value = 'contract'
|
activeTab.value = 'contract'
|
||||||
@@ -66,7 +70,7 @@ export const useEmployeeDetailPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const contract = useEmployeeContract(employee, loadEmployee)
|
const contract = useEmployeeContract(employee, loadEmployee)
|
||||||
const leave = useEmployeeLeave(employee, loadEmployee)
|
const leave = useEmployeeLeave(employee, loadEmployee, phase.selectedPhase)
|
||||||
const forfaitRemainingDaysLabel = computed(() => {
|
const forfaitRemainingDaysLabel = computed(() => {
|
||||||
if (!isForfait.value) return ''
|
if (!isForfait.value) return ''
|
||||||
const presence = leave.leaveSummary.value?.presenceDaysToToday
|
const presence = leave.leaveSummary.value?.presenceDaysToToday
|
||||||
@@ -74,12 +78,26 @@ export const useEmployeeDetailPage = () => {
|
|||||||
const remaining = 218 - presence
|
const remaining = 218 - presence
|
||||||
return ` (${remaining} restants)`
|
return ` (${remaining} restants)`
|
||||||
})
|
})
|
||||||
const rtt = useEmployeeRtt(employee, loadEmployee)
|
const rtt = useEmployeeRtt(employee, loadEmployee, phase.selectedPhase)
|
||||||
const mileage = useEmployeeMileage(employee, loadEmployee)
|
const mileage = useEmployeeMileage(employee, loadEmployee)
|
||||||
const formation = useEmployeeFormation(employee, loadEmployee)
|
const formation = useEmployeeFormation(employee, loadEmployee)
|
||||||
const bonus = useEmployeeBonus(employee, loadEmployee)
|
const bonus = useEmployeeBonus(employee, loadEmployee)
|
||||||
const observation = useEmployeeObservation(employee, loadEmployee)
|
const observation = useEmployeeObservation(employee, loadEmployee)
|
||||||
|
|
||||||
|
watch(() => phase.selectedPhase.value?.id, (newId, oldId) => {
|
||||||
|
if (newId === oldId || oldId === undefined) return
|
||||||
|
// Bascule onglet si on entre dans une phase qui ne supporte plus le tab actuel
|
||||||
|
if (!showRttTab.value && activeTab.value === 'rtt') {
|
||||||
|
activeTab.value = 'leave'
|
||||||
|
}
|
||||||
|
// Recharger l'onglet courant
|
||||||
|
if (activeTab.value === 'leave' && showLeaveTab.value) {
|
||||||
|
leave.loadLeaveData()
|
||||||
|
} else if (activeTab.value === 'rtt' && showRttTab.value) {
|
||||||
|
rtt.loadRttData()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
watch(activeTab, (tab) => {
|
watch(activeTab, (tab) => {
|
||||||
if (tab === 'leave' && !leave.leaveDataLoaded.value && showLeaveTab.value) {
|
if (tab === 'leave' && !leave.leaveDataLoaded.value && showLeaveTab.value) {
|
||||||
leave.loadLeaveData()
|
leave.loadLeaveData()
|
||||||
@@ -109,6 +127,7 @@ export const useEmployeeDetailPage = () => {
|
|||||||
showRttTab,
|
showRttTab,
|
||||||
employeeContractWorkLabel,
|
employeeContractWorkLabel,
|
||||||
forfaitRemainingDaysLabel,
|
forfaitRemainingDaysLabel,
|
||||||
|
...phase,
|
||||||
...contract,
|
...contract,
|
||||||
...leave,
|
...leave,
|
||||||
...rtt,
|
...rtt,
|
||||||
|
|||||||
Reference in New Issue
Block a user