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

Roles tweaks bugs #352

Merged
merged 2 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ export const ACTION_TYPE = {
ADD_SEARCHED_ROLE: "ADD_SEARCHED_ROLE",
ADD_ROLE_SEARCH_ID: "ADD_ROLE_SEARCH_ID",
DELETE_SEARCHED_ROLE: "DELETE_SEARCHED_ROLE",

/*
* matching role
*/
ADD_MATCHING_ROLE: "ADD_MATCHING_ROLE",
DELETE_MATCHING_ROLE: "DELETE_MATCHING_ROLE",
};

/**
Expand Down
19 changes: 19 additions & 0 deletions src/routes/CreateNewTeam/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const deleteRole = (id) => ({
payload: id,
});

const addMatchingRole = (matchingRole) => ({
type: ACTION_TYPE.ADD_MATCHING_ROLE,
payload: matchingRole,
});

const deleteMatchingRole = (matchingRole) => ({
type: ACTION_TYPE.DELETE_MATCHING_ROLE,
});

export const clearSearchedRoles = () => (dispatch, getState) => {
dispatch(clearRoles());
updateLocalStorage(getState().searchedRoles);
Expand All @@ -46,3 +55,13 @@ export const deleteSearchedRole = (id) => (dispatch, getState) => {
dispatch(deleteRole(id));
updateLocalStorage(getState().searchedRoles);
};

export const saveMatchingRole = (matchingRole) => (dispatch, getState) => {
dispatch(addMatchingRole(matchingRole));
updateLocalStorage(getState().searchedRoles);
};

export const clearMatchingRole = (matchingRole) => (dispatch, getState) => {
dispatch(deleteMatchingRole());
updateLocalStorage(getState().searchedRoles);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.completeness {
@include rounded-card;
overflow: hidden;
padding: 12px;
position: relative;
width: 250px;
Expand All @@ -25,12 +26,19 @@

.list {
margin-bottom: 55px;
& + button[disabled] {
background-color: #E9E9E9;
color: #FFF;
opacity: 1;
filter: none;
}
}

.list-item {
margin-bottom: 14px;
font-size: 14px;
line-height: 16px;
font-weight: 400;

&:before {
content: "";
Expand All @@ -45,14 +53,14 @@
}

&.active {
font-weight: 700;
font-weight: 500;
&:before {
background-color: #fff;
}
}

&.done {
font-weight: 700;
font-weight: 400;
color: rgba(255, 255, 255, 0.6);
&:before {
content: "✓";
Expand Down
53 changes: 53 additions & 0 deletions src/routes/CreateNewTeam/components/InputContainer/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* InputContainer
*
* A container component for the different
* input pages. Contains logic and supporting
* components for selecting for roles.
*/
import React, { useCallback } from "react";
import PT from "prop-types";
import AddedRolesAccordion from "../AddedRolesAccordion";
import Completeness from "../Completeness";
import SearchCard from "../SearchCard";
import ResultCard from "../ResultCard";
import NoMatchingProfilesResultCard from "../NoMatchingProfilesResultCard";
import { isCustomRole } from "utils/helpers";
import "./styles.module.scss";

function InputContainer({
stages,
isCompletenessDisabled,
toRender,
search,
completenessStyle,
addedRoles,
}) {
return (
<div styleName="page">
{toRender(search)}
<div styleName="right-side">
<AddedRolesAccordion addedRoles={addedRoles} />
<Completeness
isDisabled={isCompletenessDisabled}
onClick={search}
extraStyleName={completenessStyle}
buttonLabel={"Search"}
stages={stages}
percentage="26"
/>
</div>
</div>
);
}

InputContainer.propTypes = {
stages: PT.array,
isCompletenessDisabled: PT.bool,
search: PT.func,
toRender: PT.func,
completenessStyle: PT.string,
addedRoles: PT.array,
};

