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

Commit c89e995

Browse files
author
dengjun
committed
ci:wireup frontend with new API
1 parent 25b3a9a commit c89e995

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

src/actions/myGigs.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createActions } from "redux-actions";
2-
import { PER_PAGE } from "../constants";
2+
import { PER_PAGE, CHECKING_GIG_TIMES } from "../constants";
33
import service from "../services/myGigs";
44

55
/**
@@ -30,9 +30,24 @@ async function updateProfile(profile) {
3030
return service.updateProfile(profile);
3131
}
3232

33+
async function startCheckingGigs(externalId) {
34+
let i = 0;
35+
while (i < CHECKING_GIG_TIMES) {
36+
const res = await service.startCheckingGigs(externalId);
37+
if (res && !res.synced) {
38+
i++;
39+
continue;
40+
} else {
41+
return {};
42+
}
43+
}
44+
return {};
45+
}
46+
3347
export default createActions({
3448
GET_MY_GIGS: getMyGigs,
3549
LOAD_MORE_MY_GIGS: loadMoreMyGigs,
3650
GET_PROFILE: getProfile,
3751
UPDATE_PROFILE: updateProfile,
52+
START_CHECKING_GIGS: startCheckingGigs,
3853
});

src/constants/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,5 @@ export const GIG_STATUS_TOOLTIP = {
352352

353353
export const EMPTY_GIGS_TEXT =
354354
"Looks like you haven't applied to any gig opportunities yet.";
355+
356+
export const CHECKING_GIG_TIMES = 3;

src/containers/MyGigs/index.jsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, { useEffect, useRef, useState } from "react";
2+
import { useLocation } from "@reach/router";
23
import PT from "prop-types";
34
import { connect } from "react-redux";
45
import Modal from "../../components/Modal";
56
import Button from "../../components/Button";
67
import JobListing from "./JobListing";
78
import actions from "../../actions";
89
import { EMPTY_GIGS_TEXT } from "../../constants";
10+
import * as utils from "../../utils";
911

1012
import UpdateGigProfile from "./modals/UpdateGigProfile";
1113
import UpdateSuccess from "./modals/UpdateSuccess";
@@ -23,16 +25,41 @@ const MyGigs = ({
2325
updateProfile,
2426
updateProfileSuccess,
2527
getAllCountries,
28+
checkingGigs,
29+
startCheckingGigs,
2630
}) => {
31+
const location = useLocation();
32+
const params = utils.url.parseUrlQuery(location.search);
2733
const propsRef = useRef();
28-
propsRef.current = { getMyGigs, getProfile, getAllCountries };
34+
propsRef.current = {
35+
getMyGigs,
36+
getProfile,
37+
getAllCountries,
38+
startCheckingGigs,
39+
params,
40+
};
2941

3042
useEffect(() => {
31-
propsRef.current.getMyGigs();
3243
propsRef.current.getProfile();
3344
propsRef.current.getAllCountries();
45+
if (propsRef.current.params.externalId) {
46+
propsRef.current.startCheckingGigs(propsRef.current.params.externalId);
47+
} else {
48+
propsRef.current.getMyGigs();
49+
}
3450
}, []);
3551

52+
const isInitialMount = useRef(true);
53+
useEffect(() => {
54+
if (isInitialMount.current) {
55+
isInitialMount.current = false;
56+
return;
57+
}
58+
if (!checkingGigs) {
59+
propsRef.current.getMyGigs();
60+
}
61+
}, [checkingGigs]);
62+
3663
const [openUpdateProfile, setOpenUpdateProfile] = useState(false);
3764
const [openUpdateSuccess, setOpenUpdateSuccess] = useState(false);
3865

@@ -106,9 +133,12 @@ MyGigs.propTypes = {
106133
updateProfile: PT.func,
107134
updateProfileSuccess: PT.bool,
108135
getAllCountries: PT.func,
136+
checkingGigs: PT.bool,
137+
startCheckingGigs: PT.func,
109138
};
110139

111140
const mapStateToProps = (state) => ({
141+
checkingGigs: state.myGigs.checkingGigs,
112142
myGigs: state.myGigs.myGigs,
113143
total: state.myGigs.total,
114144
numLoaded: state.myGigs.numLoaded,
@@ -122,6 +152,7 @@ const mapDispatchToProps = {
122152
getProfile: actions.myGigs.getProfile,
123153
updateProfile: actions.myGigs.updateProfile,
124154
getAllCountries: actions.lookup.getAllCountries,
155+
startCheckingGigs: actions.myGigs.startCheckingGigs,
125156
};
126157

127158
export default connect(mapStateToProps, mapDispatchToProps)(MyGigs);

src/reducers/myGigs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const defaultState = {
1515
updatingProfile: false,
1616
updatingProfileError: null,
1717
updatingProfileSucess: null,
18+
checkingGigs: false,
1819
};
1920

2021
function onGetMyGigsInit(state) {
@@ -111,6 +112,20 @@ function onUpdateProfileFailure(state, { payload }) {
111112
};
112113
}
113114

115+
function onCheckingGigsInit(state) {
116+
return {
117+
...state,
118+
checkingGigs: true,
119+
};
120+
}
121+
122+
function onCheckingGigsDone(state) {
123+
return {
124+
...state,
125+
checkingGigs: false,
126+
};
127+
}
128+
114129
export default handleActions(
115130
{
116131
GET_MY_GIGS_INIT: onGetMyGigsInit,
@@ -125,6 +140,8 @@ export default handleActions(
125140
UPDATE_PROFILE_INIT: onUpdateProfileInit,
126141
UPDATE_PROFILE_DONE: onUpdateProfileDone,
127142
UPDATE_PROFILE_FAILURE: onUpdateProfileFailure,
143+
START_CHECKING_GIGS_INIT: onCheckingGigsInit,
144+
START_CHECKING_GIGS_DONE: onCheckingGigsDone,
128145
},
129146
defaultState
130147
);

src/services/myGigs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,17 @@ async function updateProfile(profile) {
157157
return response;
158158
}
159159

160+
async function startCheckingGigs(externalId) {
161+
const res = await api.get(
162+
`/earn-app/api/my-gigs/job?externalId=${externalId}`,
163+
process.env.URL.PLATFORM_WEBSITE_URL
164+
);
165+
return res;
166+
}
167+
160168
export default {
161169
getMyGigs,
162170
getProfile,
163171
updateProfile,
172+
startCheckingGigs,
164173
};

0 commit comments

Comments
 (0)