diff --git a/components/Forms/AddEventPopupWindow.tsx b/components/Forms/AddEventPopupWindow.tsx new file mode 100644 index 0000000..aeb259d --- /dev/null +++ b/components/Forms/AddEventPopupWindow.tsx @@ -0,0 +1,27 @@ +import React, { useEffect, useState } from 'react'; +import PopupWindow from '@/components/PopupWindow'; +import Image from 'next/image'; +import { ExclamationCircleFilled } from '@ant-design/icons'; +import { QueriedTagData } from 'bookem-shared/src/types/database'; +import useSWR from 'swr'; +import { ObjectId } from 'mongodb'; +import { Modal, message } from 'antd'; +import { fetcher } from '@/utils/utils'; + +const AddEventPopupWindow = ({ + setShowPopup, +}: { + setShowPopup: React.Dispatch>; +}) => { + return ( + <> + {/* ANTD message context holder */} + + setShowPopup(false)}> + <> + + + ); +}; + +export default AddEventPopupWindow; diff --git a/components/Table/EventTable/EventTable.tsx b/components/Table/EventTable/EventTable.tsx index 53d62b7..c02d52a 100644 --- a/components/Table/EventTable/EventTable.tsx +++ b/components/Table/EventTable/EventTable.tsx @@ -1,5 +1,5 @@ import { EventDataIndex, EventRowData } from '@/utils/table-types'; -import { Button, Input, InputRef, Space, TableProps } from 'antd'; +import { Button, Input, InputRef, Space, TableProps, message } from 'antd'; import { SearchOutlined } from '@ant-design/icons'; import { @@ -7,7 +7,7 @@ import { FilterConfirmProps, SorterResult, } from 'antd/es/table/interface'; -import React, { useEffect, useRef, useState } from 'react'; +import React, { createContext, useEffect, useRef, useState } from 'react'; import Highlighter from 'react-highlight-words'; import EventTableImpl from './EventTableImpl'; import useSWR from 'swr'; @@ -17,21 +17,53 @@ import { QueriedVolunteerEventDTO } from 'bookem-shared/src/types/database'; import { useActiveRoute } from '@/lib/useActiveRoute'; import ProgramEventTableImpl from './ProgramEventTableImpl'; +export const EventTableContext = createContext<{ + getColumnSearchProps: (dataIndex: EventDataIndex) => ColumnType; + sortedInfo: SorterResult; + handleChange: TableProps['onChange']; + filteredDataByTags: EventRowData[]; + setFilteredDataByTags: (data: EventRowData[]) => void; + handleFilterByTags: ( + e: React.KeyboardEvent, + dataForTable: EventRowData[] + ) => void; + messageApi: any; + rowSelection: any; + setSelectedRowKeys; +}>({ + getColumnSearchProps: () => ({}), + sortedInfo: {}, + handleChange: () => {}, + filteredDataByTags: [], + setFilteredDataByTags: () => {}, + handleFilterByTags: () => {}, + messageApi: {}, + rowSelection: {}, + setSelectedRowKeys: () => {}, +}); + /** * Contains the "Functionality" part of Event Table including data fetching, search, filter and sort * @returns */ -const EventTable = ({ - programId, - programname, -}: { - programId?: string; - programname?: string; -}) => { +const EventTable = ({ programId }: { programId?: string }) => { const [sortedInfo, setSortedInfo] = useState>({}); const [searchText, setSearchText] = useState(''); const [searchedColumn, setSearchedColumn] = useState(''); const searchInput = useRef(null); + const [messageApi, contextHolder] = message.useMessage(); + const [selectedRowKeys, setSelectedRowKeys] = useState([]); + const onSelectChange = newSelectedRowKeys => { + setSelectedRowKeys(newSelectedRowKeys); + }; + const rowSelection = { + selectedRowKeys, + onChange: onSelectChange, + }; + // const hasSelected = selectedRowKeys.length > 0; + const handleAddEvent = () => { + console.log(selectedRowKeys); + }; // Get current route string const route = useActiveRoute(); @@ -194,25 +226,24 @@ const EventTable = ({ }); return ( <> - {route === '/event' && ( - - )} - {route.startsWith('/events/program') && ( - - )} + {contextHolder} + + {route === '/event' && } + {route.startsWith('/events/program') && ( + + )} + ); }; diff --git a/components/Table/EventTable/EventTableImpl.tsx b/components/Table/EventTable/EventTableImpl.tsx index aa796d3..eb5ab98 100644 --- a/components/Table/EventTable/EventTableImpl.tsx +++ b/components/Table/EventTable/EventTableImpl.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useContext } from 'react'; import { Table, TableProps, @@ -32,34 +32,30 @@ import { FilterIcon, TagTitle, } from '@/styles/components/Table/EventTable.styles'; +import AddEventPopupWindow from '@/components/Forms/AddEventPopupWindow'; import mongoose from 'mongoose'; import { LOCALE_DATE_FORMAT } from '@/utils/constants'; +import { EventTableContext } from './EventTable'; /** * Contains the "UI" part of Event Table * @returns */ -const EventTableImpl = ({ - getColumnSearchProps, - sortedInfo, - handleChange, - filteredDataByTags, - setFilteredDataByTags, - handleFilterByTags, -}: { - getColumnSearchProps: (dataIndex: EventDataIndex) => ColumnType; - sortedInfo: SorterResult; - handleChange: TableProps['onChange']; - filteredDataByTags: EventRowData[]; - setFilteredDataByTags: (data: EventRowData[]) => void; - handleFilterByTags: ( - e: React.KeyboardEvent, - dataForTable: EventRowData[] - ) => void; -}) => { +const EventTableImpl = () => { + const { + getColumnSearchProps, + sortedInfo, + handleChange, + filteredDataByTags, + setFilteredDataByTags, + handleFilterByTags, + messageApi, + rowSelection, + } = useContext(EventTableContext); + const [showPopup, setShowPopup] = useState(false); const [showPopupTag, setShowPopupTag] = useState(false); - const [messageApi, contextHolder] = message.useMessage(); + const [showPopupAdd, setShowPopupAdd] = useState(false); const [dataForTable, setDataForTable] = useState([]); const { data, error, isLoading, mutate } = useSWR( @@ -84,19 +80,6 @@ const EventTableImpl = ({ useEffect(() => { setFilteredDataByTags(dataForTable); }, [dataForTable, setFilteredDataByTags]); - const [selectedRowKeys, setSelectedRowKeys] = useState([]); - - const onSelectChange = newSelectedRowKeys => { - setSelectedRowKeys(newSelectedRowKeys); - }; - const rowSelection = { - selectedRowKeys, - onChange: onSelectChange, - }; - // const hasSelected = selectedRowKeys.length > 0; - const handleAddEvent = () => { - console.log(selectedRowKeys); - }; const handleDeleteEvent = async (_id: mongoose.Types.ObjectId) => { const res = await fetch(`/api/event/${_id}`, { @@ -252,19 +235,19 @@ const EventTableImpl = ({ return ( <> - {contextHolder} {showPopup && } {showPopupTag && } - {/*