-
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.
Merge pull request #17 from ChangePlusPlusVandy/prog-management-page
Prog management page
- Loading branch information
Showing
24 changed files
with
962 additions
and
380 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import PopupWindow from '@/components/PopupWindow'; | ||
import { | ||
CreateEventContainer, | ||
CreateEventForm, | ||
FormLabel, | ||
FormHeader, | ||
InputFlex, | ||
FormInput, | ||
LargeFormInput, | ||
} from '@/styles/components/event.styles'; | ||
import { LongFormInput } from '@/styles/components/editEventPopupWindowForm.styles'; | ||
import { | ||
SubmitButton, | ||
ButtonCenter, | ||
} from '@/styles/components/windowFlow.styles'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
const CreateProgramPopupWindow = ({ | ||
setShowPopup, | ||
}: { | ||
setShowPopup: React.Dispatch<React.SetStateAction<boolean>>; | ||
}) => { | ||
const { handleSubmit } = useForm({}); | ||
const onSubmit = (data: any) => {}; | ||
return ( | ||
<PopupWindow hidePopup={() => setShowPopup(false)}> | ||
<CreateEventContainer> | ||
<CreateEventForm> | ||
<FormHeader>Create Program</FormHeader> | ||
<FormLabel>Program Name</FormLabel> | ||
<InputFlex> | ||
<LongFormInput | ||
type="text" | ||
placeholder="Program Name" | ||
pattern="[A-Za-z]" | ||
title="Input must be text" | ||
/> | ||
</InputFlex> | ||
|
||
<FormLabel>Program Description</FormLabel> | ||
<LargeFormInput placeholder="Program Description" /> | ||
|
||
<ButtonCenter> | ||
<SubmitButton onClick={handleSubmit(onSubmit)}>Create</SubmitButton> | ||
</ButtonCenter> | ||
</CreateEventForm> | ||
</CreateEventContainer> | ||
</PopupWindow> | ||
); | ||
}; | ||
|
||
export default CreateProgramPopupWindow; |
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,144 @@ | ||
import React, { useRef, useState, useEffect } from 'react'; | ||
import Highlighter from 'react-highlight-words'; | ||
import { SearchOutlined } from '@ant-design/icons'; | ||
import { Button, Input, Space, InputRef } from 'antd'; | ||
import type { ColumnType } from 'antd/es/table'; | ||
import type { FilterConfirmProps } from 'antd/es/table/interface'; | ||
import { QueriedVolunteerProgramData } from 'bookem-shared/src/types/database'; | ||
import useSWR from 'swr'; | ||
import { ProgramDataIndex, ProgramRowData } from '@/utils/table-types'; | ||
import { convertProgramDataToRowData } from '@/utils/table-utils'; | ||
import { fetcher } from '@/utils/utils'; | ||
import ProgramTableImpl from './ProgramTableImpl'; | ||
|
||
const ProgramTable = () => { | ||
const { data, error, isLoading, mutate } = useSWR< | ||
QueriedVolunteerProgramData[] | ||
>('/api/program/', fetcher, { | ||
onSuccess: data => { | ||
setDataForTable(convertProgramDataToRowData(data)); | ||
}, | ||
revalidateOnFocus: true, | ||
revalidateOnReconnect: true, | ||
}); | ||
|
||
// Extra defense to refetch data if needed | ||
useEffect(() => { | ||
mutate(); | ||
}, [mutate, data]); | ||
|
||
const [dataForTable, setDataForTable] = useState<ProgramRowData[]>([]); | ||
|
||
const [searchText, setSearchText] = useState(''); | ||
const [searchedColumn, setSearchedColumn] = useState(''); | ||
const searchInput = useRef<InputRef>(null); | ||
|
||
// check for errors and loading | ||
if (error) return <div>Failed to load event table</div>; | ||
if (isLoading) return <div>Loading...</div>; | ||
|
||
const handleSearch = ( | ||
selectedKeys: string[], | ||
confirm: (param?: FilterConfirmProps) => void, | ||
dataIndex: ProgramDataIndex | ||
) => { | ||
confirm(); | ||
setSearchText(selectedKeys[0]); | ||
setSearchedColumn(dataIndex); | ||
}; | ||
|
||
const handleReset = (clearFilters: () => void) => { | ||
clearFilters(); | ||
setSearchText(''); | ||
}; | ||
|
||
const getColumnSearchProps = ( | ||
dataIndex: ProgramDataIndex | ||
): ColumnType<ProgramRowData> => ({ | ||
filterDropdown: ({ | ||
setSelectedKeys, | ||
selectedKeys, | ||
confirm, | ||
clearFilters, | ||
close, | ||
}) => ( | ||
<div style={{ padding: 8 }} onKeyDown={e => e.stopPropagation()}> | ||
<Input | ||
ref={searchInput} | ||
placeholder={`Search ${dataIndex}`} | ||
value={selectedKeys[0]} | ||
onChange={e => | ||
setSelectedKeys(e.target.value ? [e.target.value] : []) | ||
} | ||
onPressEnter={() => | ||
handleSearch(selectedKeys as string[], confirm, dataIndex) | ||
} | ||
style={{ marginBottom: 8, display: 'block' }} | ||
/> | ||
<Space> | ||
<Button | ||
type="primary" | ||
onClick={() => | ||
handleSearch(selectedKeys as string[], confirm, dataIndex) | ||
} | ||
icon="" | ||
size="small" | ||
style={{ width: 90 }}> | ||
Search | ||
</Button> | ||
<Button | ||
onClick={() => clearFilters && handleReset(clearFilters)} | ||
size="small" | ||
style={{ width: 90 }}> | ||
Reset | ||
</Button> | ||
<Button | ||
type="link" | ||
size="small" | ||
onClick={() => { | ||
close(); | ||
}}> | ||
close | ||
</Button> | ||
</Space> | ||
</div> | ||
), | ||
filterIcon: (filtered: boolean) => ( | ||
<SearchOutlined | ||
style={{ color: filtered ? '#1677ff' : undefined }} | ||
rev={undefined} | ||
/> | ||
), | ||
onFilter: (value, record) => | ||
record[dataIndex] | ||
.toString() | ||
.toLowerCase() | ||
.includes((value as string).toLowerCase()), | ||
onFilterDropdownOpenChange: visible => { | ||
if (visible) { | ||
setTimeout(() => searchInput.current?.select(), 100); | ||
} | ||
}, | ||
render: text => | ||
searchedColumn === dataIndex ? ( | ||
<Highlighter | ||
highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }} | ||
searchWords={[searchText]} | ||
autoEscape | ||
textToHighlight={text ? text.toString() : ''} | ||
/> | ||
) : ( | ||
text | ||
), | ||
}); | ||
|
||
return ( | ||
<> | ||
<ProgramTableImpl | ||
getColumnSearchProps={getColumnSearchProps} | ||
dataForTable={dataForTable} | ||
/> | ||
</> | ||
); | ||
}; | ||
export default ProgramTable; |
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,65 @@ | ||
import CreateProgramPopupWindow from '@/components/Forms/CreateProgramPopupWindow'; | ||
import React, { useState } from 'react'; | ||
import TableHeader from './TableHeader'; | ||
import { TableContainer } from '@/styles/table.styles'; | ||
import { Button } from 'antd'; | ||
import { ProgramDataIndex, ProgramRowData } from '@/utils/table-types'; | ||
import { ColumnType, ColumnsType } from 'antd/es/table'; | ||
import { Table } from 'antd'; | ||
|
||
const ProgramTableImpl = ({ | ||
getColumnSearchProps, | ||
dataForTable, | ||
}: { | ||
getColumnSearchProps: ( | ||
dataIndex: ProgramDataIndex | ||
) => ColumnType<ProgramRowData>; | ||
dataForTable: ProgramRowData[]; | ||
}) => { | ||
const [showPopUp, setShowPopUp] = useState(false); | ||
|
||
const columns: ColumnsType<ProgramRowData> = [ | ||
{ | ||
title: 'Program Name', | ||
dataIndex: 'name', | ||
key: 'name', | ||
...getColumnSearchProps('name'), | ||
}, | ||
{ | ||
title: 'Description', | ||
dataIndex: 'description', | ||
key: 'description', | ||
}, | ||
{ | ||
title: 'Number of Events', | ||
dataIndex: 'numEvents', | ||
key: 'numEvents', | ||
}, | ||
{ | ||
title: 'Events', | ||
dataIndex: 'events', | ||
key: 'events', | ||
render: () => <Button type="link">See Events</Button>, | ||
}, | ||
]; | ||
return ( | ||
<> | ||
{showPopUp && <CreateProgramPopupWindow setShowPopup={setShowPopUp} />} | ||
<div> | ||
<TableHeader setShowPopUp={setShowPopUp} showPopUp={showPopUp} /> | ||
<TableContainer> | ||
<div id="table-container"> | ||
<Table | ||
dataSource={dataForTable} | ||
columns={columns} | ||
pagination={false} | ||
scroll={{ y: 550 }} | ||
/> | ||
</div> | ||
</TableContainer> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ProgramTableImpl; |
Oops, something went wrong.