forked from fortran-lang/registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
295 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from "react"; | ||
import { BarChart, Bar, XAxis, Tooltip } from "recharts"; | ||
|
||
const PackageRatingGraph = ({ data }) => { | ||
const graphData = data; | ||
|
||
const parsedArray = Object.entries(graphData).map(([key, value]) => ({ | ||
name: `${key} ⭐`, | ||
star: value, | ||
})); | ||
|
||
return parsedArray.length === 0 ? ( | ||
<div> | ||
No stats available right now. This will update as soon as the package gets | ||
rated. | ||
</div> | ||
) : ( | ||
<BarChart width={600} height={500} data={parsedArray}> | ||
<XAxis dataKey="name" /> | ||
<Bar dataKey="star" fill="#8884d8" /> | ||
<Tooltip /> | ||
</BarChart> | ||
); | ||
}; | ||
|
||
export default PackageRatingGraph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Form, Button, Modal, Spinner } from "react-bootstrap"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { | ||
reportPackage, | ||
resetErrorMessage, | ||
} from "../store/actions/reportPackageActions"; | ||
import { toast, ToastContainer } from "react-toastify"; | ||
import { reset } from "../store/actions/accountActions"; | ||
|
||
const ReportPackageForm = (props) => { | ||
const dispatch = useDispatch(); | ||
const [reason, setReason] = useState(""); | ||
const accessToken = useSelector((state) => state.auth.accessToken); | ||
const isLoading = useSelector((state) => state.reportPackage.isLoading); | ||
const statusCode = useSelector((state) => state.reportPackage.statuscode); | ||
const message = useSelector((state) => state.reportPackage.message); | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
dispatch( | ||
reportPackage( | ||
{ reason: reason, namespace: props.namespace, package: props.package }, | ||
accessToken | ||
) | ||
); | ||
}; | ||
|
||
useEffect(() => { | ||
if (statusCode === 200) { | ||
toast.success(message); | ||
} else { | ||
toast.error(message); | ||
} | ||
|
||
dispatch(resetErrorMessage()); | ||
}, [statusCode]); | ||
|
||
return ( | ||
<Form onSubmit={handleSubmit}> | ||
<Modal {...props} size="lg"> | ||
<Modal.Header closeButton> | ||
<Modal.Title>Report Package</Modal.Title> | ||
</Modal.Header> | ||
<ToastContainer | ||
position="top-center" | ||
autoClose={5000} | ||
hideProgressBar={false} | ||
newestOnTop={false} | ||
closeOnClick | ||
rtl={false} | ||
pauseOnFocusLoss | ||
pauseOnHover | ||
theme="light" | ||
/> | ||
<Modal.Body> | ||
<Form.Group | ||
className="mb-3" | ||
controlId="formReportPackage" | ||
id="namespace-description-textfield" | ||
> | ||
<Form.Label>Reason for reporting package</Form.Label> | ||
<Form.Control | ||
type="text" | ||
placeholder="Describe the reason for reporting the package" | ||
as="textarea" | ||
name="report_description" | ||
value={reason} | ||
onChange={(e) => setReason(e.target.value)} | ||
/> | ||
<Form.Text className="text-muted"> | ||
Write a brief description of the reason for reporting the package. | ||
</Form.Text> | ||
</Form.Group> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
{!isLoading ? ( | ||
<Button variant="primary" type="submit" onClick={handleSubmit}> | ||
Submit | ||
</Button> | ||
) : ( | ||
<div style={{ margin: 0 }}> | ||
<Spinner | ||
className="spinner-border m-3" | ||
animation="border" | ||
role="status" | ||
> | ||
<span className="visually-hidden">Loading...</span> | ||
</Spinner> | ||
</div> | ||
)} | ||
</Modal.Footer> | ||
</Modal> | ||
</Form> | ||
); | ||
}; | ||
|
||
export default ReportPackageForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import axios from "axios"; | ||
|
||
export const REPORT_PACKAGE_REQUEST = "REPORT_PACKAGE_REQUEST"; | ||
export const REPORT_PACKAGE_SUCCESS = "REPORT_PACKAGE_SUCCESS"; | ||
export const REPORT_PACKAGE_FAILURE = "REPORT_PACKAGE_FAILURE"; | ||
|
||
export const RESET_ERROR_MESSAGE = "RESET_ERROR_MESSAGE"; | ||
|
||
export const reportPackage = (data, access_token) => async (dispatch) => { | ||
let formData = new FormData(); | ||
formData.append("reason", data.reason); | ||
|
||
let package_name = data.package; | ||
let namespace_name = data.namespace; | ||
|
||
try { | ||
dispatch({ | ||
type: REPORT_PACKAGE_REQUEST, | ||
}); | ||
|
||
const result = await axios({ | ||
method: "post", | ||
url: `${process.env.REACT_APP_REGISTRY_API_URL}/report/${namespace_name}/${package_name}`, | ||
data: formData, | ||
headers: { | ||
Authorization: `Bearer ${access_token}`, | ||
}, | ||
}); | ||
|
||
dispatch({ | ||
type: REPORT_PACKAGE_SUCCESS, | ||
payload: { | ||
message: result.data.message, | ||
statuscode: result.data.code, | ||
}, | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: REPORT_PACKAGE_FAILURE, | ||
payload: { | ||
message: error.response.data.message, | ||
statuscode: error.response.data.code, | ||
}, | ||
}); | ||
} | ||
}; | ||
|
||
export const resetErrorMessage = () => (dispatch) => { | ||
dispatch({ | ||
type: RESET_ERROR_MESSAGE, | ||
}); | ||
}; |
Oops, something went wrong.