@@ -5,6 +5,7 @@ import { SearchOutlined } from "@ant-design/icons";
5
5
import Highlighter from "react-highlight-words" ;
6
6
import moment from "moment" ;
7
7
import styled , { AnyStyledComponent } from "styled-components" ;
8
+ import { CSVLink } from "react-csv" ;
8
9
9
10
import { IStyles } from "./IStyles" ;
10
11
import { IUser } from "./interfaces" ;
@@ -48,6 +49,11 @@ const ShirtResetButton: AnyStyledComponent = styled.button`
48
49
margin-bottom: 25px;
49
50
` ;
50
51
52
+ const DownloadCSV : AnyStyledComponent = styled . button `
53
+ margin-bottom: 25px;
54
+ float: right;
55
+ ` ;
56
+
51
57
const Membership : React . FC < { } > = ( ) => {
52
58
const {
53
59
loading : memberLoading ,
@@ -327,6 +333,33 @@ const Membership: React.FC<{}> = () => {
327
333
}
328
334
} ;
329
335
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
+
330
363
const getShirtStatus : Function = ( ) => {
331
364
for ( let i = 0 ; i < users . length ; i ++ ) {
332
365
if ( users [ i ] . id === userId ) {
@@ -487,6 +520,10 @@ const Membership: React.FC<{}> = () => {
487
520
Reset Shirt Status
488
521
</ ShirtResetButton >
489
522
523
+ < DownloadCSV >
524
+ { downloadCSV ( ) }
525
+ </ DownloadCSV >
526
+
490
527
< Table dataSource = { users } columns = { columns } />
491
528
< Modal
492
529
visible = { editMembershipVisible }
0 commit comments