Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc0b7cb

Browse files
authored
Merge pull request #344 from sigdotcom/feature/download-csv
Added "Download CSV" button to membership tool
2 parents f470023 + a97681b commit dc0b7cb

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

apps/admin-web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"@apollo/react-hooks": "^3.0.0",
77
"@auth0/auth0-spa-js": "^1.2.2",
8+
"@types/react-csv": "^1.1.2",
89
"antd": "^4.1.3",
910
"graphql-tag": "^2.10.1",
1011
"qrcode.react": "^1.0.0",
@@ -48,6 +49,7 @@
4849
"eslint-plugin-react-hooks": "^1.7.0",
4950
"jest-watch-typeahead": "^0.4.0",
5051
"prettier": "^1.18.2",
52+
"react-csv": "^2.0.3",
5153
"typescript": "^3.2.4"
5254
},
5355
"browserslist": [

apps/admin-web/src/screens/Membership/index.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { SearchOutlined } from "@ant-design/icons";
55
import Highlighter from "react-highlight-words";
66
import moment from "moment";
77
import styled, { AnyStyledComponent } from "styled-components";
8+
import { CSVLink } from "react-csv";
89

910
import { IStyles } from "./IStyles";
1011
import { IUser } from "./interfaces";
@@ -48,6 +49,11 @@ const ShirtResetButton: AnyStyledComponent = styled.button`
4849
margin-bottom: 25px;
4950
`;
5051

52+
const DownloadCSV: AnyStyledComponent = styled.button`
53+
margin-bottom: 25px;
54+
float: right;
55+
`;
56+
5157
const Membership: React.FC<{}> = () => {
5258
const {
5359
loading: memberLoading,
@@ -327,6 +333,33 @@ const Membership: React.FC<{}> = () => {
327333
}
328334
};
329335

336+
const downloadCSV = () => {
337+
const fileHeaders = [
338+
{ label: "Name", key: "fullName" },
339+
{ label: "Email", key: "email" },
340+
{ label: "Status", key: "isActive"},
341+
{ label: "Expiration", key: "membershipExpiration"},
342+
{ label: "ACM Shirt", key: "shirtReceived"}
343+
];
344+
const CSVLinkStyles = {
345+
color: "inherit"
346+
};
347+
const formattedUsers = users.map(row => ({
348+
...row,
349+
isActive: statusActive(row.membershipExpiration)
350+
}))
351+
.map(row => ({
352+
...row,
353+
membershipExpiration: moment(row.membershipExpiration).format("MM/DD/YYYY") === "Invalid date" ? "N/A" : moment(row.membershipExpiration).format("MM/DD/YYYY")
354+
}))
355+
.map(row => ({
356+
...row,
357+
shirtReceived: row.shirtReceived ? "Received" : "Not Received"
358+
}));
359+
360+
return <CSVLink style={CSVLinkStyles} data={formattedUsers} headers={fileHeaders} filename={"acm-members.csv"}>Download CSV</CSVLink>;
361+
};
362+
330363
const getShirtStatus: Function = () => {
331364
for (let i = 0; i < users.length; i++) {
332365
if (users[i].id === userId) {
@@ -487,6 +520,10 @@ const Membership: React.FC<{}> = () => {
487520
Reset Shirt Status
488521
</ShirtResetButton>
489522

523+
<DownloadCSV>
524+
{downloadCSV()}
525+
</DownloadCSV>
526+
490527
<Table dataSource={users} columns={columns} />
491528
<Modal
492529
visible={editMembershipVisible}

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,13 @@
30943094
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24"
30953095
integrity sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==
30963096

3097+
"@types/react-csv@^1.1.2":
3098+
version "1.1.2"
3099+
resolved "https://registry.yarnpkg.com/@types/react-csv/-/react-csv-1.1.2.tgz#a5694d7e5cbf4bc1d4baa178a3fa7ac3466ea8c5"
3100+
integrity sha512-hCtZyXAubxBtn3Oi3I9kNAx2liRTaMtl1eWpO2M98aYkHuoSTbYO8OcZEjyr9aJJ30Xnoxj+uES3G6L6O1qgtg==
3101+
dependencies:
3102+
"@types/react" "*"
3103+
30973104
"@types/react-dom@^16.0.11", "@types/react-dom@^16.8.5", "@types/react-dom@^16.9.1":
30983105
version "16.9.8"
30993106
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.9.8.tgz#fe4c1e11dfc67155733dfa6aa65108b4971cb423"
@@ -13961,6 +13968,11 @@ react-app-polyfill@^1.0.6:
1396113968
regenerator-runtime "^0.13.3"
1396213969
whatwg-fetch "^3.0.0"
1396313970

13971+
react-csv@^2.0.3:
13972+
version "2.0.3"
13973+
resolved "https://registry.yarnpkg.com/react-csv/-/react-csv-2.0.3.tgz#f5d17a3c71107d9bcbe580049350200debdc042a"
13974+
integrity sha512-exyAdFLAxtuM4wNwLYrlKyPYLiJ7e0mv9tqPAd3kq+k1CiJFtznevR3yP0icv5q/y200w+lzNgi7TQn1Wrhu0w==
13975+
1396413976
react-dev-utils@^10.2.1:
1396513977
version "10.2.1"
1396613978
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-10.2.1.tgz#f6de325ae25fa4d546d09df4bb1befdc6dd19c19"

0 commit comments

Comments
 (0)