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

fix: issue #124 #129

Merged
merged 2 commits into from
Feb 26, 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
5 changes: 0 additions & 5 deletions config/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ module.exports = {
*/
CONNECT_WEBSITE_URL: "https://connect.topcoder-dev.com",

/**
* Email to request extension
*/
EMAIL_REQUEST_EXTENSION: "customersuccess@topcoder-dev.com",

API: {
V5: "https://api.topcoder-dev.com/v5",
V3: "https://api.topcoder-dev.com/v3",
Expand Down
5 changes: 0 additions & 5 deletions config/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ module.exports = {
*/
CONNECT_WEBSITE_URL: "https://connect.topcoder.com",

/**
* Email to request extension
*/
EMAIL_REQUEST_EXTENSION: "customersuccess@topcoder.com",

API: {
V5: "https://api.topcoder.com/v5",
V3: "https://api.topcoder.com/v3",
Expand Down
21 changes: 21 additions & 0 deletions src/components/EmailPopup/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Report popup actions
*/
import { ACTION_TYPE } from "constants";

/**
* Action to create an email popup and open it
* @param {Object} popupOptions Options to customize popup appearance and behaviour
* @param {Object} data Data to send to server with email text
*/
export const openEmailPopup = (popupOptions, data) => ({
type: ACTION_TYPE.OPEN_EMAIL_POPUP,
payload: { popupOptions, data },
});

/**
* Action to close an email popup
*/
export const closeEmailPopup = () => ({
type: ACTION_TYPE.CLOSE_EMAIL_POPUP,
});
20 changes: 20 additions & 0 deletions src/components/EmailPopup/hooks/useEmailPopup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Use email popup hook
*/

import { useDispatch } from "react-redux";
import { openEmailPopup } from "../actions";

/**
* Hook to allow email popup to be opened by any other component
* (as long as it is mounted somewhere in the tree)
*
* @returns func A wrapper around the open report dispatch
*/
export const useEmailPopup = () => {
const dispatch = useDispatch();

return (popupOptions, data) => {
dispatch(openEmailPopup(popupOptions, data));
};
};
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
/**
* A report popup used to report issues with teams or team members
* An email popup used to format and send emails for reporting issues
* and requesting extensions
*/

import React, { useCallback, useState } from "react";
import _ from "lodash";
import { useSelector, useDispatch } from "react-redux";
import { toastr } from "react-redux-toastr";
import { closeReport } from "./actions";
import { closeEmailPopup } from "./actions";
import BaseModal from "components/BaseModal";
import TextArea from "components/TextArea";
import Button from "../Button";
import { postReport } from "services/teams";
import { postEmail } from "services/teams";
import CenteredSpinner from "components/CenteredSpinner";

function ReportPopup() {
const { isOpen, teamName, teamId, memberHandle } = useSelector(
(state) => state.reportPopup
function EmailPopup() {
const { isOpen, popupOptions, data } = useSelector(
(state) => state.emailPopup
);

const dispatch = useDispatch();
const [textVal, setTextVal] = useState("");
const [isLoading, setIsLoading] = useState(false);

const submitReport = () => {
const submitEmail = () => {
setIsLoading(true);

postReport(teamName, teamId, textVal, memberHandle)
const postData = _.merge({}, data);

_.set(postData, popupOptions.textDataField, textVal);

postEmail(postData)
.then(() => {
setIsLoading(false);
closeModal();
toastr.success("Report submitted successfully");
toastr.success(popupOptions.successTitle);
})
.catch((err) => {
setIsLoading(false);

toastr.error("Report failed", err.message);
toastr.error(popupOptions.errorTitle, err.message);
});
};

const button = (
<Button
onClick={() => submitReport()}
onClick={submitEmail}
size="medium"
isSubmit
disabled={textVal.trim().length < 1 || isLoading}
Expand All @@ -49,17 +55,15 @@ function ReportPopup() {
);

const closeModal = useCallback(() => {
dispatch(closeReport());
dispatch(closeEmailPopup());
setTextVal("");
}, [dispatch]);

return (
<BaseModal
open={isOpen}
onClose={closeModal}
title={`Issue Report - ${teamName}${
memberHandle ? " - " + memberHandle : ""
}`}
title={popupOptions.title}
button={button}
disabled={isLoading}
>
Expand All @@ -69,11 +73,11 @@ function ReportPopup() {
<TextArea
value={textVal}
onChange={setTextVal}
placeholder="Describe your issue"
placeholder={popupOptions.textPlaceholder}
/>
)}
</BaseModal>
);
}

export default ReportPopup;
export default EmailPopup;
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
/**
* Reducer for Report popup
* Reducer for Email popup
*/

import { ACTION_TYPE } from "constants";

const initialState = {
teamName: undefined,
teamId: undefined,
memberHandle: undefined,
isOpen: false,
popupOptions: {
title: "",
textPlaceholder: "",
textDataField: "",
},
data: null,
};

const reducer = (state = initialState, action) => {
switch (action.type) {
case ACTION_TYPE.OPEN_REPORT:
case ACTION_TYPE.OPEN_EMAIL_POPUP:
return {
...state,
...action.payload,
isOpen: true,
};

case ACTION_TYPE.CLOSE_REPORT:
case ACTION_TYPE.CLOSE_EMAIL_POPUP:
return {
...state,
isOpen: false,
Expand Down
22 changes: 0 additions & 22 deletions src/components/ReportPopup/actions/index.js

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/ReportPopup/hooks/useReportPopup.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ export const ACTION_TYPE = {
AUTH_CLEAR_TEAM_MEMBERS: "AUTH_CLEAR_TEAM_MEMBERS",

/*
Report Popup
Email Popup
*/
OPEN_REPORT: "OPEN_REPORT",
CLOSE_REPORT: "CLOSE_REPORT",
OPEN_EMAIL_POPUP: "OPEN_EMAIL_POPUP",
CLOSE_EMAIL_POPUP: "CLOSE_EMAIL_POPUP",

/*
Team (project) Members
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { combineReducers } from "redux";
import { reducer as toastrReducer } from "react-redux-toastr";
import positionDetailsReducer from "../routes/PositionDetails/reducers";
import teamMembersReducer from "../routes/TeamAccess/reducers";
import reportPopupReducer from "../components/ReportPopup/reducers";
import emailPopupReducer from "../components/EmailPopup/reducers";
import authUserReducer from "../hoc/withAuthentication/reducers";

const rootReducer = combineReducers({
toastr: toastrReducer,
positionDetails: positionDetailsReducer,
teamMembers: teamMembersReducer,
reportPopup: reportPopupReducer,
emailPopup: emailPopupReducer,
authUser: authUserReducer,
});

Expand Down
35 changes: 26 additions & 9 deletions src/routes/MyTeamsDetails/components/TeamMembers/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ import { TEAM_MEMBERS_PER_PAGE } from "constants";
import {
formatDateRange,
formatMoney,
formatRequestExtensionUrl,
formatReportData,
formatReportPopup,
formatExtensionData,
formatExtensionPopup,
} from "utils/format";
import Input from "components/Input";
import { skillShape } from "components/SkillsList";
import { useReportPopup } from "components/ReportPopup/hooks/useReportPopup";
import { useEmailPopup } from "components/EmailPopup/hooks/useEmailPopup";
import { hasPermission } from "utils/permissions";
import { PERMISSIONS } from "constants/permissions";

const TeamMembers = ({ team }) => {
const { resources, jobs } = team;
const [filter, setFilter] = useState("");

const showReportPopup = useReportPopup();
const showEmailPopup = useEmailPopup();

const filteredMembers = useMemo(
() =>
Expand Down Expand Up @@ -158,24 +161,38 @@ const TeamMembers = ({ team }) => {
`/taas/myteams/${team.id}/rb/${member.id}/edit`
);
},
hidden: !hasPermission(PERMISSIONS.UPDATE_RESOURCE_BOOKING),
hidden: !hasPermission(
PERMISSIONS.UPDATE_RESOURCE_BOOKING
),
},
{
separator: true,
hidden: !hasPermission(PERMISSIONS.UPDATE_RESOURCE_BOOKING),
hidden: !hasPermission(
PERMISSIONS.UPDATE_RESOURCE_BOOKING
),
},
{
label: "Report an Issue",
action: () => {
showReportPopup(team.name, team.id, member.handle);
showEmailPopup(
formatReportPopup(team.name, member.handle),
formatReportData(
team.name,
team.id,
member.handle
)
);
},
},
{
label: "Request an Extension",
action: () => {
window.open(
formatRequestExtensionUrl(
`Request extension for ${member.handle} on ${team.name}`
showEmailPopup(
formatExtensionPopup(team.name, member.handle),
formatExtensionData(
team.name,
team.id,
member.handle
)
);
},
Expand Down
11 changes: 8 additions & 3 deletions src/routes/MyTeamsDetails/components/TeamSummary/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import {
formatConnectProjectUrl,
formatMoney,
formatRemainingTimeForTeam,
formatReportPopup,
formatReportData,
} from "utils/format";
import IconClock from "../../../../assets/images/icon-clock.svg";
import IconMoney from "../../../../assets/images/icon-money.svg";
// import IconRating from "../../../../assets/images/icon-rating.svg";
import Button from "components/Button";
import { useReportPopup } from "components/ReportPopup/hooks/useReportPopup";
import { useEmailPopup } from "components/EmailPopup/hooks/useEmailPopup";
// import Rating from "components/Rating";
import "./styles.module.scss";

const TeamSummary = ({ team }) => {
const showReportPopup = useReportPopup();
const showReportPopup = useEmailPopup();

return (
<div styleName="team-summary">
Expand Down Expand Up @@ -61,7 +63,10 @@ const TeamSummary = ({ team }) => {
type="warning"
size="medium"
onClick={() => {
showReportPopup(team.name, team.id);
showReportPopup(
formatReportPopup(team.name),
formatReportData(team.name, team.id)
);
}}
target="_blank"
>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/MyTeamsDetails/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TeamSummary from "./components/TeamSummary";
import TeamMembers from "./components/TeamMembers";
import TeamPositions from "./components/TeamPositions";
import withAuthentication from "../../hoc/withAuthentication";
import ReportPopup from "components/ReportPopup";
import EmailPopup from "components/EmailPopup";

const MyTeamsDetails = ({ teamId }) => {
const [team, loadingError] = useData(getTeamById, teamId);
Expand All @@ -36,7 +36,7 @@ const MyTeamsDetails = ({ teamId }) => {
/>
</>
)}
<ReportPopup />
<EmailPopup />
</Page>
);
};
Expand Down
Loading