Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9dbc0ed

Browse files
committedFeb 18, 2021
Extracted loading spinner from delete modal to its own component. Finished implementing report popup and connected to API
1 parent 0e354a4 commit 9dbc0ed

File tree

7 files changed

+62
-19
lines changed

7 files changed

+62
-19
lines changed
 
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import PT from 'prop-types'
3+
import Loader from 'react-loader-spinner';
4+
import "./styles.module.scss";
5+
6+
function CenteredSpinner(props) {
7+
const {type = "TailSpin", color = "#00BFFF", height = 80, width = 80} = props;
8+
9+
return (
10+
<div styleName="loader-container">
11+
<Loader type={type} color={color} height={height} width={width} />
12+
</div>
13+
)
14+
}
15+
16+
CenteredSpinner.propTypes = {
17+
type: PT.string,
18+
color: PT.string,
19+
height: PT.number,
20+
width: PT.number
21+
}
22+
23+
export default CenteredSpinner
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.loader-container {
2+
display: flex;
3+
align-items: center;
4+
flex-direction: column;
5+
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export const ACTION_TYPE = {
22
OPEN_REPORT: "OPEN_REPORT",
33
CLOSE_REPORT: "CLOSE_REPORT",
4-
SUBMIT_REPORT: "SUMBIT_REPORT"
54
}
65

76
export const openReport = (teamName, teamId, memberHandle) => ({
@@ -12,7 +11,3 @@ export const openReport = (teamName, teamId, memberHandle) => ({
1211
export const closeReport = () => ({
1312
type: ACTION_TYPE.CLOSE_REPORT
1413
})
15-
16-
export const submitReport = () => ({
17-
type: ACTION_TYPE.SUBMIT_REPORT
18-
})

‎src/components/ReportPopup/hooks/useReportPopup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { openReport } from "../actions";
44
export const useReportPopup = () => {
55
const dispatch = useDispatch();
66

7-
return (teamName, memberHandle) => {
8-
dispatch(openReport(teamName, memberHandle));
7+
return (teamName, teamId, memberHandle) => {
8+
dispatch(openReport(teamName, teamId, memberHandle));
99
}
1010
}

‎src/components/ReportPopup/index.jsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
import React, { useCallback, useState } from 'react'
22
import { useSelector, useDispatch } from 'react-redux';
3-
3+
import { toastr } from "react-redux-toastr";
44
import { closeReport, submitReport } from "./actions";
55
import BaseModal from "components/BaseModal"
66
import TextArea from "components/TextArea"
77
import Button from "../Button";
88
import { postReport } from "services/teams";
9+
import CenteredSpinner from "components/CenteredSpinner";
910

1011

1112

1213
function ReportPopup() {
1314

14-
const {isOpen, teamName, memberHandle } = useSelector(state => state.reportPopup);
15+
const {isOpen, teamName, teamId, memberHandle } = useSelector(state => state.reportPopup);
1516

1617
const dispatch = useDispatch();
1718
const [textVal, setTextVal] = useState("");
18-
const [isDisabled, setIsDisabled] = useState(true);
19+
const [isLoading, setIsLoading] = useState(false);
1920

2021
const submitReport = () => {
21-
22+
setIsLoading(true);
23+
24+
postReport(teamName, teamId, textVal, memberHandle)
25+
.then((res) => {
26+
console.log(res);
27+
setIsLoading(false);
28+
closeModal();
29+
toastr.success("Report submitted successfully")
30+
})
31+
.catch(err => {
32+
setIsLoading(false);
33+
toastr.error("Report failed", err.message);
34+
})
2235
}
2336

24-
const button = <Button onClick={() => closeModal()} size="medium" isSubmit>Submit</Button>
37+
const button = (
38+
<Button
39+
onClick={() => submitReport()}
40+
size="medium"
41+
isSubmit
42+
disabled={textVal.trim().length < 1 || isLoading}
43+
>
44+
Submit
45+
</Button>
46+
)
2547

2648
const closeModal = useCallback(() => {
2749
dispatch(closeReport());
@@ -31,8 +53,8 @@ function ReportPopup() {
3153
<BaseModal
3254
open={isOpen}
3355
onClose={closeModal}
34-
title={`Issue Report - ${teamName}${memberHandle ? " - " + memberHandle : ""}`} button={button} disabled={isDisabled}>
35-
<TextArea value={textVal} onChange={setTextVal}placeholder="Describe your issue" />
56+
title={`Issue Report - ${teamName}${memberHandle ? " - " + memberHandle : ""}`} button={button} disabled={isLoading}>
57+
{isLoading ? <CenteredSpinner /> : <TextArea value={textVal} onChange={setTextVal}placeholder="Describe your issue" /> }
3658
</BaseModal>
3759
)
3860
}

‎src/routes/TeamAccess/components/DeleteModal/index.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { useCallback, useState } from "react";
22
import { useDispatch } from "react-redux";
33
import { toastr } from "react-redux-toastr";
4-
import Loader from "react-loader-spinner";
54
import BaseModal from "components/BaseModal";
65
import Button from "components/Button";
76
import { removeTeamMember, removeInvite } from "../../actions";
87
import "./styles.module.scss";
8+
import CenteredSpinner from "components/CenteredSpinner";
99

1010
const MEMBER_TITLE = "You're about to delete a member from the team";
1111
const INVITE_TITLE = "You're about to remove an invitation";
@@ -101,9 +101,7 @@ function DeleteModal({ selected, open, onClose, teamId, isInvite }) {
101101
disabled={loading}
102102
>
103103
{loading ? (
104-
<div styleName="loader-container">
105-
<Loader type="TailSpin" color="#00BFFF" height={80} width={80} />
106-
</div>
104+
<CenteredSpinner />
107105
) : (
108106
<p>{displayText()}</p>
109107
)}

‎src/services/teams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export const postReport = (teamName, teamId, reportText, memberHandle) => {
178178
template: "team-issue-report",
179179
data: {
180180
projectName: teamName,
181-
projectId: teamId,
181+
projected: teamId,
182182
reportText
183183
}
184184
}

0 commit comments

Comments
 (0)
This repository has been archived.