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

Commit c56fb00

Browse files
authored
Merge pull request #172 from topcoder-platform/dev
My Gigs 2nd Week PROD Release
2 parents 47e22a0 + 4d4d5c5 commit c56fb00

File tree

22 files changed

+722
-200
lines changed

22 files changed

+722
-200
lines changed

src/App.jsx

+66-10
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,89 @@ const App = () => {
8888
if (location.pathname === "/earn/my-gigs" && isLoggedIn) {
8989
if (!location.search) {
9090
store.dispatch(actions.filter.updateGigFilter(initialGigFilter));
91-
91+
const cachedGigs = store.getState().myGigs[initialGigFilter.status];
92+
if (cachedGigs.myGigs && cachedGigs.myGigs.length !== 0) {
93+
return;
94+
}
9295
store.dispatch(
93-
actions.myGigs.getMyGigs(
96+
actions.myGigs.getMyOpenGigs(
9497
constants.GIGS_FILTER_STATUSES_PARAM[initialGigFilter.status]
9598
)
9699
);
97100
return;
98101
}
99102
const params = utils.url.parseUrlQuery(location.search);
100103
if (_.keys(params).length == 1 && params.externalId) {
104+
store.dispatch(actions.myGigs.startCheckingGigs(params.externalId));
101105
return;
102106
}
107+
const s =
108+
_.values(constants.GIGS_FILTER_STATUSES).indexOf(params.status) >= 0
109+
? params.status
110+
: null;
103111
const updatedGigFilter = {
104-
status: params.status || "Open Applications",
112+
status: s || "Open Applications",
105113
};
106114
const currentGig = store.getState().filter.gig;
107115
const diff = !_.isEqual(updatedGigFilter, currentGig);
108116
if (diff) {
109117
store.dispatch(actions.filter.updateGigFilter(updatedGigFilter));
110118
}
111-
getDataDebounced.current(() =>
112-
store.dispatch(
113-
actions.myGigs.getMyGigs(
114-
constants.GIGS_FILTER_STATUSES_PARAM[updatedGigFilter.status]
115-
)
116-
)
117-
);
119+
if (updatedGigFilter.status !== initialGigFilter.status) {
120+
// preload the open application first page data.
121+
const cachedOpenGigs = store.getState().myGigs[initialGigFilter.status];
122+
if (!cachedOpenGigs.myGigs) {
123+
store.dispatch(
124+
actions.myGigs.getMyOpenGigs(
125+
constants.GIGS_FILTER_STATUSES_PARAM[initialGigFilter.status]
126+
)
127+
);
128+
}
129+
}
130+
const cachedGigs = store.getState().myGigs[updatedGigFilter.status];
131+
if (cachedGigs.myGigs) {
132+
return;
133+
}
134+
getDataDebounced.current(() => {
135+
if (
136+
updatedGigFilter.status == constants.GIGS_FILTER_STATUSES.ACTIVE_JOBS
137+
) {
138+
store.dispatch(
139+
actions.myGigs.getMyActiveGigs(
140+
constants.GIGS_FILTER_STATUSES_PARAM[updatedGigFilter.status]
141+
)
142+
);
143+
}
144+
if (
145+
updatedGigFilter.status == constants.GIGS_FILTER_STATUSES.OPEN_JOBS
146+
) {
147+
store.dispatch(
148+
actions.myGigs.getMyOpenGigs(
149+
constants.GIGS_FILTER_STATUSES_PARAM[updatedGigFilter.status]
150+
)
151+
);
152+
}
153+
if (
154+
updatedGigFilter.status ==
155+
constants.GIGS_FILTER_STATUSES.COMPLETED_JOBS
156+
) {
157+
store.dispatch(
158+
actions.myGigs.getMyCompletedGigs(
159+
constants.GIGS_FILTER_STATUSES_PARAM[updatedGigFilter.status]
160+
)
161+
);
162+
}
163+
if (
164+
updatedGigFilter.status ==
165+
constants.GIGS_FILTER_STATUSES.ARCHIVED_JOBS
166+
) {
167+
store.dispatch(
168+
actions.myGigs.getMyArchivedGigs(
169+
constants.GIGS_FILTER_STATUSES_PARAM[updatedGigFilter.status]
170+
)
171+
);
172+
}
173+
});
118174
}
119175
}, [location, isLoggedIn]);
120176

