From f52e184732bf746dd442378931fa8c55e463df0f Mon Sep 17 00:00:00 2001 From: phurpawangchuk Date: Mon, 15 Jul 2024 22:03:33 -0500 Subject: [PATCH 1/9] React-boostrap added and removed native boostrap --- frontend/src/App.js | 9 ++ .../component/dialogs/ConfirmationDialog.jsx | 23 ++++ .../AcademicResourceType.jsx | 84 ++++++++++++++ .../AcademicResourceTypeList.jsx | 58 ++++++++++ .../AcademicResourceTypeModal.jsx | 42 +++++++ .../academicResources/AcademicResource.jsx | 105 ++++++++++++++++++ .../AcademicResourceList.jsx | 90 +++++++++++++++ .../AcademicResourceModal.jsx | 93 ++++++++++++++++ .../features/dashboard/dashboard-student.jsx | 4 + .../feedbackCategories/FeedbackCategory.jsx | 86 ++++++++++++++ .../FeedbackCategoryList.jsx | 60 ++++++++++ .../FeedbackCategoryModal.jsx | 57 ++++++++++ frontend/src/features/feedbacks/Feedback.jsx | 100 +++++++++++++++++ .../src/features/feedbacks/FeedbackList.jsx | 63 +++++++++++ .../src/features/feedbacks/FeedbackModal.jsx | 77 +++++++++++++ frontend/src/service/apiAcademicResource.js | 82 ++++++++++++++ .../src/service/apiAcademicResourceTypes.js | 34 ++++++ frontend/src/service/apiFeedbackCategory.js | 30 +++++ frontend/src/service/apiFeedbackService.js | 44 ++++++++ frontend/src/types/types.js | 23 ++++ 20 files changed, 1164 insertions(+) create mode 100644 frontend/src/core/component/dialogs/ConfirmationDialog.jsx create mode 100644 frontend/src/features/academicResourceTypes/AcademicResourceType.jsx create mode 100644 frontend/src/features/academicResourceTypes/AcademicResourceTypeList.jsx create mode 100644 frontend/src/features/academicResourceTypes/AcademicResourceTypeModal.jsx create mode 100644 frontend/src/features/academicResources/AcademicResource.jsx create mode 100644 frontend/src/features/academicResources/AcademicResourceList.jsx create mode 100644 frontend/src/features/academicResources/AcademicResourceModal.jsx create mode 100644 frontend/src/features/feedbackCategories/FeedbackCategory.jsx create mode 100644 frontend/src/features/feedbackCategories/FeedbackCategoryList.jsx create mode 100644 frontend/src/features/feedbackCategories/FeedbackCategoryModal.jsx create mode 100644 frontend/src/features/feedbacks/Feedback.jsx create mode 100644 frontend/src/features/feedbacks/FeedbackList.jsx create mode 100644 frontend/src/features/feedbacks/FeedbackModal.jsx create mode 100644 frontend/src/service/apiAcademicResource.js create mode 100644 frontend/src/service/apiAcademicResourceTypes.js create mode 100644 frontend/src/service/apiFeedbackCategory.js create mode 100644 frontend/src/service/apiFeedbackService.js create mode 100644 frontend/src/types/types.js diff --git a/frontend/src/App.js b/frontend/src/App.js index 5f1aa6a2..c41eb9a8 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -4,6 +4,10 @@ import {Route, Routes} from 'react-router'; import Login from './features/authentication/login/Login'; import Register from './features/authentication/register/Register'; import Students from './features/students/Students'; +import FeedbackCategory from './features/feedbackCategories/FeedbackCategory'; +import Feedback from './features/feedbacks/Feedback'; +import AcademicResourceType from './features/academicResourceTypes/AcademicResourceType'; +import AcademicResource from './features/academicResources/AcademicResource'; function App() { return ( @@ -12,6 +16,11 @@ function App() { } /> } /> } /> + + } /> + } /> + } /> + } /> ); } diff --git a/frontend/src/core/component/dialogs/ConfirmationDialog.jsx b/frontend/src/core/component/dialogs/ConfirmationDialog.jsx new file mode 100644 index 00000000..9acb68db --- /dev/null +++ b/frontend/src/core/component/dialogs/ConfirmationDialog.jsx @@ -0,0 +1,23 @@ +import React from 'react'; +import {Modal, Button} from 'react-bootstrap'; + +const ConfirmationDialog = ({show, handleClose, handleConfirm, title, body}) => { + return ( + + + {title} + + {body} + + + + + + ); +}; + +export default ConfirmationDialog; diff --git a/frontend/src/features/academicResourceTypes/AcademicResourceType.jsx b/frontend/src/features/academicResourceTypes/AcademicResourceType.jsx new file mode 100644 index 00000000..aaeb2828 --- /dev/null +++ b/frontend/src/features/academicResourceTypes/AcademicResourceType.jsx @@ -0,0 +1,84 @@ +import React, {useCallback, useEffect, useState} from 'react'; +import {initialAcademicResourceTypeForm as initialForm} from '../../types/types'; +import {getAllApi, saveApi, updateApi} from '../../service/apiAcademicResourceTypes'; +import ErrorDialog from '../../core/component/dialogs/ErrorDialog'; +import AcademicResourceTypeList from './AcademicResourceTypeList'; +import AcademicResourceTypeModal from './AcademicResourceTypeModal'; + +const AcademicResourceType = () => { + const [resourceTypeForm, setResourceTypeForm] = useState(initialForm); + const [resourceTypesList, setResourceTypesList] = useState([]); + const [refresh, setRefresh] = useState(false); + + useEffect(() => { + fetchAcademicResourceTypes(); + }, [refresh]); + + const fetchAcademicResourceTypes = useCallback(async () => { + try { + const data = await getAllApi(); + setResourceTypesList(data); + } catch (error) { + {}} />; + } + }, []); + + const resetForm = () => { + setResourceTypeForm(initialForm); + }; + + const [show, setShow] = useState(false); + + const handleClose = () => { + resetForm(); + setShow(false); + }; + const handleShow = () => setShow(true); + + const handleSave = async event => { + event.preventDefault(); + try { + resourceTypeForm.id > 0 ? await updateApi(resourceTypeForm) : await saveApi(resourceTypeForm); + setRefresh(!refresh); + } catch (error) { + {}} />; + } + resetForm(); + setShow(false); + }; + + const handleChange = event => { + const {name, value} = event.target; + + setResourceTypeForm(prevFeedbackCategoryForm => ({ + ...prevFeedbackCategoryForm, + [name]: value + })); + }; + + return ( +
+ + + + + +
+ ); +}; + +export default AcademicResourceType; diff --git a/frontend/src/features/academicResourceTypes/AcademicResourceTypeList.jsx b/frontend/src/features/academicResourceTypes/AcademicResourceTypeList.jsx new file mode 100644 index 00000000..ea3a1589 --- /dev/null +++ b/frontend/src/features/academicResourceTypes/AcademicResourceTypeList.jsx @@ -0,0 +1,58 @@ +import React from 'react'; +import {deleteApi} from '../../service/apiAcademicResourceTypes'; + +const AcademicResourceTypeList = ({resourceTypesList, setResourceTypeForm, setResourceTypesList, setShow}) => { + const editHandler = id => { + if (id) { + setShow(true); + const result = resourceTypesList.find(cat => cat.id === id); + if (result) { + setResourceTypeForm({ + id: result.id, + name: result.name + }); + } + } + }; + + const deleteHandler = async id => { + try { + const data = await deleteApi(id); + setResourceTypesList(data); + } catch (error) { + console.error('Error deleting feedbackcategory:', error); + } + }; + + return ( +
+ + + + + + + + + + + + {resourceTypesList.map((data, index) => ( + + + + + + + ))} + +
#NameDescription
{index + 1}{data.name} editHandler(data.id)}> + Edit + deleteHandler(data.id)}> + Delete +
+
+ ); +}; + +export default AcademicResourceTypeList; diff --git a/frontend/src/features/academicResourceTypes/AcademicResourceTypeModal.jsx b/frontend/src/features/academicResourceTypes/AcademicResourceTypeModal.jsx new file mode 100644 index 00000000..e6c01b12 --- /dev/null +++ b/frontend/src/features/academicResourceTypes/AcademicResourceTypeModal.jsx @@ -0,0 +1,42 @@ +import React from 'react'; +import {Modal, Button} from 'react-bootstrap'; + +const AcademicResourceTypeModal = ({show, handleClose, handleSave, title, handleChange, resourceTypeForm}) => { + return ( + + + + {resourceTypeForm.id > 0 ? 'Edit ' : 'Add '} + {title} + + + +
+ + +
+
+ + + + + +
+ ); +}; + +export default AcademicResourceTypeModal; diff --git a/frontend/src/features/academicResources/AcademicResource.jsx b/frontend/src/features/academicResources/AcademicResource.jsx new file mode 100644 index 00000000..83a2ef62 --- /dev/null +++ b/frontend/src/features/academicResources/AcademicResource.jsx @@ -0,0 +1,105 @@ +import React, {useCallback, useEffect, useState} from 'react'; +import {initialAcademicForm as initialForm} from '../../types/types'; +import {getAllApi, getAllCategoriesApi, saveApi, updateApi} from '../../service/apiAcademicResource'; +import ErrorDialog from '../../core/component/dialogs/ErrorDialog'; +import AcademicResourceModal from './AcademicResourceModal'; +import AcademicResourceList from './AcademicResourceList'; + +const AcademicResource = () => { + const [academicResForm, setAcademicResForm] = useState(initialForm); + const [academicResourceList, setAcademicResourceList] = useState([]); + const [resCategory, setResCategory] = useState([]); + const [refresh, setRefresh] = useState(false); + + useEffect(() => { + fetchAcademicResource(); + fetchAllCategories(); + }, [refresh]); + + const fetchAcademicResource = useCallback(async () => { + try { + const data = await getAllApi(); + setAcademicResourceList(data); + } catch (error) { + {}} />; + } + }, []); + + const fetchAllCategories = useCallback(async () => { + try { + const data = await getAllCategoriesApi(); + + setResCategory(data); + } catch (error) { + {}} />; + } + }, []); + + const resetForm = () => { + setAcademicResForm(initialForm); + }; + + const [show, setShow] = useState(false); + + const handleClose = () => { + resetForm(); + setShow(false); + }; + + const handleShow = () => setShow(true); + + const handleSave = async event => { + event.preventDefault(); + try { + academicResForm.id > 0 ? await updateApi(academicResForm) : await saveApi(academicResForm); + setRefresh(!refresh); + } catch (error) { + {}} />; + } + resetForm(); + setShow(false); + }; + + const handleChange = event => { + const {name, value, files} = event.target; + + if (name === 'file') { + setAcademicResForm(prevFormData => ({ + ...prevFormData, + file: files[0] + })); + } else { + setAcademicResForm(prevFormData => ({ + ...prevFormData, + [name]: value + })); + } + }; + + return ( +
+ + + + + +
+ ); +}; + +export default AcademicResource; diff --git a/frontend/src/features/academicResources/AcademicResourceList.jsx b/frontend/src/features/academicResources/AcademicResourceList.jsx new file mode 100644 index 00000000..27fa8175 --- /dev/null +++ b/frontend/src/features/academicResources/AcademicResourceList.jsx @@ -0,0 +1,90 @@ +import React, {useState} from 'react'; +import {deleteApi} from '../../service/apiAcademicResource'; +import ConfirmationDialog from '../../core/component/dialogs/ConfirmationDialog'; + +const AcademicResourceList = ({academicResourceList, setAcademicResourceList, setAcademicResForm, setShow}) => { + const [showDialog, setShowDialog] = useState(false); + const [itemToDelete, setItemToDelete] = useState(null); // State to keep track of the item to delete + + const editHandler = id => { + if (id) { + setShow(true); + const result = academicResourceList.find(cat => cat.id === id); + if (result) { + setAcademicResForm({ + id: result.id, + name: result.name, + body: result.body, + resourceCategory: result.resourceType ? result.resourceType.id : '', + file: null + }); + } + } + }; + + const handleConfirmDelete = async () => { + if (itemToDelete) { + try { + const data = await deleteApi(itemToDelete); + setAcademicResourceList(data); + setItemToDelete(null); // Reset the item to delete + } catch (error) { + console.error('Error deleting feedbackcategory:', error); + } + setShowDialog(false); // Close the dialog after deletion + } + }; + + const handleCloseDialog = () => { + setShowDialog(false); + setItemToDelete(null); // Reset the item to delete on dialog close + }; + + const deleteHandler = id => { + setItemToDelete(id); // Set the item to delete + setShowDialog(true); // Show the confirmation dialog + }; + + return ( +
+ + + + + + + + + + + + + {academicResourceList.map((data, index) => ( + + + + + + + + + ))} + +
#NameDescriptionCategory
{index + 1}{data.name}{data.body}{data.resourceType.name} editHandler(data.id)}> + Edit + deleteHandler(data.id)}> + Delete +
+ + +
+ ); +}; + +export default AcademicResourceList; diff --git a/frontend/src/features/academicResources/AcademicResourceModal.jsx b/frontend/src/features/academicResources/AcademicResourceModal.jsx new file mode 100644 index 00000000..1c4c8316 --- /dev/null +++ b/frontend/src/features/academicResources/AcademicResourceModal.jsx @@ -0,0 +1,93 @@ +import React from 'react'; +import {Modal, Button} from 'react-bootstrap'; + +const AcademicResourceModal = ({ + show, + handleClose, + handleSave, + title, + handleChange, + allCategories, + academicResForm +}) => { + return ( + + + + {academicResForm.id > 0 ? 'Edit ' : 'Add '} + {title} + + + +
+ + +
+ +
+ +