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

Commit 07562ba

Browse files
committed
Allow user to delete positions in Team Details popup. Rename Roles to Positions in Added Roles Accordion.
1 parent 4cf54b4 commit 07562ba

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

src/constants/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export const ACTION_TYPE = {
257257
CLEAR_SEARCHED_ROLES: "CLEAR_SEARCHED_ROLES",
258258
ADD_SEARCHED_ROLE: "ADD_SEARCHED_ROLE",
259259
ADD_ROLE_SEARCH_ID: "ADD_ROLE_SEARCH_ID",
260-
REPLACE_SEARCHED_ROLES: "REPLACE_SEARCHED_ROLES",
260+
DELETE_SEARCHED_ROLE: "DELETE_SEARCHED_ROLE",
261261
};
262262

263263
/**

src/routes/CreateNewTeam/actions/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const addPreviousSearchId = (id) => ({
2222
payload: id,
2323
});
2424

25-
export const replaceSearchedRoles = (roles) => ({
26-
type: ACTION_TYPE.REPLACE_SEARCHED_ROLES,
27-
payload: { roles, lastRoleId: roles[roles.length - 1].searchId },
25+
const deleteRole = (id) => ({
26+
type: ACTION_TYPE.DELETE_SEARCHED_ROLE,
27+
payload: id,
2828
});
2929

3030
export const clearSearchedRoles = () => (dispatch, getState) => {
@@ -41,3 +41,8 @@ export const addRoleSearchId = (id) => (dispatch, getState) => {
4141
dispatch(addPreviousSearchId(id));
4242
updateLocalStorage(getState().searchedRoles);
4343
};
44+
45+
export const deleteSearchedRole = (id) => (dispatch, getState) => {
46+
dispatch(deleteRole(id));
47+
updateLocalStorage(getState().searchedRoles);
48+
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function AddedRolesAccordion({ addedRoles }) {
1919
<div styleName="heading">
2020
<h4 styleName="title">
2121
{addedRoles.length}{" "}
22-
{addedRoles.length > 1 ? "roles have" : "role has"} been added.
22+
{addedRoles.length > 1 ? "positions have" : "position has"} been
23+
added.
2324
</h4>
2425
</div>
2526
<div styleName={cn("arrow", { [isOpen ? "up" : "down"]: true })}></div>

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
import React, { useState } from "react";
77
import PT from "prop-types";
88
import { Form, Field, useField } from "react-final-form";
9+
import { useDispatch } from "react-redux";
910
import FormField from "components/FormField";
1011
import BaseCreateModal from "../BaseCreateModal";
1112
import { FORM_FIELD_TYPE } from "constants/";
1213
import { formatPlural } from "utils/format";
1314
import Button from "components/Button";
1415
import MonthPicker from "components/MonthPicker";
1516
import InformationTooltip from "components/InformationTooltip";
17+
import { deleteSearchedRole } from "../../actions";
18+
import IconCrossLight from "../../../../assets/images/icon-cross-light.svg";
1619
import "./styles.module.scss";
1720

1821
const Error = ({ name }) => {
@@ -32,6 +35,8 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
3235
return roles;
3336
});
3437

38+
const dispatch = useDispatch();
39+
3540
const toggleDescription = () => {
3641
setShowDescription((prevState) => !prevState);
3742
};
@@ -169,6 +174,7 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
169174
<th># of resources</th>
170175
<th>Duration (weeks)</th>
171176
<th>Start month</th>
177+
<th></th>
172178
</tr>
173179
{addedRoles.map(({ searchId: id, name }) => (
174180
<tr styleName="role-row" key={id}>
@@ -193,7 +199,7 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
193199
/>
194200
<Error name={`${id}.durationWeeks`} />
195201
</td>
196-
<td styleName="start-month">
202+
<td>
197203
{startMonthVisible[id] ? (
198204
<>
199205
<Field
@@ -231,6 +237,14 @@ function TeamDetailsModal({ open, onClose, submitForm, addedRoles }) {
231237
</div>
232238
)}
233239
</td>
240+
<td>
241+
<button
242+
styleName="delete-role"
243+
onClick={() => dispatch(deleteSearchedRole(id))}
244+
>
245+
<IconCrossLight height="12px" width="12px" />
246+
</button>
247+
</td>
234248
</tr>
235249
))}
236250
</table>

src/routes/CreateNewTeam/components/TeamDetailsModal/styles.module.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
color: #2a2a2a;
4343
border-bottom: 1px solid #e9e9e9;
4444

45-
&.start-month {
45+
&:last-child {
4646
padding-right: 0;
4747
}
4848

@@ -73,6 +73,17 @@
7373
display: block;
7474
}
7575

76+
.delete-role {
77+
border: none;
78+
background: none;
79+
80+
&:hover {
81+
g {
82+
stroke: red;
83+
}
84+
}
85+
}
86+
7687
.modal-body {
7788
textarea {
7889
height: 95px;

src/routes/CreateNewTeam/reducers/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ const loadState = () => {
1818
return defaultState;
1919
}
2020
};
21-
2221
const initialState = loadState();
2322

23+
const deleteRoleInState = (state, deleteId) => {
24+
const filteredRoles = state.addedRoles.filter(
25+
(role) => role.searchId !== deleteId
26+
);
27+
return {
28+
...state,
29+
addedRoles: filteredRoles,
30+
};
31+
};
32+
2433
const reducer = (state = initialState, action) => {
2534
switch (action.type) {
2635
case ACTION_TYPE.CLEAR_SEARCHED_ROLES:
@@ -42,12 +51,8 @@ const reducer = (state = initialState, action) => {
4251
previousSearchId: action.payload,
4352
};
4453

45-
case ACTION_TYPE.REPLACE_SEARCHED_ROLES:
46-
return {
47-
...state,
48-
addedRoles: action.payload.roles,
49-
previousSearchId: action.payload.lastRoleId,
50-
};
54+
case ACTION_TYPE.DELETE_SEARCHED_ROLE:
55+
return deleteRoleInState(state, action.payload);
5156

5257
default:
5358
return state;

0 commit comments

Comments
 (0)