src/actions/myGigs.js

+31-17
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,36 @@ import {
66
} from "../constants";
77
import service from "../services/myGigs";
88

9-
/**
10-
* Action to get my gigs.
11-
* @param {number} page page to fetch
12-
* @param {number} perPage items per page. by default is 10.
13-
* @returns
14-
*/
15-
async function getMyGigs(status = "open_jobs", page = 1, perPage = PER_PAGE) {
9+
async function getMyActiveGigs(
10+
status = "active_jobs",
11+
page = 1,
12+
perPage = PER_PAGE
13+
) {
1614
return service.getMyGigs(status, page, perPage);
1715
}
1816

19-
/**
20-
* Action to load more pages of my gigs
21-
* @param {number} nextPage page to fetch
22-
* @param {*} perPage items per page. by default is 10
23-
* @returns
24-
*/
25-
async function loadMoreMyGigs(status, nextPage, perPage = PER_PAGE) {
26-
return service.getMyGigs(status, nextPage, perPage);
17+
async function getMyOpenGigs(
18+
status = "open_jobs",
19+
page = 1,
20+
perPage = PER_PAGE
21+
) {
22+
return service.getMyGigs(status, page, perPage);
23+
}
24+
25+
async function getMyCompletedGigs(
26+
status = "completed_jobs",
27+
page = 1,
28+
perPage = PER_PAGE
29+
) {
30+
return service.getMyGigs(status, page, perPage);
31+
}
32+
33+
async function getMyArchivedGigsDone(
34+
status = "archived_jobs",
35+
page = 1,
36+
perPage = PER_PAGE
37+
) {
38+
return service.getMyGigs(status, page, perPage);
2739
}
2840

2941
async function getProfile() {
@@ -54,8 +66,10 @@ async function startCheckingGigs(externalId) {
5466
}
5567

5668
export default createActions({
57-
GET_MY_GIGS: getMyGigs,
58-
LOAD_MORE_MY_GIGS: loadMoreMyGigs,
69+
GET_MY_ACTIVE_GIGS: getMyActiveGigs,
70+
GET_MY_OPEN_GIGS: getMyOpenGigs,
71+
GET_MY_COMPLETED_GIGS: getMyCompletedGigs,
72+
GET_MY_ARCHIVED_GIGS: getMyArchivedGigsDone,
5973
GET_PROFILE: getProfile,
6074
UPDATE_PROFILE: updateProfile,
6175
START_CHECKING_GIGS: startCheckingGigs,

src/api/common/helper.js

+59-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ async function getJobCandidates(criteria) {
299299
* @param {*} userId
300300
* @returns
301301
*/
302-
async function handlePlacedJobCandidates(jobCandidates, userId) {
302+
async function handlePlacedJobCandidates(jobCandidates, userId, userHandle) {
303303
if (!jobCandidates || jobCandidates.length == 0 || !userId) {
304304
return;
305305
}
@@ -345,13 +345,71 @@ async function handlePlacedJobCandidates(jobCandidates, userId) {
345345
new Date(rb.endDate).toDateString() != new Date().toDateString()
346346
) {
347347
jc.status = "completed";
348+
jc.rbStartDate = rb.startDate;
349+
jc.rbEndDate = rb.endDate;
350+
jc.rbId = rb.id;
351+
jc.userHandle = userHandle;
348352
}
349353
}
350354
}
351355
});
356+
await getWorkingPeriods(jobCandidates, userHandle, rbRes);
352357
return;
353358
}
354359

360+
/**
361+
* Get payment Total for working period
362+
*
363+
* @param {*} jobCandidates job candidates we will process
364+
* @param {*} userHandle the user's handle
365+
* @param {*} resourceBookings the resource booking belongs to this user
366+
* @returns
367+
*/
368+
async function getWorkingPeriods(jobCandidates, userHandle, resourceBookings) {
369+
if (
370+
!userHandle ||
371+
!resourceBookings ||
372+
resourceBookings.length == 0 ||
373+
!jobCandidates ||
374+
jobCandidates.length == 0
375+
) {
376+
return;
377+
}
378+
const rbIds = resourceBookings.map((item) => item.id);
379+
const token = await getM2MToken();
380+
const url = `${config.API.V5}/work-periods`;
381+
const criteria = {
382+
userHandle: userHandle,
383+
resourceBookingIds: rbIds.join(","),
384+
};
385+
const res = await request
386+
.get(url)
387+
.query(criteria)
388+
.set("Authorization", `Bearer ${token}`)
389+
.set("Accept", "application/json");
390+
localLogger.debug({
391+
context: "getWorkingPeriods",
392+
message: `response body: ${JSON.stringify(res.body)}`,
393+
});
394+
if (res.body && res.body.length == 0) {
395+
return;
396+
}
397+
// All the working periods for the rbs.
398+
const wpRes = res.body;
399+
_.each(rbIds, (rbId) => {
400+
const wps = wpRes.filter(
401+
(wp) => wp.userHandle == userHandle && wp.resourceBookingId == rbId
402+
);
403+
const paymentTotal = wps.reduce((total, wp) => total + wp.paymentTotal, 0);
404+
const jc = jobCandidates.find(
405+
(item) => item.rbId == rbId && item.userHandle == userHandle
406+
);
407+
if (jc) {
408+
jc.paymentTotal = paymentTotal;
409+
}
410+
});
411+
}
412+
355413
/**
356414
* Return jobs by given criteria
357415
* @param {string} criteria the search criteria

src/api/docs/swagger.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ components:
273273
example: "Dummy title"
274274
description: "The title."
275275
maxLength: 64
276+
paymentTotal:
277+
type: integer
278+
example: 20
279+
description: "the amount of payment that a member has received for a completed job"
280+
rbStartDate:
281+
type: string
282+
example: "2021-06-05"
283+
description: "the official start time for a job"
284+
rbEndDate:
285+
type: string
286+
example: "2021-07-05"
287+
description: "the official end time for a job"
288+
updatedAt:
289+
type: string
290+
format: date-time
291+
example: "2021-06-21T03:57:17.774Z"
292+
description: "The latest updated date time for a jobCandidate."
276293
payment:
277294
$ref: "#/components/schemas/Payment"
278295
hoursPerWeek:

src/api/services/JobApplicationService.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ async function getMyJobApplications(currentUser, criteria) {
3030
return emptyResult;
3131
}
3232
// get user id by calling taas-api with current user's token
33-
const { id: userId } = await helper.getCurrentUserDetails(
33+
const { id: userId, handle: userHandle } = await helper.getCurrentUserDetails(
3434
currentUser.jwtToken
3535
);
36-
if (!userId) {
36+
if (!userId || !userHandle) {
3737
throw new errors.NotFoundError(
38-
`Id for user: ${currentUser.userId} not found`
38+
`Id for user: ${currentUser.userId} or handle for user: ${currentUser.handle} not found`
3939
);
4040
}
4141
// get jobCandidates of current user by calling taas-api
@@ -54,7 +54,11 @@ async function getMyJobApplications(currentUser, criteria) {
5454
let jcResult = jobCandidates.result;
5555
// handle placed status for completed_jobs, archived_jobs query
5656
if (status && (status == "active_jobs" || status == "completed_jobs")) {
57-
await helper.handlePlacedJobCandidates(jobCandidates.result, userId);
57+
await helper.handlePlacedJobCandidates(
58+
jobCandidates.result,
59+
userId,
60+
userHandle
61+
);
5862
if (status == "completed_jobs") {
5963
jcResult = jobCandidates.result.filter(
6064
(item) => item.status == "completed"
@@ -76,6 +80,10 @@ async function getMyJobApplications(currentUser, criteria) {
7680
const job = _.find(jobs, ["id", jobCandidate.jobId]);
7781
return {
7882
title: job.title,
83+
paymentTotal: jobCandidate.paymentTotal,
84+
rbStartDate: jobCandidate.rbStartDate,
85+
rbEndDate: jobCandidate.rbEndDate,
86+
updatedAt: jobCandidate.updatedAt,
7987
payment: {
8088
min: job.minSalary,
8189
max: job.maxSalary,

src/assets/images/completed.svg

+11
Loading

src/components/Empty/styles.scss

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
background-color: #ffffff;
99
padding: 81px 0px 330px 0px;
1010
min-width: 650px;
11+
min-height: 551px;
1112
.empty-inner {
1213
display: flex;
1314
flex-direction: column;

src/constants/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ export const SORT_STATUS_ORDER = [
353353
MY_GIG_PHASE.PHONE_SCREEN,
354354
MY_GIG_PHASE.SKILLS_TEST,
355355
MY_GIG_PHASE.APPLIED,
356+
MY_GIG_PHASE.WITHDRAWN,
356357
MY_GIG_PHASE.JOB_CLOSED,
357358
MY_GIG_PHASE.NOT_SELECTED,
358359
MY_GIG_PHASE.COMPLETED,
359-
MY_GIG_PHASE.WITHDRAWN,
360360
];
361361

362362
export const PER_PAGE = 10;
@@ -373,6 +373,8 @@ export const AVAILABLE_REMARK_BY_JOB_STATUS = [
373373
MY_GIGS_JOB_STATUS.REJECTED_OTHER,
374374
MY_GIGS_JOB_STATUS.REJECTED_PRE_SCREEN,
375375
MY_GIGS_JOB_STATUS.JOB_CLOSED,
376+
MY_GIGS_JOB_STATUS.WITHDRAWN,
377+
MY_GIGS_JOB_STATUS.WITHDRAWN_PRESCREEN,
376378
];
377379
export const MY_GIG_STATUS_PLACED = "PLACED";
378380

@@ -387,14 +389,23 @@ export const GIG_STATUS_TOOLTIP = {
387389
};
388390

389391
export const MY_GIGS_STATUS_EMPTY_TEXT = {
390-
[GIGS_FILTER_STATUSES.ACTIVE_JOBS]: "YOU DON'T HAVE ANY ACTIVE GIGS YET.",
392+
[GIGS_FILTER_STATUSES.ACTIVE_JOBS]:
393+
"YOU ARE NOT ENGAGED IN ANY GIGS AT THE MOMENT.",
391394
[GIGS_FILTER_STATUSES.OPEN_JOBS]:
392395
"LOOKS LIKE YOU HAVEN'T APPLIED TO ANY GIG OPPORTUNITIES YET.",
393396
[GIGS_FILTER_STATUSES.COMPLETED_JOBS]:
394397
"YOU DON'T HAVE ANY COMPLETED GIGS YET.",
395398
[GIGS_FILTER_STATUSES.ARCHIVED_JOBS]: "YOU DON'T HAVE ANY ARCHIVED GIGS YET.",
396399
};
397400

401+
export const MY_GIGS_STATUS_REMARK_TEXT = {
402+
[MY_GIGS_JOB_STATUS.WITHDRAWN]:
403+
"You withdrew your application for this gig or you have been placed in another gig.",
404+
[MY_GIGS_JOB_STATUS.WITHDRAWN_PRESCREEN]:
405+
"You withdrew your application for this gig or you have been placed in another gig.",
406+
[MY_GIGS_JOB_STATUS.COMPLETED]: "Congrats on completing the gig!",
407+
};
408+
398409
export const CHECKING_GIG_TIMES = 3;
399410

400411
export const DELAY_CHECK_GIG_TIME = 2000;

0 commit comments

Comments
 (0)