mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
Align task pages with access permissions
Use the shared page-permission helper across task routes and gate client creation controls on CREATE_CLIENT. Remove an unused profile permission import.
This commit is contained in:
@@ -9,7 +9,7 @@ import LazyLoading from '@/components/loader/LazyLoading';
|
|||||||
|
|
||||||
import { type IProfile } from './components/type';
|
import { type IProfile } from './components/type';
|
||||||
import { type IUser } from '@/app/admin/administration/user/component/type';
|
import { type IUser } from '@/app/admin/administration/user/component/type';
|
||||||
import { getAccessPagePermission, getCacheServerSession, getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
import { getAccessPagePermission, getCacheServerSession } from '@/lib/get-access-data';
|
||||||
|
|
||||||
const ForgotPassword = lazy(() => import('./components/ForgotPassword'));
|
const ForgotPassword = lazy(() => import('./components/ForgotPassword'));
|
||||||
const ChangeTheme = lazy(() => import("./components/ChangeTheme"))
|
const ChangeTheme = lazy(() => import("./components/ChangeTheme"))
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
|||||||
import { getFilteredAssignments } from '../../../data';
|
import { getFilteredAssignments } from '../../../data';
|
||||||
import { getClientById, getAssignmentsByClient } from '../../../utils/queries';
|
import { getClientById, getAssignmentsByClient } from '../../../utils/queries';
|
||||||
import Reveal from '@/components/ui/reveal';
|
import Reveal from '@/components/ui/reveal';
|
||||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: Promise<{ client_id: string }>
|
params: Promise<{ client_id: string }>
|
||||||
@@ -55,7 +55,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function ClientDetailPage({ params, searchParams }: Props) {
|
export default async function ClientDetailPage({ params, searchParams }: Props) {
|
||||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW_CLIENT')
|
const actions = await getAccessPagePermission('/task', 'VIEW_CLIENT', false)
|
||||||
|
|
||||||
const { client_id } = await params;
|
const { client_id } = await params;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Button } from '@/components/ui/button';
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import AssignmentDetailComponent from './AssignmentDetailComponent';
|
import AssignmentDetailComponent from './AssignmentDetailComponent';
|
||||||
import { getClientById, getAssignmentById } from '../../../utils/queries';
|
import { getClientById, getAssignmentById } from '../../../utils/queries';
|
||||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: Promise<{ client_id: string; assignment_id: string }>
|
params: Promise<{ client_id: string; assignment_id: string }>
|
||||||
@@ -46,7 +46,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function AssignmentDetailPage({ params }: Props) {
|
export default async function AssignmentDetailPage({ params }: Props) {
|
||||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW_ASSIGNMENT')
|
const actions = await getAccessPagePermission('/task', 'VIEW_ASSIGNMENT', false)
|
||||||
|
|
||||||
const { client_id, assignment_id } = await params;
|
const { client_id, assignment_id } = await params;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { Metadata } from 'next';
|
import type { Metadata } from 'next';
|
||||||
import ProjectAssignmentForm from "./ProjectAssignmentForm";
|
import ProjectAssignmentForm from "./ProjectAssignmentForm";
|
||||||
import { getClientById, getAssignmentById } from "../../../utils/queries";
|
import { getClientById, getAssignmentById } from "../../../utils/queries";
|
||||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: Promise<{ client_id?: string }>
|
params: Promise<{ client_id?: string }>
|
||||||
@@ -15,7 +15,7 @@ export async function generateMetadata({ params, searchParams }: Props): Promise
|
|||||||
const assignmentId = typeof resolvedSearchParams?.assignment_id === 'string' ? resolvedSearchParams.assignment_id : undefined;
|
const assignmentId = typeof resolvedSearchParams?.assignment_id === 'string' ? resolvedSearchParams.assignment_id : undefined;
|
||||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||||
|
|
||||||
await getNonAdminAccessPagePermission('/task', isPromote ? 'PROMOTE_ASSIGNMENT' : isEdit ? 'UPDATE_ASSIGNMENT' : 'CREATE_ASSIGNMENT');
|
await getAccessPagePermission('/task', isPromote ? 'PROMOTE_ASSIGNMENT' : isEdit ? 'UPDATE_ASSIGNMENT' : 'CREATE_ASSIGNMENT', false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const clientPromise = client_id ? getClientById(client_id) : Promise.resolve(undefined);
|
const clientPromise = client_id ? getClientById(client_id) : Promise.resolve(undefined);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import FilterComponent from '@/app/(dashboard)/task/component/FilterComponent';
|
|||||||
import { COMPLETE_STATUS_LIST, getFilteredAssignments, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data';
|
import { COMPLETE_STATUS_LIST, getFilteredAssignments, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data';
|
||||||
import { getClientById, getProjectAssignment } from '../../../../utils/queries';
|
import { getClientById, getProjectAssignment } from '../../../../utils/queries';
|
||||||
import Reveal from '@/components/ui/reveal';
|
import Reveal from '@/components/ui/reveal';
|
||||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: Promise<{ client_id: string; project_id: string }>
|
params: Promise<{ client_id: string; project_id: string }>
|
||||||
@@ -18,7 +18,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
|
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
|
||||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW_PROJECT')
|
await getAccessPagePermission('/task', 'VIEW_PROJECT', false)
|
||||||
|
|
||||||
const { client_id, project_id } = await params;
|
const { client_id, project_id } = await params;
|
||||||
const searchParams_ = await searchParams;
|
const searchParams_ = await searchParams;
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ import { calculateOverviewStats } from '../utils/client-overview-helpers';
|
|||||||
|
|
||||||
interface HomeTaskProps {
|
interface HomeTaskProps {
|
||||||
clients?: IClient[];
|
clients?: IClient[];
|
||||||
|
actions?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function HomeTask({ clients = [] }: HomeTaskProps) {
|
export default function HomeTask({ clients = [], actions }: HomeTaskProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [showForm, setShowForm] = useState(false);
|
const [showForm, setShowForm] = useState(false);
|
||||||
|
|
||||||
@@ -60,14 +61,16 @@ export default function HomeTask({ clients = [] }: HomeTaskProps) {
|
|||||||
Complete overview of all clients, projects, personnel and work orders in one place.
|
Complete overview of all clients, projects, personnel and work orders in one place.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3 shrink-0">
|
{actions?.includes("CREATE_CLIENT") &&
|
||||||
<Button
|
<div className="flex items-center gap-3 shrink-0">
|
||||||
className="gap-2 w-full sm:w-auto shrink-0 font-medium"
|
<Button
|
||||||
onClick={() => setShowForm(true)}
|
className="gap-2 w-full sm:w-auto shrink-0 font-medium"
|
||||||
>
|
onClick={() => setShowForm(true)}
|
||||||
<Plus className="w-4 h-4" /> Add Client
|
>
|
||||||
</Button>
|
<Plus className="w-4 h-4" /> Add Client
|
||||||
</div>
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Top Stat Cards (4 Cards Grid) */}
|
{/* Top Stat Cards (4 Cards Grid) */}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export default function Client({ clients, actions, initialLayout = 'grid' }: Cli
|
|||||||
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
||||||
Try to change the filter or create one to get started.
|
Try to change the filter or create one to get started.
|
||||||
</p>
|
</p>
|
||||||
{actions?.includes('CREATE') &&
|
{actions?.includes('CREATE_CLIENT') &&
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { Metadata } from 'next';
|
|||||||
import { getFilteredClients } from './data';
|
import { getFilteredClients } from './data';
|
||||||
import { getClients } from './utils/queries';
|
import { getClients } from './utils/queries';
|
||||||
import { Loader2 } from 'lucide-react';
|
import { Loader2 } from 'lucide-react';
|
||||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||||
|
|
||||||
const HomeTask = lazy(() => import('./component/HomeTask'));
|
const HomeTask = lazy(() => import('./component/HomeTask'));
|
||||||
const Client = lazy(() => import('./component/client/Client'));
|
const Client = lazy(() => import('./component/client/Client'));
|
||||||
@@ -41,7 +41,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function ClientsPage({ searchParams }: Props) {
|
export default async function ClientsPage({ searchParams }: Props) {
|
||||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW')
|
const actions = await getAccessPagePermission('/task', 'VIEW', false)
|
||||||
const searchParams_ = await searchParams;
|
const searchParams_ = await searchParams;
|
||||||
|
|
||||||
// const view = searchParams_.view === 'assignments' ? 'assignments' : 'clients';
|
// const view = searchParams_.view === 'assignments' ? 'assignments' : 'clients';
|
||||||
@@ -64,7 +64,7 @@ export default async function ClientsPage({ searchParams }: Props) {
|
|||||||
<div className="flex-1 space-y-8 p-4 sm:p-8 pt-4 sm:pt-6">
|
<div className="flex-1 space-y-8 p-4 sm:p-8 pt-4 sm:pt-6">
|
||||||
|
|
||||||
<Suspense fallback={<div className='flex justify-center items-center h-48 gap-2'><Loader2 className="animate-spin" />Loading...</div>}>
|
<Suspense fallback={<div className='flex justify-center items-center h-48 gap-2'><Loader2 className="animate-spin" />Loading...</div>}>
|
||||||
<HomeTask clients={allClients} />
|
<HomeTask clients={allClients} actions={actions} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|
||||||
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
||||||
|
|||||||
Reference in New Issue
Block a user