Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
aliamerj committed Mar 7, 2024
1 parent 61d8019 commit 6e92835
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Link from "next/link";
import {
IoAppsOutline,
IoEyeOutline,
IoLockClosedOutline,
IoLockOpenOutline,
} from "react-icons/io5";

Expand All @@ -12,7 +11,7 @@ export const ProjectTypeOptions = ({
}: {
selectedOption: string;
}) => {
const visibilityOptions = ["All", "Public", "Permission", "Private"];
const visibilityOptions = ["All", "Public", "Permission"];
return (
<div className="flex space-x-2 p-4">
{visibilityOptions.map((option) => (
Expand All @@ -39,7 +38,6 @@ const VisibilityOption = ({
All: <IoAppsOutline className="mr-2" />,
Public: <IoEyeOutline className="mr-2" />,
Permission: <IoLockOpenOutline className="mr-2" />,
Private: <IoLockClosedOutline className="mr-2" />,
};

return (
Expand Down
2 changes: 1 addition & 1 deletion app/(main)/components/projects_box/no_project_found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MdSearchOff } from "react-icons/md";
const NoProjectsFound = () => {
return (
<div className="flex h-full flex-col items-center justify-center p-6 text-center">
<MdSearchOff className="mb-4 h-16 w-16 text-blue-500" />
<MdSearchOff className="mb-4 h-16 w-16 text-primary" />
<h2 className="mb-2 text-xl font-bold text-gray-800">
No Projects Found
</h2>
Expand Down
6 changes: 3 additions & 3 deletions app/(main)/components/projects_box/projects_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { IProjectCard, ProjectCard } from "../project_card/project_card";
import { ProjectTypeOptions } from "../project_type_options/project_type_options";
import { Pagination } from "@/global-components/pagination/pagination";
import { databaseDrizzle } from "@/db/database";
import { projectType } from "@/db/schemes/projectSchema";
import getTableCount from "@/utils/api_handler/get_table_count";
import NoProjectsFound from "./no_project_found";
import { ProjectSearch } from "./project_search";
Expand All @@ -18,7 +17,8 @@ export const ProjectsBox = async ({
currentPage: string;
search: string;
}) => {
const types = Object.values(projectType["enumValues"]);

const types = ["public","permission"];
const projectsCount = await getTableCount("project");
const page = parseInt(currentPage) || 1;
const projects: IProjectCard[] = await databaseDrizzle.query.project.findMany(
Expand All @@ -32,7 +32,7 @@ export const ProjectsBox = async ({
)
: visibility && types.includes(visibility.toLowerCase())
? (p, o) => o.eq(p.type, visibility.toLowerCase())
: undefined,
: (p,o)=> o.not(o.eq(p.type, 'private')),
columns: {
id: true,
logo: true,
Expand Down
4 changes: 3 additions & 1 deletion app/(main)/dashboard/[projectId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TaskMangementPage } from "../_component/task_mangement_page/task_mangem
import { parseInt } from "lodash";
import { notFound } from "next/navigation";
import { DashboardProvider } from "../context/dashboard_context";
import NotAllowedPage from "../../project/_components/not_allowed/not_allowed";

interface Props {
params: { projectId: string };
Expand All @@ -18,7 +19,7 @@ export default async function DashboardPage({ params, searchParams }: Props) {
// Retrieve project from database
const projectId = parseInt(params.projectId);
const project = await databaseDrizzle.query.project.findFirst({
where: (p, o) => o.eq(p.id, projectId),
where: (p, o) => o.eq(p.id, projectId,),
with: {
creator: {
columns: {
Expand Down Expand Up @@ -52,6 +53,7 @@ export default async function DashboardPage({ params, searchParams }: Props) {
if (!project) {
return notFound();
}
if(project.type === 'private' && project.owner === session?.user || project.devs.find(d =>d.contributor.id === session?.user.id)) return <NotAllowedPage/>
// Check if the current user is the owner of the project
const isOwner =
session?.user.id === project?.owner ? session?.user.id : undefined;
Expand Down
4 changes: 2 additions & 2 deletions app/(main)/project/_components/not_allowed/not_allowed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const NotAllowedPage = () => {
</p>
<Link
href={AppRouter.signup}
className="inline-block w-full rounded-lg bg-blue-500 px-6 py-3 text-lg text-white transition duration-300 hover:bg-blue-600 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-50"
className="inline-block w-full rounded-lg bg-primary px-6 py-3 text-lg text-white transition duration-300 hover:bg-blue-600 focus:outline-none focus:ring focus:ring-blue-300 focus:ring-opacity-50"
>
Login
</Link>
<Link
href="/" // Replace with your home route
href="/"
className="mt-4 inline-block text-sm text-gray-500 transition duration-300 hover:text-gray-600"
>
Or return to homepage
Expand Down
4 changes: 2 additions & 2 deletions app/(main)/project/_components/project_card/project_card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
FaUnlock,
} from "react-icons/fa";
import getTableCount from "@/utils/api_handler/get_table_count";
import { calcCompletionWithTasks } from "@/utils/helper_function";
import { calcCompletionUnified } from "@/utils/helper_function";

export const ProjectCard = async ({
owner,
Expand All @@ -30,7 +30,7 @@ export const ProjectCard = async ({
const devsCount = await getTableCount("dev", "project_id", id);

const session = await getServerSession(authOptions);
const compilation = calcCompletionWithTasks(features);
const compilation = calcCompletionUnified(features);
const isCreator = owner === session?.user.id;
// const githubLink = `https://github.com/${link}`;

Expand Down
5 changes: 3 additions & 2 deletions app/(main)/project/view/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import NotAllowedPage from "../../_components/not_allowed/not_allowed";
import { ProjectBody } from "../../_components/_view_section/project_body/project_body";
import { ProjectSchema } from "@/utils/validations/projectValidation";
import getTableCount from "@/utils/api_handler/get_table_count";
import { calcCompletionWithTasks } from "@/utils/helper_function";
import { calcCompletionUnified } from "@/utils/helper_function";

interface Props {
params: { id: string };
Expand Down Expand Up @@ -66,11 +66,12 @@ export default async function ProjectViewPage({ params }: Props) {
},
});
if (!project) return notFound();
if(project.type === 'private' && project.owner === session?.user || project.devs.find(d=> d.devId=== session?.user.id)) return <NotAllowedPage/>
const starCount = await getTableCount("star_project");
const devCount = await getTableCount("dev");
const isDev = project?.devs ? project.devs[0]?.devId : null;
const isStared = project?.stars ? project.stars[0]?.userId : null;
const completion = calcCompletionWithTasks(project.features);
const completion = calcCompletionUnified(project.features);

if (project.type === "private") {
if (!session || !session.user.id) return notFound();
Expand Down

0 comments on commit 6e92835

Please sign in to comment.