4
4
* Page for resource booking details.
5
5
* It gets `teamId` and `resourceBookingId` from the router.
6
6
*/
7
- import React , { useState , useEffect } from "react" ;
7
+ import React , { useMemo , useState , useEffect } from "react" ;
8
8
import PT from "prop-types" ;
9
+ import _ from "lodash" ;
9
10
import Page from "../../components/Page" ;
10
11
import PageHeader from "../../components/PageHeader" ;
11
12
import { useData } from "hooks/useData" ;
12
13
import { getReourceBookingById } from "services/resourceBookings" ;
13
- import { getPositionDetails } from "services/teams" ;
14
+ import { getTeamById } from "services/teams" ;
14
15
import LoadingIndicator from "../../components/LoadingIndicator" ;
15
16
import withAuthentication from "../../hoc/withAuthentication" ;
16
17
import Button from "../../components/Button" ;
@@ -19,32 +20,27 @@ import ResourceDetails from "./ResourceDetails";
19
20
import "./styles.module.scss" ;
20
21
21
22
const ResourceBookingDetails = ( { teamId, resourceBookingId } ) => {
22
- const [ jobId , setJobId ] = useState ( null ) ;
23
- const [ title , setTitle ] = useState ( null ) ;
24
- const [ candidate , setCandidate ] = useState ( null ) ;
25
23
const [ rb , loadingError ] = useData ( getReourceBookingById , resourceBookingId ) ;
24
+ const [ team , loadingTeamError ] = useData ( getTeamById , teamId ) ;
26
25
27
- useEffect ( ( ) => {
28
- if ( ! ! rb ) {
29
- setJobId ( rb . jobId ) ;
26
+ const member = useMemo ( ( ) => {
27
+ if ( team ) {
28
+ const resource = _ . find (
29
+ team . resources ,
30
+ ( r ) => r . id === resourceBookingId
31
+ ) ;
32
+ let job ;
33
+ if ( resource . jobId ) {
34
+ job = _ . find ( team . jobs , { id : resource . jobId } ) ;
35
+ }
36
+ resource . jobTitle = _ . get ( job , "title" , "<Not Assigned>" ) ;
37
+ return resource ;
30
38
}
31
- } , [ rb ] ) ;
32
-
33
- useEffect ( ( ) => {
34
- if ( jobId ) {
35
- getPositionDetails ( teamId , jobId ) . then ( ( response ) => {
36
- const data = response . data . candidates ?. find (
37
- ( x ) => x . userId === rb . userId
38
- ) ;
39
- setCandidate ( data ) ;
40
- setTitle ( response . data . title ) ;
41
- } ) ;
42
- }
43
- } , [ jobId ] ) ;
39
+ } , [ team , resourceBookingId ] ) ;
44
40
45
41
return (
46
42
< Page title = "Member Details" >
47
- { ! candidate ? (
43
+ { ! member ? (
48
44
< LoadingIndicator error = { loadingError } />
49
45
) : (
50
46
< >
@@ -53,8 +49,8 @@ const ResourceBookingDetails = ({ teamId, resourceBookingId }) => {
53
49
backTo = { `/taas/myteams/${ teamId } ` }
54
50
/>
55
51
< div styleName = "content-wrapper" >
56
- < ResourceSummary candidate = { candidate } />
57
- < ResourceDetails resource = { { ...rb , title : title } } />
52
+ < ResourceSummary candidate = { member } />
53
+ < ResourceDetails resource = { { ...rb , title : member . jobTitle } } />
58
54
< div styleName = "actions" >
59
55
< Button
60
56
size = "medium"
0 commit comments