From 9c41309c28e89f36c75d5dafbd414c721bca15fc Mon Sep 17 00:00:00 2001
From: Dhiraj Singh <92836453+Dhirajsingh212@users.noreply.github.com>
Date: Tue, 8 Oct 2024 00:03:41 +0530
Subject: [PATCH] feature:Added HR role (#477)
* feature:Added HR role
* feature:Added HR role
---
prisma/schema.prisma | 1 +
prisma/seed.ts | 1 +
src/components/navitem.tsx | 9 +++++++--
src/config/app.config.ts | 1 +
src/layouts/header.tsx | 5 +++--
src/layouts/mobile-nav.tsx | 14 ++++++++++----
src/lib/constant/app.constant.ts | 4 ++--
src/middleware.tsx | 6 +++++-
8 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 1a90c0f0..8aa98268 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -89,6 +89,7 @@ enum WorkMode {
enum Role {
USER
ADMIN
+ HR
}
enum EmployementType {
diff --git a/prisma/seed.ts b/prisma/seed.ts
index 5a47f17f..7a16f7f6 100644
--- a/prisma/seed.ts
+++ b/prisma/seed.ts
@@ -14,6 +14,7 @@ const prisma = new PrismaClient();
const users = [
{ id: '1', name: 'Jack', email: 'user@gmail.com' },
{ id: '2', name: 'Admin', email: 'admin@gmail.com', role: Role.ADMIN },
+ { id: '3', name: 'Hr', email: 'hr@gmail.com', role: Role.HR },
];
let jobs = [
diff --git a/src/components/navitem.tsx b/src/components/navitem.tsx
index 9b90519e..33e159c0 100644
--- a/src/components/navitem.tsx
+++ b/src/components/navitem.tsx
@@ -11,7 +11,7 @@ export const NavItem = ({
}: {
path: string;
label: string;
- roleRequired?: string;
+ roleRequired?: string[];
isPrivate?: boolean;
}) => {
const session = useSession();
@@ -22,7 +22,12 @@ export const NavItem = ({
if (!session.data?.user && isPrivate) {
return;
}
- if (session && roleRequired && session.data?.user.role !== roleRequired) {
+ if (
+ session &&
+ roleRequired &&
+ session.data?.user.role &&
+ !roleRequired.includes(session.data?.user.role)
+ ) {
return;
}
diff --git a/src/config/app.config.ts b/src/config/app.config.ts
index 607f42d6..2e332f78 100644
--- a/src/config/app.config.ts
+++ b/src/config/app.config.ts
@@ -1,4 +1,5 @@
export const ADMIN_ROLE = 'ADMIN';
+export const HR_ROLE = 'HR';
export const USER_ROLE = 'USER';
export const JOBS_PER_PAGE = 10;
export const DEFAULT_PAGE = 1;
diff --git a/src/layouts/header.tsx b/src/layouts/header.tsx
index cf3ecf53..a3c19f54 100644
--- a/src/layouts/header.tsx
+++ b/src/layouts/header.tsx
@@ -12,7 +12,7 @@ import Image from 'next/image';
import { Skeleton } from '@/components/ui/skeleton';
import { Moon, Sun } from 'lucide-react';
import { useTheme } from 'next-themes';
-import { ADMIN_ROLE } from '@/config/app.config';
+import { ADMIN_ROLE, HR_ROLE } from '@/config/app.config';
import { useEffect, useState } from 'react';
import { Button } from '@/components/ui/button';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
@@ -76,7 +76,8 @@ const Header = () => {
HS