diff --git a/components/Forms/CreateProgramPopupWindow.tsx b/components/Forms/CreateProgramPopupWindow.tsx index 10f29b5..6bca7a3 100644 --- a/components/Forms/CreateProgramPopupWindow.tsx +++ b/components/Forms/CreateProgramPopupWindow.tsx @@ -1,52 +1,117 @@ -import React from 'react'; +import React, { useState } 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'; + LongFormInput, + CreateProgramContainer, +} from '@/styles/components/createProgram.styles'; import { SubmitButton, ButtonCenter, } from '@/styles/components/windowFlow.styles'; import { useForm } from 'react-hook-form'; +import { VolunteerProgramData } from 'bookem-shared/src/types/database'; +import { fetcher } from '@/utils/utils'; +import useSWR from 'swr'; +import { Modal, message } from 'antd'; const CreateProgramPopupWindow = ({ setShowPopup, + messageApi, }: { setShowPopup: React.Dispatch>; + messageApi: any; }) => { - const { handleSubmit } = useForm({}); - const onSubmit = (data: any) => {}; + const { + data: allPrograms, + isLoading, + error, + mutate, // Used to refetch the data + } = useSWR('/api/program/', fetcher, { + onSuccess: data => { + console.log(allPrograms); + }, + }); + // ANTD message + const [programName, setProgramName] = useState(''); + const [programDescription, setProgramDescription] = useState(''); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + // check if the program name already exists + if (allPrograms?.some(p => p.name === programName)) { + messageApi.open({ + type: 'warning', + content: 'Program name already exists.', + }); + } else { + const response = await fetch('/api/program/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + name: programName, + description: programDescription, + }), + }); + if (response.ok) { + const resObj = await response.json(); + console.log(resObj); + messageApi.open({ + type: 'success', + content: resObj.message, + }); + mutate(); + setShowPopup(false); + } else { + messageApi.open({ + type: 'error', + content: 'Failed to create program', + }); + } + } + }; + return ( - setShowPopup(false)}> - - - Create Program - Program Name - - - + <> + setShowPopup(false)}> + + + Create Program + Program Name + + setProgramName(e.target.value)} + maxLength={50} + /> + - Program Description - + Program Description + setProgramDescription(e.target.value)} + maxLength={250} + /> - - Create - - - - + + Create + + + + + ); }; diff --git a/components/table/event-table/EventTableImpl.tsx b/components/table/event-table/EventTableImpl.tsx index e11494b..a78e509 100644 --- a/components/table/event-table/EventTableImpl.tsx +++ b/components/table/event-table/EventTableImpl.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { Table, TableProps, Tag, Input, Popover } from 'antd'; +import { Table, TableProps, Tag, Input, Popover, Button } from 'antd'; import type { ColumnType, ColumnsType, @@ -69,6 +69,19 @@ 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); + }; // check for errors and loading if (error) return
Failed to load event table
; @@ -193,15 +206,21 @@ const EventTableImpl = ({ <> {showPopup && } {showPopupTag && } + {/*