Skip to content

Commit

Permalink
Merge pull request #17 from ChangePlusPlusVandy/prog-management-page
Browse files Browse the repository at this point in the history
Prog management page
  • Loading branch information
JiashuHarryHuang authored Feb 3, 2024
2 parents 51c2be6 + e238d24 commit db3f518
Show file tree
Hide file tree
Showing 24 changed files with 962 additions and 380 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"printWidth": 80,
"semi": true,
"singleQuote": true,
"tabSize": 2,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
12 changes: 4 additions & 8 deletions components/Application/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ const StatusOptions = styled.select``;

const Option = styled.option``;

const UserApplication = ({
application,
}: {
application: QueriedVolunteerApplicationData;
}) => {
const UserApplication = ({ application }: { application: any }) => {
const [eventLoaded, setEventLoaded] = useState(false);
const [event, setEvent] = useState<QueriedVolunteerEventData>();
const [approvalStatus, setApprovalStatus] = useState('pending');
Expand Down Expand Up @@ -102,7 +98,7 @@ const UserApplication = ({
try {
const approveObject = { updatedStatus: 'rejected', id: application._id };
const path = '/api/applications/updateStatus';
console.log("I'm here!");
// console.log("I'm here!");
await fetch(path, {
method: 'POST',
body: JSON.stringify(approveObject),
Expand Down Expand Up @@ -149,12 +145,12 @@ const UserApplication = ({
<Option value="pending">pending</Option>
</StatusOptions>
</StatusContainer>
{application?.formData.map((item: any) => (
{/* {application?.formData.map((item: any) => (
<ItemContainer key={item.question}>
<Question>{item.question}</Question>
<Response>{item.answer}</Response>
</ItemContainer>
))}
))} */}
</Container>
);
};
Expand Down
4 changes: 2 additions & 2 deletions components/Forms/CreateEventPopupWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const CreateEventPopupWindow = ({
'HH:mm'
)}
onChange={(value, startTime) => {
setStartTime(startTime);
setStartTime(startTime.toString());
console.log(startTime);
}}
/>
Expand All @@ -80,7 +80,7 @@ const CreateEventPopupWindow = ({
'HH:mm'
)}
onChange={(value, endTime) => {
setEndTime(endTime);
setEndTime(endTime.toString());
console.log(endTime);
}}
/>
Expand Down
53 changes: 53 additions & 0 deletions components/Forms/CreateProgramPopupWindow.tsx
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;
4 changes: 2 additions & 2 deletions components/Forms/EditEventPopupWindowForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const EditEventPopupWindowForm = ({
'HH:mm'
)}
onChange={(value, startTime) => {
setStartTime(startTime);
setStartTime(startTime.toString());
console.log(startTime);
}}
/>
Expand All @@ -169,7 +169,7 @@ const EditEventPopupWindowForm = ({
'HH:mm'
)}
onChange={(value, endTime) => {
setEndTime(endTime);
setEndTime(endTime.toString());
console.log(endTime);
}}
/>
Expand Down
1 change: 0 additions & 1 deletion components/table/event-table/EventTableImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ const EventTableImpl = ({
showPopup={showPopup}
setShowPopupTag={setShowPopupTag}
showPopupTag={showPopup}
handleExport={handleExport}
/>
<TableContainer>
<div id="table-container">
Expand Down
5 changes: 2 additions & 3 deletions components/table/event-table/TableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import { SearchContainter, TableButton } from '@/styles/table.styles';
import React from 'react';
import Image from 'next/image';
import { Button } from 'antd';
import { handleExport } from '@/utils/utils';

const TableHeader = ({
setShowPopup,
showPopup,
setShowPopupTag,
showPopupTag,
handleExport,
}: {
setShowPopup: (a: boolean) => void;
showPopup: boolean;
setShowPopupTag: (a: boolean) => void;
showPopupTag: boolean;
handleExport: () => void;
}) => {
return (
<>
Expand Down Expand Up @@ -43,7 +42,7 @@ const TableHeader = ({
/>
</TableButton>
<Button
onClick={handleExport}
onClick={() => handleExport('events')}
style={{
width: 250,
marginLeft: 90,
Expand Down
144 changes: 144 additions & 0 deletions components/table/program-table/ProgramTable.tsx
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;
65 changes: 65 additions & 0 deletions components/table/program-table/ProgramTableImpl.tsx
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;
Loading

0 comments on commit db3f518

Please sign in to comment.