11/**
22 * 급여명세서 바텀시트 데이터 관리 훅.
3- * 계약 목록 → 계약 상세( 근무지명, payrollDeductionType) + 급여 계산을 병렬 호출하여
4- * 근무지별 급여명세서 데이터를 구성.
3+ * 계약 목록 응답에서 근무지명, payrollDeductionType을 직접 사용하고
4+ * 급여 계산만 병렬 호출하여 근무지별 급여명세서 데이터를 구성.
55 */
66import { useState , useCallback } from "react" ;
7- import {
8- getContracts ,
9- getContractDetail ,
10- calculateSalary ,
11- } from "../../api/worker" ;
7+ import { getContracts , calculateSalary } from "../../api/worker" ;
128import type {
139 PayrollDeductionType ,
1410 SalaryCalculateResponse ,
@@ -35,29 +31,23 @@ const useSalaryStatement = (year: number, month: number) => {
3531
3632 const results = await Promise . all (
3733 activeContracts . map ( async ( contract ) => {
38- const [ detailRes , salaryRes ] = await Promise . allSettled ( [
39- getContractDetail ( contract . id ) ,
40- calculateSalary ( contract . id , year , month ) ,
41- ] ) ;
42-
43- const detail =
44- detailRes . status === "fulfilled"
45- ? detailRes . value . data
46- : null ;
47- const salary =
48- salaryRes . status === "fulfilled"
49- ? salaryRes . value . data
50- : null ;
34+ let salary : SalaryCalculateResponse | null = null ;
35+ try {
36+ const salaryRes = await calculateSalary (
37+ contract . id ,
38+ year ,
39+ month
40+ ) ;
41+ salary = salaryRes . data ?? null ;
42+ } catch {
43+ // 급여 계산 실패 시 null
44+ }
5145
5246 return {
5347 contractId : contract . id ,
54- workplaceName :
55- detail ?. workplaceName ??
56- contract . workplaceName ??
57- "알 수 없음" ,
58- payrollDeductionType :
59- detail ?. payrollDeductionType ?? "PART_TIME_NONE" ,
60- salary : salary ?? null ,
48+ workplaceName : contract . workplaceName ,
49+ payrollDeductionType : contract . payrollDeductionType ,
50+ salary,
6151 } ;
6252 } )
6353 ) ;
0 commit comments