-
Notifications
You must be signed in to change notification settings - Fork 35
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 #160 from bluewave-labs/get-banner-by-id
Editing and Deleting Banners
- Loading branch information
Showing
14 changed files
with
272 additions
and
156 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
59 changes: 0 additions & 59 deletions
59
frontend/src/components/templates/GuideTemplate/GuideTemplate.jsx
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,87 +1,31 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import CreateActivityButton from "../../components/Button/CreateActivityButton/CreateActivityButton"; | ||
import HomePageTemplate from "../../templates/HomePageTemplate/HomePageTemplate"; | ||
import { ACTIVITY_TYPES } from "../../data/CreateActivityButtonData"; | ||
import ParagraphCSS from "../../components/ParagraphCSS/ParagraphCSS"; | ||
import React from 'react'; | ||
import DefaultPageTemplate from '../../templates/DefaultPageTemplate/DefaultPageTemplate'; | ||
import { getBanners, deleteBanner } from '../../services/bannerServices'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import GuideMainPageTemplate from "../../templates/GuideMainPageTemplate/GuideMainPageTemplate"; | ||
import { getBanners } from "../../services/bannerServices"; | ||
import { ACTIVITY_TYPES_INFO } from '../../data/GuideMainPageData'; | ||
|
||
const BannerDefaultPage = () => { | ||
const navigate = useNavigate(); | ||
const [banners, setBanners] = useState([]); | ||
const [selectedItem, setSelectedItem] = useState(null); | ||
const [isPopupOpen, setPopupOpen] = useState(false); | ||
|
||
const handleSelect = (idItem) => { | ||
setSelectedItem(idItem); | ||
}; | ||
|
||
const handleDelete = () => { | ||
setPopupOpen(false); | ||
}; | ||
|
||
const handleOpenPopup = () => { | ||
setPopupOpen(true); | ||
}; | ||
|
||
const handleClosePopup = () => { | ||
setPopupOpen(false); | ||
}; | ||
const getBannerDetails = (banner) => ({ | ||
title: `Banner ${banner.id}`, | ||
text: banner.bannerText, | ||
}); | ||
|
||
const handleCreateItem = () => { | ||
const navigateToCreate = (state) => { | ||
navigate('/banner/create', state); | ||
}; | ||
|
||
const navigateToCreate = () => {navigate('/banner/create')} | ||
|
||
useEffect(() => { | ||
const fetchBanners = async () => { | ||
try { | ||
const bannerData = await getBanners(); | ||
setBanners(bannerData); | ||
} catch (error) { | ||
console.error("Failed to fetch banners:", error); | ||
} | ||
}; | ||
|
||
fetchBanners(); | ||
}, []); | ||
|
||
const style = { | ||
display: "flex", | ||
flexDirection: "column", | ||
width: "100%", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}; | ||
|
||
const items = banners.map(banners => ({ | ||
idItem: banners.id, | ||
title: `Banner ${banners.id}`, | ||
text: banners.bannerText, | ||
onDelete: () => console.log(`Delete banner ${banners.id}`), // Placeholder for delete function | ||
onEdit: () => console.log(`Edit banner ${banners.id}`), // Placeholder for edit function | ||
})); | ||
|
||
return ( | ||
<HomePageTemplate> | ||
{banners.length === 0 ? ( | ||
<div style={style}> | ||
<ParagraphCSS /> | ||
<CreateActivityButton type={ACTIVITY_TYPES.BANNERS} onClick={navigateToCreate} /> | ||
</div> | ||
) : ( | ||
<GuideMainPageTemplate items={items} | ||
handleSelect={handleSelect} | ||
handleDelete={handleDelete} | ||
isPopupOpen={isPopupOpen} | ||
handleClosePopup={handleClosePopup} | ||
type={ACTIVITY_TYPES_INFO.BANNERS} | ||
onClick={navigateToCreate}/> | ||
)} | ||
</HomePageTemplate> | ||
<DefaultPageTemplate | ||
getItems={getBanners} | ||
deleteItem={deleteBanner} | ||
navigateToCreate={navigateToCreate} | ||
itemType={ACTIVITY_TYPES_INFO.BANNERS} | ||
itemTypeInfo={ACTIVITY_TYPES_INFO.BANNERS} | ||
getItemDetails={getBannerDetails} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
export default BannerDefaultPage; |
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
Oops, something went wrong.