- {
- discussionCommunitites[params.forum as keyof discussionComms]
- .name
- }
+ {forum.name}
{/* Member info */}
-
+
{/* Member Pfps */}
{/* image */}
- {discussionCommunitites[
- params.forum as keyof discussionComms
- ].members
- .slice(0, 3)
- .map((member, idx) => (
-
-
-
- ))}
+
{" "}
{/* Member count */}
-
- {`${
- discussionCommunitites[
- params.forum as keyof discussionComms
- ].members.length
- }`}{" "}
- members
+
+ {forum.members.length} members
{/* Comm description */}
{
- discussionCommunitites[params.forum as keyof discussionComms]
- .description
+ // discussionCommunitites[params.forum as keyof discussionComms]
+ // .description
+
+ forum?.description
}
{/* Start a discussion */}
- {/*
*/}
-
{/* Discussion list */}
- {discussionCommunitites[
- params.forum as keyof discussionComms
- ].discussions.map((item, ifx) => (
- //
+ {forum?.discussions.map((item) => (
))}
diff --git a/app/(mentor)/(dashboard-mentor)/mentor-community/page.tsx b/app/(mentor)/(dashboard-mentor)/mentor-community/page.tsx
index c28fef70..7ed9a224 100644
--- a/app/(mentor)/(dashboard-mentor)/mentor-community/page.tsx
+++ b/app/(mentor)/(dashboard-mentor)/mentor-community/page.tsx
@@ -1,15 +1,42 @@
"use client";
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { DiscussionForums, MentorshipSessions } from "@/components/Community";
import SearchCommunitySearchbar from "@/components/Community/searchcommunity-searchbar";
-import { discussionCommunities } from "./data";
+import { Community, discussionCommunities } from "./data";
import SecondSearchCommunitySearchbar from "@/components/Community/searchcommunity-searchbar2";
import ProtectedRoute from "@/context/ProtectedRoute";
+import { getForums } from "@/lib/apiHelper";
export default function MenteeCommunitiesPage() {
+ const [initialForums, setInitialForums] = useState([
+ {
+ slug: "",
+ name: "",
+ members: [],
+ description: "",
+ discussions: [],
+ },
+ ] as Community[]);
+
+ const [discussionData, setDiscussionData] = useState([
+ {
+ slug: "",
+ name: "",
+ members: [],
+ description: "",
+ discussions: [],
+ },
+ ] as Community[]);
+
+ useEffect(() => {
+ getForums(setInitialForums);
+
+ getForums(setDiscussionData);
+ }, []);
+ console.log(initialForums);
+
// set discussion data to a state
- const [discussionData, setDiscussionData] = useState(discussionCommunities);
// filter part
const [q, setQ] = useState("");
@@ -17,7 +44,7 @@ export default function MenteeCommunitiesPage() {
const filterDiscussions = () => {
if (q) {
// console.log("Search is on. Query: ", q);
- const filteredSliderInfo = discussionCommunities.filter((item) =>
+ const filteredSliderInfo = initialForums.filter((item) =>
item.name.toLowerCase().includes(q.toLowerCase())
);
@@ -42,6 +69,7 @@ export default function MenteeCommunitiesPage() {
/>
{/* Discussion Forums */}
+
void };
+const CreateDiscussionModal: React.FC = ({ onClose }) => {
+ function removeSpacesAndConvertToLower(inputString: string) {
+ // Remove spaces with regex and convert to lowercase
+ const result = inputString.replace(/\s+/g, "").toLowerCase();
+ return result;
+ }
+ // Define state variables for form inputs and image
+
+ const [topic, setTopic] = useState("");
+ const [note, setNote] = useState("");
+ const [image, setImage] = useState(null); // Store the selected image as a File object
+
+ const handleImageChange = (e: React.ChangeEvent) => {
+ const selectedImage = e.target.files?.[0];
+ if (selectedImage) {
+ setImage(selectedImage);
+ }
+ };
+
+ const handlePostDiscussion = () => {
+ // Here, you can use the 'image' state to access the selected image
+ // and send it to the backend, e.g., using FormData.
+
+ // For example, to create a FormData object and append the image:
+
+ const dataPost: Community = {
+ slug: removeSpacesAndConvertToLower(topic),
+ name: topic,
+ description: note,
+ members: [
+ {
+ name: "Member 1",
+ isMentor: true,
+ profilePhotoUrl: "url-to-member-1-photo",
+ },
+ ],
+ discussions: [],
+ };
+ console.log(dataPost);
+
+ // Now, you can send 'formData' to the backend using an HTTP request.
+ // This will send the image data along with other form data.
+ postSingleForum(dataPost);
+
+ setTopic("");
+ setNote("");
+ // Close the modal
+ onClose();
+ };
+ return (
+
+
+
+
+ Start discussion
+
+
+
+
+
+
+
+ );
+};
+
+export default CreateDiscussionModal;
diff --git a/components/Community/ForumCard.tsx b/components/Community/ForumCard.tsx
index b592026c..f39c66ae 100644
--- a/components/Community/ForumCard.tsx
+++ b/components/Community/ForumCard.tsx
@@ -115,7 +115,7 @@ const Forum = ({
ref={discussionRef}
>
-
+
{name}
diff --git a/components/Community/discussion-card.tsx b/components/Community/discussion-card.tsx
index 9a9f5983..880aabc6 100644
--- a/components/Community/discussion-card.tsx
+++ b/components/Community/discussion-card.tsx
@@ -7,6 +7,7 @@ import {
ShareIcon,
} from "@/public/assets/Icons/mentor-communities";
import { Member } from "@/app/(mentor)/(dashboard-mentor)/mentor-community/data";
+import { images } from "@/lib/constants/index";
interface Props {
image?: StaticImageData;
@@ -50,15 +51,11 @@ export default function DiscussionCard({
{/* Image */}
- {author.profilePhotoUrl ? (
-
- ) : (
- ""
- )}
+
{/* name */}
diff --git a/components/Community/startdiscussion-modal.tsx b/components/Community/startdiscussion-modal.tsx
index 3e3cb86a..62c18fa9 100644
--- a/components/Community/startdiscussion-modal.tsx
+++ b/components/Community/startdiscussion-modal.tsx
@@ -38,15 +38,33 @@ const StartDiscussionModal = ({ setIsModalOpen }: Props) => {
}
};
+ function removeSpacesAndConvertToLower(inputString: string) {
+ // Remove spaces with regex and convert to lowercase
+ const result = inputString.replace(/\s+/g, "").toLowerCase();
+ return result;
+ }
const onFormSubmit = (data: FieldValues) => {
// todo send data to backend
console.log("hello there");
console.log("Form Data:", data);
- // await new Promise((resolve) => setTimeout(resolve, 1000));
+ const dataPost = {
+ slug: removeSpacesAndConvertToLower(data.topic),
+ name: data.topic,
+ description: data.topic,
+ members: [
+ {
+ name: "Member 1",
+ isMentor: true,
+ profilePhotoUrl: "url-to-member-1-photo",
+ },
+ ],
+ discussions: [],
+ };
+ console.log(dataPost);
// close modal
- setIsModalOpen((p) => !p);
+ setIsModalOpen(false);
};
// md:max-h-[28.625rem]
return (
@@ -60,7 +78,7 @@ const StartDiscussionModal = ({ setIsModalOpen }: Props) => {
>
{
- setIsModalOpen((p) => !p);
+ setIsModalOpen(true);
console.log("close modal");
}}
@@ -156,7 +174,8 @@ const StartDiscussionModal = ({ setIsModalOpen }: Props) => {