Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grab2.9 #835

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ NEXT_PUBLIC_BACKEND_URL=http://localhost:8000

## To use production one please uncomment this one( this is for OSS community)
# NEXT_PUBLIC_BACKEND_URL=https://grabtern-backend-demo.vercel.app


NEXT_PUBLIC_FORNTEND_URL=http://localhost:3000
19 changes: 9 additions & 10 deletions components/basic/TableComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React, { useEffect, useMemo, useState } from "react";
import { useTable } from "react-table";

const TableComponent = ({ sessions, activeTab }) => {
const TableComponent = ({ isMentor, sessions, activeTab }) => {
const [data, setData] = useState([]);

useEffect(() => {
let filteredSessions = [];
if (activeTab?.toLocaleLowerCase() === "pending") {
filteredSessions = sessions.filter((session) => session.isbooked);
} else {
filteredSessions = sessions.filter((session) => !session.isbooked);
}
const filteredSessions = sessions.filter(
(session) =>
(activeTab?.toLocaleLowerCase() === "pending" && session.isbooked) ||
(activeTab?.toLocaleLowerCase() !== "pending" && !session.isbooked),
);
setData(filteredSessions);
}, [activeTab, sessions]);

Expand All @@ -21,8 +20,8 @@ const TableComponent = ({ sessions, activeTab }) => {
accessor: "sessionName",
},
{
Header: "Mentee",
accessor: "userName",
Header: isMentor ? "Mentee" : "Mentor",
accessor: isMentor ? "userName" : "mentorName",
},
{
Header: "Date",
Expand All @@ -33,7 +32,7 @@ const TableComponent = ({ sessions, activeTab }) => {
accessor: "sessionTime",
},
],
[], // Empty dependency array, as columns won't change during the component lifecycle
[isMentor],
);

const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } =
Expand Down
6 changes: 5 additions & 1 deletion components/mentorDashboard/Bookings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ const Bookings = ({ setLoadingState, setErrorState }) => {
{/* sessions list */}
<div className="tw-mt-8">
{sessions ? (
<TableComponent sessions={sessions} activeTab={activeTab} />
<TableComponent
sessions={sessions}
activeTab={activeTab}
isMentor={true}
/>
) : (
<Spinner />
)}
Expand Down
58 changes: 3 additions & 55 deletions components/userDashboard/Bookings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const Bookings = () => {

const tabs = ["Pending", "Completed"];

const tableHeadings = ["Topic", "Mentor", "Day", "Time"];

// session state
const [sessions, setSessions] = useState([]);

Expand All @@ -27,6 +25,7 @@ const Bookings = () => {
withCredentials: true,
},
);
console.log(response.data);
setSessions(response.data);
} catch (error) {
setError(error.response.data.message);
Expand Down Expand Up @@ -55,7 +54,7 @@ const Bookings = () => {
</div>

{/* pending and completed tab */}
<nav className="tw-mb-6">
<nav>
<ul className="tw-flex tw-gap-8 tw-border-b-2">
{tabs.map((tab, index) => (
<li
Expand All @@ -82,64 +81,13 @@ const Bookings = () => {

{sessions ? (
<TableComponent
tableHeadings={tableHeadings}
sessions={sessions}
activeTab={activeTab}
isMentor={false}
/>
) : (
<Spinner />
)}

{/* <div className="tw-mt-8 tw-w-full">
<ul className="tw-bg-primary-100 tw-text-white tw-flex tw-gap-8 tw-items-center tw-w-full tw-py-4 tw-px-8">
<li className="tw-hidden min-[540px]:tw-inline">Topic</li>
<li className="min-[540px]:tw-hidden">Session List</li>
<li className="tw-hidden sm:tw-inline">Mentor</li>
<div className="tw-hidden md:tw-grid md:tw-justify-between md:tw-grid-cols-[5rem_5rem]">
<li>Day</li>
<li className="tw-text-right">Time</li>
</div>
<li className="tw-hidden min-[540px]:tw-inline tw-text-right md:tw-hidden">
Mentoring On
</li>
</ul>
<ul className="tw-bg-white tw-border tw-rounded-b">
{sessions
.filter((session) =>
activeTab.toLocaleLowerCase() === "pending"
? session.isbooked
: !session.isbooked,
)
.map((session, index) => (
<li
key={index}
className="min-[540px]:tw-grid min-[540px]:tw-grid-cols-[auto_7rem] min-[540px]:tw-justify-between sm:tw-justify-normal tw-p-4 sm:tw-grid-cols-[auto_8rem] md:tw-grid-cols-[auto_13rem] tw-text-base-400 tw-border-b last:tw-border-b-0 tw-gap-6"
>
<div className="sm:tw-grid min-[540px]:tw-grid-cols-[auto_8rem] sm:tw-grid-cols-[auto_8rem] tw-gap-6">
<p className="tw-font-medium">{session.sessionName}</p>
<p className="tw-capitalize sm:tw-hidden">
Mentor • {session.userName}
</p>
<p className="tw-capitalize tw-hidden sm:tw-block">
{session.userName}
</p>
</div>
<div>
<div className="md:tw-grid tw-hidden md:tw-grid-cols-[5rem_5rem] md:tw-justify-between">
<p className="tw-capitalize">{session.sessionDay}</p>
<p className="tw-uppercase tw-text-right">
{session.sessionTime}
</p>
</div>
<p className="tw-capitalize min-[540px]:tw-text-right md:tw-hidden">
{session.sessionDay.substring(0, 3)},&nbsp;
{session.sessionTime}
</p>
</div>
</li>
))}
</ul>
</div> */}
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion components/userDashboard/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function Profile({ setLoadingState, setErrorState, user, setUser }) {
border: "2px solid var(--base-300)",
background: "white",
paddingLeft: "35px",
backgroundColor: "var(--base-400)",
backgroundColor: "#f1f1f1",
}}
placeholder={user?.email}
readOnly
Expand Down
101 changes: 81 additions & 20 deletions pages/dashboard/dashboardTour.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import axios from "axios";
import { useTour } from "@reactour/tour";
import Image from "next/image";
import logo from "../../public/logo.png";
Expand Down Expand Up @@ -131,17 +132,48 @@ function UserDashboardTour() {

const { setIsOpen, setSteps, setCurrentStep } = useTour();
useEffect(() => {
setCurrentStep(0);
const userTour = localStorage.getItem("userTour");
if (userTour) return;
setIsOpen(true);
if (window.innerWidth > 768) {
setSteps(desktopSteps);
} else {
setSteps(mobileSteps);
}
localStorage.setItem("userTour", "true");
const fetchVisitedStatus = async () => {
try {
const response = await axios.get(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/dashboard/flags/isVisitedDashboard`,
{
withCredentials: true,
},
);
const isVisitedDashboard = response.data.isVisitedDashboard;
console.log(isVisitedDashboard);

if (!isVisitedDashboard) {
// User has not visited the dashboard, show the tour
setCurrentStep(0);
setIsOpen(true);

if (window.innerWidth > 768) {
setSteps(desktopSteps);
} else {
setSteps(mobileSteps);
}

// Set the status to visited in the backend
await axios.put(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/dashboard/flags/setIsVisitedDashboard`,
{
isVisitedDashboard: true,
},
{
withCredentials: true,
},
);
}
} catch (error) {
console.error("Error fetching or updating visited status:", error);
}
};

fetchVisitedStatus();
}, []);

return null;
}

function MentorDashboardTour() {
Expand Down Expand Up @@ -313,16 +345,45 @@ function MentorDashboardTour() {
];

useEffect(() => {
setCurrentStep(0);
const mentorTour = localStorage.getItem("mentorTour");
if (mentorTour) return;
setIsOpen(true);
if (window.innerWidth > 768) {
setSteps(desktopSteps);
} else {
setSteps(mobileSteps);
}
localStorage.setItem("mentorTour", true);
const fetchVisitedStatus = async () => {
try {
const response = await axios.get(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/dashboard/flags/isVisitedDashboard`,
{
withCredentials: true,
},
);
const isVisitedDashboard = response.data.isVisitedDashboard;
console.log(isVisitedDashboard);

if (!isVisitedDashboard) {
// User has not visited the dashboard, show the tour
setCurrentStep(0);
setIsOpen(true);

if (window.innerWidth > 768) {
setSteps(desktopSteps);
} else {
setSteps(mobileSteps);
}

// Set the status to visited in the backend
await axios.put(
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/dashboard/flags/setIsVisitedDashboard`,
{
isVisitedDashboard: true,
},
{
withCredentials: true,
},
);
}
} catch (error) {
console.error("Error fetching or updating visited status:", error);
}
};

fetchVisitedStatus();
}, []);
}

Expand Down
Loading