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

Commit ae8738d

Browse files
committed
New icon-role-fallback for RoleItem
Change SkillItem to use IconSkill Use localStorage to persist searched roles
1 parent 59410d7 commit ae8738d

File tree

12 files changed

+112
-124
lines changed

12 files changed

+112
-124
lines changed
Lines changed: 17 additions & 0 deletions
Loading
Lines changed: 22 additions & 16 deletions
Loading
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import { ACTION_TYPE } from "constants";
22

3-
export const clearSearchedRoles = () => ({
3+
const updateLocalStorage = (state) => {
4+
try {
5+
localStorage.setItem("rolesState", JSON.stringify(state));
6+
} catch {
7+
console.error("Unable to set localStorage");
8+
}
9+
};
10+
11+
const clearRoles = () => ({
412
type: ACTION_TYPE.CLEAR_SEARCHED_ROLES,
513
});
614

7-
export const addSearchedRole = (searchedRole) => ({
15+
const addRole = (searchedRole) => ({
816
type: ACTION_TYPE.ADD_SEARCHED_ROLE,
917
payload: searchedRole,
1018
});
1119

12-
export const addRoleSearchId = (id) => ({
20+
const addPreviousSearchId = (id) => ({
1321
type: ACTION_TYPE.ADD_ROLE_SEARCH_ID,
1422
payload: id,
1523
});
@@ -18,3 +26,18 @@ export const replaceSearchedRoles = (roles) => ({
1826
type: ACTION_TYPE.REPLACE_SEARCHED_ROLES,
1927
payload: { roles, lastRoleId: roles[roles.length - 1].searchId },
2028
});
29+
30+
export const clearSearchedRoles = () => (dispatch, getState) => {
31+
dispatch(clearRoles());
32+
updateLocalStorage(getState().searchedRoles);
33+
};
34+
35+
export const addSearchedRole = (searchedRole) => (dispatch, getState) => {
36+
dispatch(addRole(searchedRole));
37+
updateLocalStorage(getState().searchedRoles);
38+
};
39+
40+
export const addRoleSearchId = (id) => (dispatch, getState) => {
41+
dispatch(addPreviousSearchId(id));
42+
updateLocalStorage(getState().searchedRoles);
43+
};

src/routes/CreateNewTeam/components/NoMatchingProfilesResultCard/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function NoMatchingProfilesResultCard() {
2828
<p styleName="cost">$1,200</p>
2929
<p>/Week</p>
3030
</div>
31-
<Link to="/taas/myteams/createnewteam" state={{ keepAddedRoles: true }}>
31+
<Link to="/taas/myteams/createnewteam">
3232
<Button type="secondary" styleName="button">
3333
Modify Search Criteria
3434
</Button>

src/routes/CreateNewTeam/components/SearchAndSubmit/index.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { Router } from "@reach/router";
22
import React from "react";
3+
import { useSelector } from "react-redux";
34
import SearchContainer from "../SearchContainer";
45
import SubmitContainer from "../SubmitContainer";
56

67
function SearchAndSubmit(props) {
8+
const { addedRoles, previousSearchId } = useSelector(
9+
(state) => state.searchedRoles
10+
);
11+
712
return (
813
<Router>
9-
<SearchContainer path="/" {...props} />
10-
<SubmitContainer path="result" {...props} />
14+
<SearchContainer
15+
path="/"
16+
addedRoles={addedRoles}
17+
previousSearchId={previousSearchId}
18+
{...props}
19+
/>
20+
<SubmitContainer path="result" addedRoles={addedRoles} {...props} />
1121
</Router>
1222
);
1323
}

src/routes/CreateNewTeam/components/SearchContainer/index.jsx

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,25 @@ import { setCurrentStage } from "utils/helpers";
1919
import { addRoleSearchId, addSearchedRole } from "../../actions";
2020
import "./styles.module.scss";
2121

22-
/**
23-
* Converts an array of role search objects to two data
24-
* lists which can be set as sessionStorage items
25-
*
26-
* @param {object[]} arrayOfObjects array of role objects
27-
*/
28-
const storeStrings = (arrayOfObjects) => {
29-
const objectOfArrays = arrayOfObjects.reduce(
30-
(acc, curr) => ({
31-
searchId: [...acc.searchId, curr.searchId],
32-
name: [...acc.name, curr.name],
33-
}),
34-
{ searchId: [], name: [] }
35-
);
36-
37-
sessionStorage.setItem("searchIds", objectOfArrays.searchId.join(","));
38-
sessionStorage.setItem("roleNames", objectOfArrays.name.join(","));
39-
};
40-
4122
function SearchContainer({
4223
stages,
4324
setStages,
4425
isCompletenessDisabled,
4526
toRender,
4627
searchObject,
4728
completenessStyle,
48-
reloadRolesPage,
4929
navigate,
30+
addedRoles,
31+
previousSearchId,
5032
}) {
51-
const { addedRoles, previousSearchId } = useSelector(
52-
(state) => state.searchedRoles
53-
);
54-
5533
const [searchState, setSearchState] = useState(null);
5634
const [matchingRole, setMatchingRole] = useState(null);
57-
const [addAnotherModalOpen, setAddAnotherModalOpen] = useState(false);
58-
const [submitDone, setSubmitDone] = useState(true);
5935

6036
const dispatch = useDispatch();
6137

6238
const onSubmit = useCallback(() => {
63-
storeStrings(addedRoles);
6439
navigate("result", { state: { matchingRole } });
65-
}, [addedRoles, navigate, matchingRole]);
40+
}, [navigate, matchingRole]);
6641

6742
const search = () => {
6843
setCurrentStage(1, stages, setStages);
@@ -135,8 +110,9 @@ SearchContainer.propTypes = {
135110
searchObject: PT.object,
136111
toRender: PT.node,
137112
completenessStyle: PT.string,
138-
reloadRolesPage: PT.func,
139113
navigate: PT.func,
114+
addedRoles: PT.array,
115+
previousSearchId: PT.string,
140116
};
141117

142118
export default SearchContainer;

src/routes/CreateNewTeam/components/SubmitContainer/index.jsx

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,34 @@ import ConfirmationModal from "../ConfirmationModal";
1919
import withAuthentication from "../../../../hoc/withAuthentication";
2020
import "./styles.module.scss";
2121
import { setCurrentStage } from "utils/helpers";
22-
import { clearSearchedRoles, replaceSearchedRoles } from "../../actions";
22+
import { clearSearchedRoles } from "../../actions";
2323
import { postTeamRequest } from "services/teams";
2424
import SuccessCard from "../SuccessCard";
2525

26-
const retrieveRoles = () => {
27-
const searchIdString = sessionStorage.getItem("searchIds");
28-
const nameString = sessionStorage.getItem("roleNames");
29-
30-
if (!searchIdString || !nameString) return [];
31-
const searchIds = searchIdString.split(",");
32-
const names = nameString.split(",");
33-
if (searchIds.length !== names.length) return [];
34-
35-
const roles = [];
36-
for (let i = 0; i < searchIds.length; i++) {
37-
roles.push({
38-
searchId: searchIds[i],
39-
name: names[i],
40-
});
41-
}
42-
43-
return roles;
44-
};
45-
46-
const clearSessionKeys = () => {
47-
sessionStorage.removeItem("searchIds");
48-
sessionStorage.removeItem("roleNames");
49-
};
50-
5126
function SubmitContainer({
5227
stages,
5328
setStages,
5429
completenessStyle,
55-
reloadRolesPage,
5630
location,
31+
addedRoles,
5732
}) {
5833
const matchingRole = location?.state?.matchingRole;
5934

60-
const { addedRoles } = useSelector((state) => state.searchedRoles);
61-
6235
const [addAnotherOpen, setAddAnotherOpen] = useState(true);
6336
const [teamDetailsOpen, setTeamDetailsOpen] = useState(false);
6437
const [teamObject, setTeamObject] = useState(null);
6538
const [requestLoading, setRequestLoading] = useState(false);
6639

6740
const dispatch = useDispatch();
6841

42+
// Set correct state for Completeness tab, and redirect
43+
// to main page if path loaded without any selected roles.
6944
useEffect(() => {
7045
setCurrentStage(2, stages, setStages);
71-
const storedRoles = retrieveRoles();
72-
if (storedRoles) {
73-
if (!addedRoles || storedRoles.length > addedRoles.length) {
74-
dispatch(replaceSearchedRoles(storedRoles));
75-
}
46+
if (!addedRoles || addedRoles.length === 0) {
47+
navigate("/taas/myteams/createnewteam");
7648
}
49+
// only needed on initial load, avoids too many re-renders
7750
// eslint-disable-next-line react-hooks/exhaustive-deps
7851
}, []);
7952

@@ -83,11 +56,7 @@ function SubmitContainer({
8356
};
8457

8558
const addAnother = () => {
86-
if (reloadRolesPage) {
87-
setCurrentStage(0, stages, setStages);
88-
reloadRolesPage();
89-
}
90-
navigate("/taas/myteams/createnewteam/role");
59+
navigate("/taas/myteams/createnewteam");
9160
};
9261

9362
const assembleTeam = (formData) => {
@@ -121,7 +90,6 @@ function SubmitContainer({
12190
postTeamRequest(teamObject)
12291
.then((res) => {
12392
const projectId = _.get(res, ["data", "projectId"]);
124-
clearSessionKeys();
12593
dispatch(clearSearchedRoles());
12694
navigate(`/taas/myteams/${projectId}`);
12795
})
@@ -171,8 +139,8 @@ SubmitContainer.propTypes = {
171139
stages: PT.array,
172140
setStages: PT.func,
173141
completenessStyle: PT.string,
174-
reloadRolesPage: PT.bool,
175142
location: PT.object,
143+
addedRoles: PT.array,
176144
};
177145

178146
export default withAuthentication(SubmitContainer);

src/routes/CreateNewTeam/components/SuccessCard/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function SuccessCard() {
3030
Please use the button to the right to submit your request, or the
3131
button below to search for additional roles.
3232
</p>
33-
<Link to="/taas/myteams/createnewteam" state={{ keepAddedRoles: true }}>
33+
<Link to="/taas/myteams/createnewteam">
3434
<Button type="secondary" styleName="button">
3535
Continue Search
3636
</Button>

src/routes/CreateNewTeam/index.jsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
11
/**
22
* Create New Team
33
*
4-
* Gets location state from router to pass
5-
* along to search pages
6-
*
74
* Landing page for creating new teams
85
* by selecting a role, inputting skills,
96
* or inputting a job description
107
*/
118
import React, { useEffect } from "react";
129
import { navigate } from "@reach/router";
1310
import _ from "lodash";
14-
import PT from "prop-types";
15-
import { useDispatch } from "react-redux";
1611
import Page from "components/Page";
1712
import PageHeader from "components/PageHeader";
1813
import LandingBox from "./components/LandingBox";
1914
import IconMultipleActionsCheck from "../../assets/images/icon-multiple-actions-check-2.svg";
2015
import IconListQuill from "../../assets/images/icon-list-quill.svg";
2116
import IconOfficeFileText from "../../assets/images/icon-office-file-text.svg";
22-
import { clearSearchedRoles } from "./actions";
23-
24-
function CreateNewTeam({ location: { state: locationState } }) {
25-
const dispatch = useDispatch();
26-
27-
useEffect(() => {
28-
if (!locationState || !locationState.keepAddedRoles) {
29-
dispatch(clearSearchedRoles());
30-
}
31-
});
3217

18+
function CreateNewTeam() {
3319
const goToRoute = (path) => {
3420
navigate(path);
3521
};
@@ -65,8 +51,4 @@ function CreateNewTeam({ location: { state: locationState } }) {
6551
);
6652
}
6753

68-
CreateNewTeam.propTypes = {
69-
locationState: PT.object,
70-
};
71-
7254
export default CreateNewTeam;

src/routes/CreateNewTeam/pages/InputSkills/components/SkillItem/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import React from "react";
77
import PT from "prop-types";
8-
import IconQuestionCircle from "../../../../../../assets/images/icon-question-circle.svg";
8+
import IconSkill from "../../../../../../assets/images/icon-skill.svg";
99
import "./styles.module.scss";
1010
import cn from "classnames";
1111

@@ -28,7 +28,7 @@ function SkillItem({ id, name, onClick, isSelected }) {
2828
styleName="image"
2929
/>
3030
) : (
31-
<IconQuestionCircle styleName="image" />
31+
<IconSkill styleName="image" />
3232
)}
3333
<p styleName="item-text">{name}</p>
3434
</div>

0 commit comments

Comments
 (0)