@@ -6,10 +6,9 @@ import React, { useState } from 'react'
6
6
7
7
import ResponsiveWholePageCollapsible from 'citizen-frontend/children/ResponsiveWholePageCollapsible'
8
8
import { useTranslation } from 'citizen-frontend/localization'
9
- import { combine , Failure , Result , Success , wrapResult } from 'lib-common/api'
9
+ import { combine , Failure , Result , Success } from 'lib-common/api'
10
10
import { ChildId } from 'lib-common/generated/api-types/shared'
11
- import { useQueryResult } from 'lib-common/query'
12
- import { useApiState } from 'lib-common/utils/useRestApi'
11
+ import { constantQuery , useQueryResult } from 'lib-common/query'
13
12
import HorizontalLine from 'lib-components/atoms/HorizontalLine'
14
13
import ErrorSegment from 'lib-components/atoms/state/ErrorSegment'
15
14
import Spinner from 'lib-components/atoms/state/Spinner'
@@ -22,50 +21,44 @@ import { Gap } from 'lib-components/white-space'
22
21
import { featureFlags } from 'lib-customizations/citizen'
23
22
24
23
import { renderResult } from '../../../async-rendering'
25
- import {
26
- getChildDailyServiceTimes ,
27
- getChildServiceNeeds
28
- } from '../../../generated/api-clients/children'
29
24
import { childrenQuery , childServiceApplicationsQuery } from '../../queries'
30
25
31
26
import AttendanceSummaryTable from './AttendanceSummaryTable'
32
27
import DailyServiceTimeTable from './DailyServiceTimeTable'
33
28
import ServiceApplications from './ServiceApplications'
34
29
import ServiceNeedTable from './ServiceNeedTable'
30
+ import { childDailyServiceTimesQuery , childServiceNeedsQuery } from './queries'
35
31
36
32
interface ServiceNeedProps {
37
33
childId : ChildId
38
34
showServiceTimes : boolean
39
35
}
40
36
41
- const getChildServiceNeedsResult = wrapResult ( getChildServiceNeeds )
42
- const getChildDailyServiceTimesResult = wrapResult ( getChildDailyServiceTimes )
43
-
44
37
export default React . memo ( function ServiceNeedAndDailyServiceTimeSection ( {
45
38
childId,
46
39
showServiceTimes
47
40
} : ServiceNeedProps ) {
48
41
const t = useTranslation ( )
49
42
const [ open , setOpen ] = useState ( false )
50
- const [ serviceNeedsResponse ] = useApiState (
51
- ( ) => getChildServiceNeedsResult ( { childId } ) ,
52
- [ childId ]
43
+ const serviceNeedsResponse = useQueryResult (
44
+ childServiceNeedsQuery ( { childId } )
53
45
)
54
- const [ dailyServiceTimesResponse ] = useApiState (
55
- ( ) =>
56
- showServiceTimes
57
- ? getChildDailyServiceTimesResult ( { childId } )
58
- : Promise . resolve ( Success . of ( [ ] ) ) ,
59
- [ childId , showServiceTimes ]
46
+ const dailyServiceTimesResponse = useQueryResult (
47
+ showServiceTimes
48
+ ? childDailyServiceTimesQuery ( { childId } )
49
+ : constantQuery ( [ ] )
60
50
)
61
51
62
- const hasContractDays = serviceNeedsResponse
63
- . map ( ( serviceNeeds ) =>
64
- serviceNeeds . some (
65
- ( { contractDaysPerMonth } ) => contractDaysPerMonth !== null
52
+ const showAttendanceSummary =
53
+ featureFlags . citizenAttendanceSummary &&
54
+ serviceNeedsResponse
55
+ . map ( ( serviceNeeds ) =>
56
+ serviceNeeds . some (
57
+ ( { contractDaysPerMonth, reservationsEnabled } ) =>
58
+ contractDaysPerMonth !== null && reservationsEnabled
59
+ )
66
60
)
67
- )
68
- . getOrElse ( false )
61
+ . getOrElse ( false )
69
62
70
63
const serviceApplications = useQueryResult (
71
64
childServiceApplicationsQuery ( { childId } )
@@ -101,7 +94,7 @@ export default React.memo(function ServiceNeedAndDailyServiceTimeSection({
101
94
< ServiceNeedTable serviceNeeds = { serviceNeeds } />
102
95
)
103
96
} ) }
104
- { featureFlags . citizenAttendanceSummary && hasContractDays && (
97
+ { showAttendanceSummary && (
105
98
< >
106
99
< Gap size = "s" />
107
100
< AttendanceSummaryTable
0 commit comments