Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit b96c46e

Browse files
authored
Merge pull request #97 from yoution/issue-90
fix: issue #90
2 parents b0d6864 + 1c724ad commit b96c46e

File tree

3 files changed

+45
-40
lines changed

3 files changed

+45
-40
lines changed

src/routes/ResourceBookingDetails/index.jsx

+20-24
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
* Page for resource booking details.
55
* It gets `teamId` and `resourceBookingId` from the router.
66
*/
7-
import React, { useState, useEffect } from "react";
7+
import React, { useMemo, useState, useEffect } from "react";
88
import PT from "prop-types";
9+
import _ from "lodash";
910
import Page from "../../components/Page";
1011
import PageHeader from "../../components/PageHeader";
1112
import { useData } from "hooks/useData";
1213
import { getReourceBookingById } from "services/resourceBookings";
13-
import { getPositionDetails } from "services/teams";
14+
import { getTeamById } from "services/teams";
1415
import LoadingIndicator from "../../components/LoadingIndicator";
1516
import withAuthentication from "../../hoc/withAuthentication";
1617
import Button from "../../components/Button";
@@ -19,32 +20,27 @@ import ResourceDetails from "./ResourceDetails";
1920
import "./styles.module.scss";
2021

2122
const ResourceBookingDetails = ({ teamId, resourceBookingId }) => {
22-
const [jobId, setJobId] = useState(null);
23-
const [title, setTitle] = useState(null);
24-
const [candidate, setCandidate] = useState(null);
2523
const [rb, loadingError] = useData(getReourceBookingById, resourceBookingId);
24+
const [team, loadingTeamError] = useData(getTeamById, teamId);
2625

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;
3038
}
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]);
4440

4541
return (
4642
<Page title="Member Details">
47-
{!candidate ? (
43+
{!member ? (
4844
<LoadingIndicator error={loadingError} />
4945
) : (
5046
<>
@@ -53,8 +49,8 @@ const ResourceBookingDetails = ({ teamId, resourceBookingId }) => {
5349
backTo={`/taas/myteams/${teamId}`}
5450
/>
5551
<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 }} />
5854
<div styleName="actions">
5955
<Button
6056
size="medium"

src/routes/ResourceBookingForm/index.jsx

+23-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import React, { useState, useEffect } from "react";
88
import PT from "prop-types";
9+
import _ from "lodash";
910
import { toastr } from "react-redux-toastr";
1011
import Page from "../../components/Page";
1112
import PageHeader from "../../components/PageHeader";
@@ -14,7 +15,7 @@ import {
1415
getReourceBookingById,
1516
updateReourceBooking,
1617
} from "services/resourceBookings";
17-
import { getPositionDetails } from "services/teams";
18+
import { getTeamById } from "services/teams";
1819
import LoadingIndicator from "../../components/LoadingIndicator";
1920
import withAuthentication from "../../hoc/withAuthentication";
2021
import TCForm from "../../components/TCForm";
@@ -25,6 +26,7 @@ const ResourceBookingDetails = ({ teamId, resourceBookingId }) => {
2526
const [submitting, setSubmitting] = useState(false);
2627
const [jobId, setJobId] = useState(null);
2728
const [formData, setFormData] = useState(null);
29+
const [team, loadingTeamError] = useData(getTeamById, teamId);
2830
const [rb, loadingError] = useData(getReourceBookingById, resourceBookingId);
2931

3032
useEffect(() => {
@@ -34,20 +36,27 @@ const ResourceBookingDetails = ({ teamId, resourceBookingId }) => {
3436
}, [rb]);
3537

3638
useEffect(() => {
37-
if (jobId) {
38-
getPositionDetails(teamId, jobId).then((response) => {
39-
const candidate = response.data.candidates?.find(
40-
(x) => x.userId === rb.userId
41-
);
42-
const data = {
43-
title: response.data.title,
44-
...candidate,
45-
...rb,
46-
};
47-
setFormData(data);
48-
});
39+
if (team && rb) {
40+
const resource = _.find(
41+
team.resources,
42+
(r) => r.id === resourceBookingId
43+
);
44+
45+
let job;
46+
if (resource.jobId) {
47+
job = _.find(team.jobs, { id: resource.jobId });
48+
}
49+
50+
const jobTitle = _.get(job, "title", "<Not Assigned>");
51+
52+
const data = {
53+
jobTitle,
54+
...resource,
55+
...rb,
56+
};
57+
setFormData(data);
4958
}
50-
}, [jobId, rb, teamId]);
59+
}, [rb, team, resourceBookingId]);
5160

5261
const onSubmit = async (values) => {
5362
const data = getRequestData(values);

src/routes/ResourceBookingForm/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
} from "../../constants";
1313

1414
const EDIT_ResourceBooking_ROWS = [
15-
{ type: FORM_ROW_TYPE.SINGLE, fields: ["title"] },
1615
{ type: FORM_ROW_TYPE.SINGLE, fields: ["handle"] },
16+
{ type: FORM_ROW_TYPE.SINGLE, fields: ["jobTitle"] },
1717
{ type: FORM_ROW_TYPE.GROUP, fields: ["startDate", "endDate"] },
1818
{ type: FORM_ROW_TYPE.GROUP, fields: ["customerRate", "memberRate"] },
1919
{ type: FORM_ROW_TYPE.SINGLE, fields: ["status"] },
@@ -26,8 +26,8 @@ const EDIT_ResourceBooking_ROWS = [
2626
export const getEditResourceBookingConfig = (onSubmit) => {
2727
return {
2828
fields: [
29-
{ readonly: true, type: FORM_FIELD_TYPE.TEXT, name: "title" },
3029
{ readonly: true, type: FORM_FIELD_TYPE.TEXT, name: "handle" },
30+
{ readonly: true, type: FORM_FIELD_TYPE.TEXT, name: "jobTitle" },
3131
{
3232
label: "Client Rate",
3333
type: FORM_FIELD_TYPE.NUMBER,

0 commit comments

Comments
 (0)