export default InputContainer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.page {
display: flex;
flex-direction: row;
justify-content: center;
align-items: flex-start;
margin: 42px 35px;
.right-side {
display: flex;
flex-direction: column;
& > div:not(:first-child) {
margin-top: 16px;
}
}
}
2 changes: 1 addition & 1 deletion src/routes/CreateNewTeam/components/ItemList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function ItemList({
return (
<div styleName="item-list">
<PageHeader
title={title}
title={<div styleName="title">{title}</div>}
backTo="/taas/createnewteam"
aside={
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
height: 80vh;
overflow-y: auto;

.title {
font-weight: 500;
}
> header {
padding: 16px 24px;
}
Expand Down Expand Up @@ -67,4 +70,4 @@ input:not([type="checkbox"]).filter-input {
justify-content: flex-start;
flex-wrap: wrap;
margin-right: 24px;
}
}
42 changes: 33 additions & 9 deletions src/routes/CreateNewTeam/components/SearchAndSubmit/index.jsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
import { Router } from "@reach/router";
import { Router, navigate } from "@reach/router";
import _ from "lodash";
import React, { useCallback, useState } from "react";
import React, { useCallback, useState, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { searchRoles } from "services/teams";
import { isCustomRole, setCurrentStage } from "utils/helpers";
import { addRoleSearchId, addSearchedRole } from "../../actions";
import { clearMatchingRole, saveMatchingRole, addRoleSearchId, addSearchedRole } from "../../actions";
import InputContainer from "../InputContainer";
import SearchContainer from "../SearchContainer";
import SubmitContainer from "../SubmitContainer";

function SearchAndSubmit(props) {
const { stages, setStages, searchObject, onClick } = props;
const { stages, setStages, searchObject, onClick, page } = props;

const [searchState, setSearchState] = useState(null);
const [matchingRole, setMatchingRole] = useState(null);

const { addedRoles, previousSearchId } = useSelector(
const { matchingRole } = useSelector(
(state) => state.searchedRoles
);

useEffect(()=> {
const isFromInputPage = searchObject.role || searchObject.skills && searchObject.skills.length
|| searchObject.jobDescription
// refresh in search page directly
if (matchingRole && !isFromInputPage) {
setCurrentStage(2, stages, setStages);
setSearchState("done");
}
}, [])

const dispatch = useDispatch();

const { addedRoles, previousSearchId } = useSelector(
(state) => state.searchedRoles
);

const search = useCallback(() => {
navigate(`${page}/search`);
setCurrentStage(1, stages, setStages);
setSearchState("searching");
setMatchingRole(null);
dispatch(clearMatchingRole());
const searchObjectCopy = { ...searchObject };
if (previousSearchId) {
searchObjectCopy.previousRoleSearchRequestId = previousSearchId;
Expand All @@ -37,7 +52,9 @@ function SearchAndSubmit(props) {
} else if (searchId) {
dispatch(addRoleSearchId(searchId));
}
setMatchingRole(res.data);
// setMatchingRole(res.data);

dispatch(saveMatchingRole(res.data));
})
.catch((err) => {
console.error(err);
Expand All @@ -51,11 +68,18 @@ function SearchAndSubmit(props) {

return (
<Router>
<SearchContainer
<InputContainer
path="/"
addedRoles={addedRoles}
previousSearchId={previousSearchId}
search={search}
{...props}
/>
<SearchContainer
path="search"
addedRoles={addedRoles}
previousSearchId={previousSearchId}
search={search}
searchState={searchState}
matchingRole={matchingRole}
{...props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ function SearchContainer({
matchingRole,
}) {
const onSubmit = useCallback(() => {
navigate("result");
navigate("../result");
}, [navigate]);

const renderLeftSide = () => {
if (!searchState) return toRender(search);
if (searchState === "searching") return <SearchCard />;
if (!isCustomRole(matchingRole)) return <ResultCard role={matchingRole} />;
return <NoMatchingProfilesResultCard role={matchingRole} />;
};

const getPercentage = useCallback(() => {
if (!searchState) return "26";
if (searchState === "searching") return "52";
if (matchingRole) return "98";
return "88";
Expand All @@ -52,7 +50,6 @@ function SearchContainer({
<AddedRolesAccordion addedRoles={addedRoles} />
<Completeness
isDisabled={
isCompletenessDisabled ||
searchState === "searching" ||
(searchState === "done" && (!addedRoles || !addedRoles.length))
}
Expand Down
7 changes: 5 additions & 2 deletions src/routes/CreateNewTeam/components/SubmitContainer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ function SubmitContainer({
setRequestLoading(true);
postTeamRequest(teamObject)
.then(() => {
dispatch(clearSearchedRoles());
navigate("/taas/myteams");
setTimeout(() => {
dispatch(clearSearchedRoles());
// Backend api create project has sync issue, so delay 2 seconds
navigate("/taas/myteams");
}, 2000)
})
.catch((err) => {
setRequestLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
return errors;
};

const validateRequired = value => (value ? undefined : 'Please enter a positive integer')

return (
<Form
onSubmit={submitForm}
Expand All @@ -108,7 +110,7 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
changeValue(state, fieldName, () => undefined);
},
}}
initialValues={{ teamName: "My Great Team" }}
initialValues={{ teamName: "" }}
validate={validator}
>
{({
Expand Down Expand Up @@ -181,7 +183,7 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
<tr styleName="role-row" key={id}>
<td>{name}</td>
<td>
<Field name={`${id}.numberOfResources`} initialValue="3">
<Field validate={validateRequired} name={`${id}.numberOfResources`} initialValue="3">
{({ input, meta }) => (
<NumberInput
name={input.name}
Expand All @@ -197,7 +199,7 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
<Error name={`${id}.numberOfResources`} />
</td>
<td>
<Field name={`${id}.durationWeeks`} initialValue="20">
<Field validate={validateRequired} name={`${id}.durationWeeks`} initialValue="20">
{({ input, meta }) => (
<NumberInput
name={input.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
.role-row {
td {
padding: 18px 18px 18px 0;
vertical-align: middle;
vertical-align: top;
@include font-barlow;
font-weight: 600;
font-size: 16px;
Expand Down Expand Up @@ -66,6 +66,7 @@
align-items: center;
justify-content: flex-start;
width: 118px;
margin-top: 13px;
}

.error {
Expand All @@ -79,6 +80,8 @@
border: none;
background: none;

margin-top: 13px;

&:hover {
g {
stroke: red;
Expand Down
Loading