From 1bf1cf1a7185dc9c8c6585323de36b9b262222cf Mon Sep 17 00:00:00 2001 From: Celestin Niyindagiriye Date: Mon, 10 Mar 2025 11:52:43 +0200 Subject: [PATCH] add updates --- .../restful/controllers/ArticleController.ts | 1 + .../ContactActivity/social_medias.ts | 4 +- .../FarmerPlatformActivity/index.tsx | 4 +- .../activities/LandingActivity/index.tsx | 25 ++-- src/modules/admin/BannerActivity/index.tsx | 2 +- .../ManageBanners/AddBanner/index.tsx | 118 +++++++++-------- .../ManageBanners/ViewBanner/index.tsx | 87 +++++++++---- .../_Partials/ManageFile/AddFile/index.tsx | 8 +- .../_Partials/ManageFile/ViewFile/index.tsx | 58 +++++++-- src/pages/api/banners/index.ts | 121 +++++++++++------- src/pages/index.tsx | 17 ++- src/system/static/index.ts | 12 +- 12 files changed, 291 insertions(+), 166 deletions(-) diff --git a/src/apis/restful/controllers/ArticleController.ts b/src/apis/restful/controllers/ArticleController.ts index 78d18a6c..fb57cbc1 100644 --- a/src/apis/restful/controllers/ArticleController.ts +++ b/src/apis/restful/controllers/ArticleController.ts @@ -30,6 +30,7 @@ export default class ArticleController { 'text', 'views', 'updatedAt', + 'createdAt', ], ['firstname', 'lastname', 'profile_image'], ), diff --git a/src/modules/activities/ContactActivity/social_medias.ts b/src/modules/activities/ContactActivity/social_medias.ts index ac5ad52a..20a1da4c 100644 --- a/src/modules/activities/ContactActivity/social_medias.ts +++ b/src/modules/activities/ContactActivity/social_medias.ts @@ -2,7 +2,7 @@ import { Call, Email, Facebook,Twitter, WhatsApp, LinkedIn } from '@mui/icons-ma const social_medias = [ { name:"Facebook", - link:"https://web.facebook.com/YEANAGRO", + link:"https://www.facebook.com/share/g/1C3oFs5joM/?mibextid=wwXIfr", bg_color:"bg-[#4267B2]", logo:Facebook, }, @@ -15,7 +15,7 @@ const social_medias = [ { name:"WhatsApp", - link:"https://api.whatsapp.com/send?phone=250788940434", + link:"https://api.whatsapp.com/send?phone=250792397594", bg_color:"bg-[#00a884]", logo:WhatsApp, }, diff --git a/src/modules/activities/FarmerPlatformActivity/index.tsx b/src/modules/activities/FarmerPlatformActivity/index.tsx index 9fb0838c..c6b5bd41 100644 --- a/src/modules/activities/FarmerPlatformActivity/index.tsx +++ b/src/modules/activities/FarmerPlatformActivity/index.tsx @@ -117,7 +117,7 @@ const FarmerPlatformActivity = () => {
{ ; recentArticles: any[]; recentExtensionMaterials: any[]; slides: any[]; @@ -37,18 +38,20 @@ const LandingAcitivity = ({ const confirmedPartners = partners?.rows; const renderBanners = (section: string) => { - const banner = banners?.find( - banner => banner.section === section, - ); + const banner = banners[section]; if (!banner) return null; return ( -
+
- - + ))}
- {renderBanners('products')} {/* it must be section products */} + {renderBanners('first')} {/* it must be section products */}

Extension Materials @@ -133,7 +136,7 @@ const LandingAcitivity = ({ View More

- {renderBanners('services')} {/* it must be section services */} + {renderBanners('second')} {/* it must be section services */}

Latest Blog @@ -156,7 +159,7 @@ const LandingAcitivity = ({ View More

- {renderBanners('about')} {/* it must be section about */} + {renderBanners('third')} {/* it must be section about */}

Our Partners diff --git a/src/modules/admin/BannerActivity/index.tsx b/src/modules/admin/BannerActivity/index.tsx index 3dfaba83..7c573f2e 100644 --- a/src/modules/admin/BannerActivity/index.tsx +++ b/src/modules/admin/BannerActivity/index.tsx @@ -70,7 +70,7 @@ const BannerActivity: React.FC = () => { // Filter banners based on search input const filteredBanners = React.useMemo(() => { return banners.filter(banner => - banner.title.toLowerCase().includes(filterValue.toLowerCase()), + banner.title?.toLowerCase().includes(filterValue.toLowerCase()), ); }, [banners, filterValue]); diff --git a/src/modules/admin/_Partials/ManageBanners/AddBanner/index.tsx b/src/modules/admin/_Partials/ManageBanners/AddBanner/index.tsx index dea718da..045b5038 100644 --- a/src/modules/admin/_Partials/ManageBanners/AddBanner/index.tsx +++ b/src/modules/admin/_Partials/ManageBanners/AddBanner/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @next/next/no-img-element */ import React, { useState } from 'react'; import { Dialog, @@ -11,38 +12,43 @@ import { MenuItem, FormControl, InputLabel, - Alert + Alert, } from '@mui/material'; import { CloudUpload, Close } from '@mui/icons-material'; import { useDropzone } from 'react-dropzone'; import { Banner } from 'types/types'; +import { useRouter } from 'next/router'; interface AddBannerProps { onAdd: (banner: Banner) => void; children: React.ReactNode; + allowedTypes?: string[]; } interface FormData { - title: string; - url: string; section: string; path: string; image: File | null; } const INITIAL_FORM_STATE: FormData = { - title: '', - url: '', section: '', path: '', image: null, }; -const sections = ['products', 'services', 'about']; +const sections = [1, 2, 3]; -export default function AddBanner({ onAdd, children }: AddBannerProps) { +export default function AddBanner({ + onAdd, + children, + allowedTypes = ['image/png', 'image/jpeg', 'image/gif'], +}: AddBannerProps) { + const router = useRouter(); const [open, setOpen] = useState(false); - const [formData, setFormData] = useState(INITIAL_FORM_STATE); + const [formData, setFormData] = useState( + INITIAL_FORM_STATE, + ); const [isSubmitting, setIsSubmitting] = useState(false); const [previewUrl, setPreviewUrl] = useState(''); const [error, setError] = useState(''); @@ -71,14 +77,13 @@ export default function AddBanner({ onAdd, children }: AddBannerProps) { return; } - setFormData((prev) => ({ ...prev, image: file })); + setFormData(prev => ({ ...prev, image: file })); setPreviewUrl(URL.createObjectURL(file)); setError(''); }; const { getRootProps, getInputProps } = useDropzone({ onDrop, - accept: 'image/*' as any, maxSize: 100 * 1024 * 1024, //100MB }); @@ -88,9 +93,11 @@ export default function AddBanner({ onAdd, children }: AddBannerProps) { setError(''); try { - const { title, url, section, path, image } = formData; - if (!title.trim() || !url.trim() || !section.trim() || !path.trim() || !image) { - throw new Error('Please fill in all required fields completely'); + const { section, path, image } = formData; + if (!section || !image || !path.trim()) { + throw new Error( + 'Please fill in all required fields completely', + ); } const submitFormData = new FormData(); @@ -107,14 +114,19 @@ export default function AddBanner({ onAdd, children }: AddBannerProps) { if (!response.ok) { const errorData = await response.json(); - throw new Error(errorData.message || 'Failed to create banner'); + throw new Error( + errorData.message || 'Failed to create banner', + ); } const newBanner = await response.json(); - onAdd(newBanner); + // onAdd(newBanner); handleClose(); + router.reload(); } catch (err) { - setError(err instanceof Error ? err.message : 'An error occurred'); + setError( + err instanceof Error ? err.message : 'An error occurred', + ); } finally { setIsSubmitting(false); } @@ -143,43 +155,23 @@ export default function AddBanner({ onAdd, children }: AddBannerProps) {
- setFormData((prev) => ({ ...prev, title: e.target.value }))} - required - disabled={isSubmitting} - margin="normal" - variant="outlined" - color="success" - /> - - setFormData((prev) => ({ ...prev, url: e.target.value }))} - required - disabled={isSubmitting} - margin="normal" - variant="outlined" - color="success" - /> - Section @@ -187,20 +179,27 @@ export default function AddBanner({ onAdd, children }: AddBannerProps) { setFormData((prev) => ({ ...prev, path: e.target.value }))} + onChange={e => + setFormData(prev => ({ + ...prev, + path: e.target.value, + })) + } required disabled={isSubmitting} margin="normal" variant="outlined" color="success" + type="url" />

) : (
- + Drag and Drop Banner Image @@ -276,7 +282,7 @@ export default function AddBanner({ onAdd, children }: AddBannerProps) { + */}
-

{data.title}

-
- - {data.section} - - {data.path} -
@@ -239,7 +255,10 @@ const ViewBanner: React.FC = ({ data, onEdit, onDelete }) => { {/* Title Input */}
-