mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
Apply RBAC permissions across admin and tasks
Enforce page access and action-level permissions across admin and task views, including exports and record actions. Move user creation to a client component behind server-side permission checks, standardize data fetching, and remove the deprecated user-role route.
This commit is contained in:
@@ -71,9 +71,10 @@ const ConfirmDeleteWithInput = dynamic(
|
||||
interface Props {
|
||||
clientId: string;
|
||||
assignmentLists: IProjectAssignment[];
|
||||
actions?: string[]
|
||||
}
|
||||
|
||||
export default function ClientDetailComponent({ clientId, assignmentLists }: Props) {
|
||||
export default function ClientDetailComponent({ clientId, assignmentLists, actions }: Props) {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const urlLayout = searchParams?.get('layout') as 'grid' | 'list' | null;
|
||||
|
||||
@@ -9,9 +9,10 @@ import { IClient, CLIENT_FALLBACK_IMAGE } from '../../../types';
|
||||
interface Props {
|
||||
client: IClient;
|
||||
clientId: string;
|
||||
actions?: string[]
|
||||
}
|
||||
|
||||
export default function ClientProfileCard({ client, clientId }: Props) {
|
||||
export default function ClientProfileCard({ client, clientId, actions }: Props) {
|
||||
const isActive = client.status_name?.toLowerCase() === 'active';
|
||||
|
||||
return (
|
||||
@@ -60,12 +61,14 @@ export default function ClientProfileCard({ client, clientId }: Props) {
|
||||
|
||||
{/* Right: + New assignment Button */}
|
||||
<div className="shrink-0 self-start lg:self-center">
|
||||
<Link href={`/task/client-detail/${clientId}/project-assignments`}>
|
||||
<Button className="gap-2 bg-his hover:bg-his/90 text-white font-medium rounded-xl px-5 py-2.5 shadow-sm transition-transform active:scale-[0.98]">
|
||||
<Plus className="h-4 w-4" />
|
||||
<span>New assignment</span>
|
||||
</Button>
|
||||
</Link>
|
||||
{actions?.includes("CREATE") &&
|
||||
<Link href={`/task/client-detail/${clientId}/project-assignments`}>
|
||||
<Button className="gap-2 bg-his hover:bg-his/90 text-white font-medium rounded-xl px-5 py-2.5 shadow-sm transition-transform active:scale-[0.98]">
|
||||
<Plus className="h-4 w-4" />
|
||||
<span>New assignment</span>
|
||||
</Button>
|
||||
</Link>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</Card900>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
||||
import { getFilteredAssignments } from '../../../data';
|
||||
import { getClientById, getAssignmentsByClient } from '../../../utils/queries';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id: string }>
|
||||
@@ -54,6 +55,8 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
}
|
||||
|
||||
export default async function ClientDetailPage({ params, searchParams }: Props) {
|
||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW_CLIENT')
|
||||
|
||||
const { client_id } = await params;
|
||||
|
||||
const searchParams_ = await searchParams;
|
||||
@@ -96,7 +99,7 @@ export default async function ClientDetailPage({ params, searchParams }: Props)
|
||||
</Reveal>
|
||||
|
||||
<Reveal delay={0.04}>
|
||||
<ClientProfileCard client={client} clientId={client_id} />
|
||||
<ClientProfileCard client={client} clientId={client_id} actions={actions} />
|
||||
</Reveal>
|
||||
|
||||
<ClientDetailComponent
|
||||
|
||||
+87
-73
@@ -72,6 +72,7 @@ const UpdateRealProgressModal = dynamic(
|
||||
interface Props {
|
||||
client: IClient | undefined;
|
||||
initialAssignment: IProjectAssignment;
|
||||
actions?: string[]
|
||||
}
|
||||
|
||||
const TEAM_PREVIEW_LIMIT = 5;
|
||||
@@ -90,7 +91,7 @@ function formatSpan(start?: string | null, end?: string | null) {
|
||||
return parts.length ? parts.join(' ') : 'Same day';
|
||||
}
|
||||
|
||||
export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) {
|
||||
export default function AssignmentDetail({ client, initialAssignment: assignment, actions }: Props) {
|
||||
const router = useRouter();
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | 'UPDATE_REAL_PROGRESS' | undefined>();
|
||||
const [showAllTeam, setShowAllTeam] = useState(false);
|
||||
@@ -201,7 +202,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
{/* Action Buttons: Keep Promote to Project (if IM), Update Technical Status, Update Admin Status */}
|
||||
{/* Action Buttons: Administration & Technical status (+ Promote if IM) */}
|
||||
<div className="flex flex-wrap sm:flex-nowrap items-center gap-2.5 w-full md:w-auto shrink-0">
|
||||
{!isWorkOrder && (
|
||||
{!isWorkOrder && actions?.includes('PROMOTE_ASSIGNMENT') && (
|
||||
<Button
|
||||
variant="outline"
|
||||
asChild
|
||||
@@ -213,21 +214,25 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setAction('UPDATE_ADMIN_STATUS')}
|
||||
className="w-full sm:w-auto shrink-0 gap-2 transition-transform active:scale-[0.98]"
|
||||
>
|
||||
<ClipboardCheck className="h-4 w-4 text-his" />
|
||||
Update Administration Status
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => setAction('UPDATE_STATUS')}
|
||||
className="w-full sm:w-auto shrink-0 gap-2 bg-[#ea512c] hover:bg-[#ea512c]/90 text-white font-medium shadow-md shadow-[#ea512c]/20 transition-transform active:scale-[0.98]"
|
||||
>
|
||||
<Clock className="h-4 w-4" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
{actions?.includes('UPDATE_ADMINISTRATION_STATUS') &&
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setAction('UPDATE_ADMIN_STATUS')}
|
||||
className="w-full sm:w-auto shrink-0 gap-2 transition-transform active:scale-[0.98]"
|
||||
>
|
||||
<ClipboardCheck className="h-4 w-4 text-his" />
|
||||
Update Administration Status
|
||||
</Button>
|
||||
}
|
||||
{actions?.includes("UPDATE_TECHNICAL_STATUS") &&
|
||||
<Button
|
||||
onClick={() => setAction('UPDATE_STATUS')}
|
||||
className="w-full sm:w-auto shrink-0 gap-2 bg-[#ea512c] hover:bg-[#ea512c]/90 text-white font-medium shadow-md shadow-[#ea512c]/20 transition-transform active:scale-[0.98]"
|
||||
>
|
||||
<Clock className="h-4 w-4" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -254,17 +259,19 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<span className="font-mono text-sm font-extrabold text-foreground">
|
||||
{assignment.progress ?? 0}%
|
||||
</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setAction('UPDATE_REAL_PROGRESS')}
|
||||
className="h-6.5 px-2 text-[11px] font-medium hover:border-his/40 hover:bg-his hover:text-white transition-all shadow-2xs gap-1"
|
||||
title="Update real progress and notes"
|
||||
>
|
||||
<Pencil className="size-3" />
|
||||
<span>Update</span>
|
||||
</Button>
|
||||
{actions?.includes("UPDATE_ASSIGNMENT_PROGRESS") &&
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setAction('UPDATE_REAL_PROGRESS')}
|
||||
className="h-6.5 px-2 text-[11px] font-medium hover:border-his/40 hover:bg-his hover:text-white transition-all shadow-2xs gap-1"
|
||||
title="Update real progress and notes"
|
||||
>
|
||||
<Pencil className="size-3" />
|
||||
<span>Update</span>
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative h-2.5 w-full overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700/50">
|
||||
@@ -375,6 +382,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
<DevelopmentActivityLog
|
||||
history={assignment.project_assignment_history}
|
||||
assignmentId={assignment.id}
|
||||
actions={actions}
|
||||
assignmentName={assignmentName}
|
||||
assignmentCode={assignmentCode}
|
||||
onLogAdded={() => router.refresh()}
|
||||
@@ -542,14 +550,12 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
Add people from the team directory to start tracking who works on this assignment.
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => setAction('MANAGE_EMPLOYEE')}
|
||||
size="sm"
|
||||
className="mt-2 gap-1.5 transition-transform active:scale-[0.98]"
|
||||
>
|
||||
<UserPlus className="h-4 w-4" />
|
||||
Assign member
|
||||
</Button>
|
||||
{actions?.includes("MANAGE_TEAM") &&
|
||||
<Button onClick={() => setAction('MANAGE_EMPLOYEE')} size="sm" className="mt-2 gap-1.5 transition-transform active:scale-[0.98]" >
|
||||
<UserPlus className="h-4 w-4" />
|
||||
Assign member
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
@@ -600,48 +606,56 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
|
||||
)}
|
||||
</Surface>
|
||||
</Reveal>
|
||||
</div>
|
||||
</div >
|
||||
|
||||
{/* Modals */}
|
||||
{action === 'UPDATE_ADMIN_STATUS' ? (
|
||||
<UpdateAdministrationStatus
|
||||
assignmentId={assignment.id}
|
||||
assignment={assignment}
|
||||
onClose={handleClose}
|
||||
onSuccess={() => {
|
||||
router.refresh();
|
||||
handleClose();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{
|
||||
action === 'UPDATE_ADMIN_STATUS' ? (
|
||||
<UpdateAdministrationStatus
|
||||
assignmentId={assignment.id}
|
||||
assignment={assignment}
|
||||
onClose={handleClose}
|
||||
onSuccess={() => {
|
||||
router.refresh();
|
||||
handleClose();
|
||||
}}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
|
||||
{action === 'UPDATE_STATUS' ? (
|
||||
<UpdateTechnicalStatus assignmentId={assignment.id} onClose={handleClose} />
|
||||
) : null}
|
||||
{
|
||||
action === 'UPDATE_STATUS' ? (
|
||||
<UpdateTechnicalStatus assignmentId={assignment.id} onClose={handleClose} />
|
||||
) : null
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' ? (
|
||||
<ManageTeam
|
||||
assignmentId={assignment.id}
|
||||
onClose={handleClose}
|
||||
startDate={assignment.wo_start_date || assignment.im_start_date}
|
||||
endDate={assignment.wo_end_date || assignment.im_end_date}
|
||||
/>
|
||||
) : null}
|
||||
{
|
||||
action === 'MANAGE_EMPLOYEE' ? (
|
||||
<ManageTeam
|
||||
assignmentId={assignment.id}
|
||||
onClose={handleClose}
|
||||
startDate={assignment.wo_start_date || assignment.im_start_date}
|
||||
endDate={assignment.wo_end_date || assignment.im_end_date}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
|
||||
{action === 'UPDATE_REAL_PROGRESS' ? (
|
||||
<UpdateRealProgressModal
|
||||
assignmentId={assignment.id}
|
||||
assignmentName={assignmentName}
|
||||
assignmentCode={assignmentCode}
|
||||
currentProgress={assignment.progress}
|
||||
open={action === 'UPDATE_REAL_PROGRESS'}
|
||||
onClose={handleClose}
|
||||
onSuccess={() => {
|
||||
router.refresh();
|
||||
handleClose();
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{
|
||||
action === 'UPDATE_REAL_PROGRESS' ? (
|
||||
<UpdateRealProgressModal
|
||||
assignmentId={assignment.id}
|
||||
assignmentName={assignmentName}
|
||||
assignmentCode={assignmentCode}
|
||||
currentProgress={assignment.progress}
|
||||
open={action === 'UPDATE_REAL_PROGRESS'}
|
||||
onClose={handleClose}
|
||||
onSuccess={() => {
|
||||
router.refresh();
|
||||
handleClose();
|
||||
}}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
+6
-7
@@ -20,6 +20,7 @@ const AddActivityLogModal = dynamic(
|
||||
|
||||
interface DevelopmentActivityLogProps {
|
||||
history?: IProjectAssignmentHistory[];
|
||||
actions?: string[]
|
||||
assignmentId?: number;
|
||||
assignmentName?: string;
|
||||
assignmentCode?: string;
|
||||
@@ -28,6 +29,7 @@ interface DevelopmentActivityLogProps {
|
||||
|
||||
export function DevelopmentActivityLog({
|
||||
history = [],
|
||||
actions,
|
||||
assignmentId,
|
||||
assignmentName,
|
||||
assignmentCode,
|
||||
@@ -87,11 +89,8 @@ export function DevelopmentActivityLog({
|
||||
)}
|
||||
</h2>
|
||||
|
||||
{assignmentId && (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
onClick={() => setIsAddModalOpen(true)}
|
||||
{assignmentId && actions?.includes("CREATE_ACTIVITY_LOG") && (
|
||||
<Button type="button" size="sm" onClick={() => setIsAddModalOpen(true)}
|
||||
className="h-8 gap-1.5 bg-his hover:bg-his/90 text-white font-medium text-xs shadow-xs transition-transform active:scale-[0.98]"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" />
|
||||
@@ -220,8 +219,8 @@ export function DevelopmentActivityLog({
|
||||
size="sm"
|
||||
onClick={() => setCurrentPage(pageNum)}
|
||||
className={`h-7 w-7 p-0 text-xs font-mono ${pageNum === safeCurrentPage
|
||||
? 'bg-his text-white hover:bg-his/90'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
? 'bg-his text-white hover:bg-his/90'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{pageNum}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Button } from '@/components/ui/button';
|
||||
import Link from 'next/link';
|
||||
import AssignmentDetailComponent from './AssignmentDetailComponent';
|
||||
import { getClientById, getAssignmentById } from '../../../utils/queries';
|
||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id: string; assignment_id: string }>
|
||||
@@ -45,6 +46,8 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
}
|
||||
|
||||
export default async function AssignmentDetailPage({ params }: Props) {
|
||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW_ASSIGNMENT')
|
||||
|
||||
const { client_id, assignment_id } = await params;
|
||||
|
||||
const [client, assignment] = await Promise.all([getClientById(client_id), getAssignmentById(assignment_id)]);
|
||||
@@ -63,6 +66,6 @@ export default async function AssignmentDetailPage({ params }: Props) {
|
||||
|
||||
// Pass the fetched data to the interactive Client Component
|
||||
return (
|
||||
<AssignmentDetailComponent client={client} initialAssignment={assignment} />
|
||||
<AssignmentDetailComponent client={client} initialAssignment={assignment} actions={actions} />
|
||||
);
|
||||
}
|
||||
|
||||
+65
-57
@@ -51,9 +51,10 @@ interface WorkOrderCardProps {
|
||||
workOrder: IProjectAssignment;
|
||||
index: number;
|
||||
defaultOpen?: boolean;
|
||||
actions?: string[]
|
||||
}
|
||||
|
||||
export default function WorkOrderCard({ workOrder, index, defaultOpen = false }: WorkOrderCardProps) {
|
||||
export default function WorkOrderCard({ workOrder, index, defaultOpen = false, actions }: WorkOrderCardProps) {
|
||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
||||
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | undefined>();
|
||||
const [selectedData, setSelectedData] = useState<IProjectAssignment>();
|
||||
@@ -260,30 +261,30 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }:
|
||||
badgeText={`${statusList.length} stages`}
|
||||
action={
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('UPDATE_ADMIN_STATUS');
|
||||
}}
|
||||
>
|
||||
<ClipboardCheck className="h-3.5 w-3.5 text-his" />
|
||||
Update Admin Status
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('UPDATE_STATUS');
|
||||
}}
|
||||
>
|
||||
<IterationCcw className="h-3.5 w-3.5 text-his" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
{actions?.includes("UPDATE_ADMINISTRATION_STATUS") &&
|
||||
<Button size="sm" variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('UPDATE_ADMIN_STATUS');
|
||||
}}
|
||||
>
|
||||
<ClipboardCheck className="h-3.5 w-3.5 text-his" />
|
||||
Update Admin Status
|
||||
</Button>
|
||||
}
|
||||
{actions?.includes("UPDATE_TECHNICAL_STATUS") &&
|
||||
<Button size="sm" variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('UPDATE_STATUS');
|
||||
}}
|
||||
>
|
||||
<IterationCcw className="h-3.5 w-3.5 text-his" />
|
||||
Update Technical Status
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
@@ -303,18 +304,19 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }:
|
||||
title="Assigned Team"
|
||||
badgeText={`${team.length} people`}
|
||||
action={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('MANAGE_EMPLOYEE');
|
||||
}}
|
||||
>
|
||||
<UserPlus className="h-3.5 w-3.5 text-his" />
|
||||
Manage Team
|
||||
</Button>
|
||||
actions?.includes("MANAGE_TEAM") ?
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
|
||||
onClick={() => {
|
||||
setSelectedData(workOrder);
|
||||
setAction('MANAGE_EMPLOYEE');
|
||||
}}
|
||||
>
|
||||
<UserPlus className="h-3.5 w-3.5 text-his" />
|
||||
Manage Team
|
||||
</Button> : null
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -332,30 +334,36 @@ export default function WorkOrderCard({ workOrder, index, defaultOpen = false }:
|
||||
</motion.div>
|
||||
) : null}
|
||||
</AnimatePresence>
|
||||
</article>
|
||||
</article >
|
||||
|
||||
{/* Modals */}
|
||||
{action === 'UPDATE_ADMIN_STATUS' && selectedData ? (
|
||||
<UpdateAdministrationStatus
|
||||
assignmentId={selectedData.id}
|
||||
assignment={selectedData}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
) : null}
|
||||
{
|
||||
action === 'UPDATE_ADMIN_STATUS' && selectedData ? (
|
||||
<UpdateAdministrationStatus
|
||||
assignmentId={selectedData.id}
|
||||
assignment={selectedData}
|
||||
onClose={handleClose}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
|
||||
{action === 'UPDATE_STATUS' && selectedData ? (
|
||||
<UpdateTimelineStatus assignmentId={selectedData.id} onClose={handleClose} />
|
||||
) : null}
|
||||
{
|
||||
action === 'UPDATE_STATUS' && selectedData ? (
|
||||
<UpdateTimelineStatus assignmentId={selectedData.id} onClose={handleClose} />
|
||||
) : null
|
||||
}
|
||||
|
||||
{action === 'MANAGE_EMPLOYEE' && selectedData ? (
|
||||
<ManageTeam
|
||||
assignmentId={selectedData.id}
|
||||
onClose={handleClose}
|
||||
startDate={selectedData.wo_start_date || selectedData.im_start_date}
|
||||
endDate={selectedData.wo_end_date || selectedData.im_end_date}
|
||||
/>
|
||||
) : null}
|
||||
</li>
|
||||
{
|
||||
action === 'MANAGE_EMPLOYEE' && selectedData ? (
|
||||
<ManageTeam
|
||||
assignmentId={selectedData.id}
|
||||
onClose={handleClose}
|
||||
startDate={selectedData.wo_start_date || selectedData.im_start_date}
|
||||
endDate={selectedData.wo_end_date || selectedData.im_end_date}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
</li >
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import FilterComponent from '@/app/(dashboard)/task/component/FilterComponent';
|
||||
import { COMPLETE_STATUS_LIST, getFilteredAssignments, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data';
|
||||
import { getClientById, getProjectAssignment } from '../../../../utils/queries';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id: string; project_id: string }>
|
||||
@@ -17,6 +18,8 @@ type Props = {
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
|
||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW_PROJECT')
|
||||
|
||||
const { client_id, project_id } = await params;
|
||||
const searchParams_ = await searchParams;
|
||||
const queryString = await getQueryStringFilteredAssignments(searchParams_ || {});
|
||||
|
||||
@@ -39,9 +39,10 @@ const ConfirmDeleteWithInput = dynamic(
|
||||
interface ClientProps {
|
||||
clients: IClient[];
|
||||
initialLayout?: 'grid' | 'list';
|
||||
actions: string[];
|
||||
}
|
||||
|
||||
export default function Client({ clients, initialLayout = 'grid' }: ClientProps) {
|
||||
export default function Client({ clients, actions, initialLayout = 'grid' }: ClientProps) {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const layout = searchParams?.get('layout') === 'list' ? 'list' : initialLayout;
|
||||
@@ -74,26 +75,28 @@ export default function Client({ clients, initialLayout = 'grid' }: ClientProps)
|
||||
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
||||
Try to change the filter or create one to get started.
|
||||
</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mt-4"
|
||||
onClick={() => {
|
||||
setAction('EDIT');
|
||||
setSelectedData(undefined);
|
||||
}}
|
||||
>
|
||||
Create New Client
|
||||
</Button>
|
||||
{actions?.includes('CREATE') &&
|
||||
<Button
|
||||
variant="outline"
|
||||
className="mt-4"
|
||||
onClick={() => {
|
||||
setAction('EDIT');
|
||||
setSelectedData(undefined);
|
||||
}}
|
||||
>
|
||||
Create New Client
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{clients.length > 0 && layout === 'list' ?
|
||||
<ClientList clients={clients} onEdit={handleEdit} onDelete={handleDelete} />
|
||||
<ClientList clients={clients} onEdit={handleEdit} onDelete={handleDelete} actions={actions} />
|
||||
: null}
|
||||
|
||||
{clients.length > 0 && layout === 'grid' ?
|
||||
<ClientGrid clients={clients} onEdit={handleEdit} onDelete={handleDelete} />
|
||||
<ClientGrid clients={clients} onEdit={handleEdit} onDelete={handleDelete} actions={actions} />
|
||||
: null}
|
||||
|
||||
{action === 'EDIT' && (
|
||||
|
||||
@@ -36,12 +36,13 @@ const ClientMilestoneTimeline = dynamic(
|
||||
);
|
||||
|
||||
interface ClientGridProps {
|
||||
actions: string[]
|
||||
clients: IClient[];
|
||||
onEdit: (client: IClient) => void;
|
||||
onDelete: (client: IClient) => void;
|
||||
}
|
||||
|
||||
export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProps) {
|
||||
export default function ClientGrid({ clients, actions, onEdit, onDelete }: ClientGridProps) {
|
||||
return (
|
||||
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
{clients.map((client, i) => {
|
||||
@@ -245,33 +246,24 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp
|
||||
</div>
|
||||
|
||||
<div className='flex items-center gap-1.5'>
|
||||
<Link href={`/task/client-detail/${client.id}`}>
|
||||
<Button
|
||||
variant='default'
|
||||
size="sm"
|
||||
className="text-xs h-7.5 px-2.5 gap-1 hover:bg-accent"
|
||||
>
|
||||
<span>Detail</span>
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
{actions?.includes('VIEW_CLIENT') &&
|
||||
<Link href={`/task/client-detail/${client.id}`}>
|
||||
<Button variant='default' size="sm" className="text-xs h-7.5 px-2.5 gap-1 hover:bg-accent">
|
||||
<span>Detail</span>
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
</Button>
|
||||
</Link>
|
||||
}
|
||||
{actions?.includes('UPDATE_CLIENT') &&
|
||||
<Button onClick={() => onEdit(client)} title='Update Client' size='icon-sm' variant='outline' className='text-teal-500'>
|
||||
<PencilLine />
|
||||
</Button>
|
||||
</Link>
|
||||
<Button onClick={() => onEdit(client)}
|
||||
title='Update Client'
|
||||
size='icon-sm'
|
||||
variant='outline'
|
||||
className='text-teal-500'
|
||||
>
|
||||
<PencilLine />
|
||||
</Button>
|
||||
|
||||
<Button onClick={() => onDelete(client)}
|
||||
title='Delete Client'
|
||||
size='icon-sm'
|
||||
variant='outline'
|
||||
className='text-rose-500'
|
||||
>
|
||||
<Trash />
|
||||
</Button>
|
||||
}
|
||||
{actions?.includes('DELETE_CLIENT') &&
|
||||
<Button onClick={() => onDelete(client)} title='Delete Client' size='icon-sm' variant='outline' className='text-rose-500'>
|
||||
<Trash />
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</Card900>
|
||||
|
||||
@@ -33,12 +33,13 @@ const ClientMilestoneTimeline = dynamic(() => import('./ClientMilestoneTimeline'
|
||||
});
|
||||
|
||||
interface ClientListProps {
|
||||
actions: string[]
|
||||
clients: IClient[];
|
||||
onEdit: (client: IClient) => void;
|
||||
onDelete: (client: IClient) => void;
|
||||
}
|
||||
|
||||
export default function ClientList({ clients, onEdit, onDelete }: ClientListProps) {
|
||||
export default function ClientList({ clients, onEdit, onDelete, actions }: ClientListProps) {
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
{clients.map((client, index) => {
|
||||
@@ -245,34 +246,24 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
|
||||
|
||||
{/* Action Buttons: View Detail + More Actions Dropdown */}
|
||||
<div className="flex items-center justify-end gap-2 pt-2">
|
||||
<Link href={`/task/client-detail/${client.id}`} className="flex-1">
|
||||
<Button
|
||||
variant='default'
|
||||
size="sm"
|
||||
className="w-full text-xs h-8 gap-1.5"
|
||||
>
|
||||
<span>View Detail</span>
|
||||
<ExternalLink className="w-3.5 h-3.5" />
|
||||
{actions?.includes('VIEW_CLIENT') &&
|
||||
<Link href={`/task/client-detail/${client.id}`} className="flex-1">
|
||||
<Button variant='default' size="sm" className="w-full text-xs h-8 gap-1.5">
|
||||
<span>View Detail</span>
|
||||
<ExternalLink className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
</Link>
|
||||
}
|
||||
{actions?.includes('UPDATE_CLIENT') &&
|
||||
<Button onClick={() => onEdit(client)} title='Update Client' size='icon-sm' variant='outline' className='text-teal-500'>
|
||||
<PencilLine />
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<Button onClick={() => onEdit(client)}
|
||||
title='Update Client'
|
||||
size='icon-sm'
|
||||
variant='outline'
|
||||
className='text-teal-500'
|
||||
>
|
||||
<PencilLine />
|
||||
</Button>
|
||||
|
||||
<Button onClick={() => onDelete(client)}
|
||||
title='Delete Client'
|
||||
size='icon-sm'
|
||||
variant='outline'
|
||||
className='text-rose-500'
|
||||
>
|
||||
<Trash />
|
||||
</Button>
|
||||
}
|
||||
{actions?.includes('DELETE_CLIENT') &&
|
||||
<Button onClick={() => onDelete(client)} title='Delete Client' size='icon-sm' variant='outline' className='text-rose-500'>
|
||||
<Trash />
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -76,6 +76,7 @@ function CompactPhaseStepper({ phaseIndex, progressColor }: { phaseIndex: number
|
||||
interface AssignmentGridProps {
|
||||
assignments: IProjectAssignment[];
|
||||
clientId?: string;
|
||||
actions?: string[]
|
||||
onManageTeam?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateStatus?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateAdministrationStatus?: (assignment: IProjectAssignment) => void;
|
||||
@@ -85,6 +86,7 @@ interface AssignmentGridProps {
|
||||
export default function AssignmentGrid({
|
||||
assignments,
|
||||
clientId,
|
||||
actions,
|
||||
onManageTeam,
|
||||
onUpdateStatus,
|
||||
onUpdateAdministrationStatus,
|
||||
@@ -187,7 +189,7 @@ export default function AssignmentGrid({
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
{promoteAssignmentUrl && (
|
||||
{actions?.includes("PROMOTE_ASSIGNMENT") && promoteAssignmentUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
|
||||
<ArrowUpRight className="w-4 h-4 text-his" />
|
||||
@@ -195,40 +197,42 @@ export default function AssignmentGrid({
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
|
||||
</DropdownMenuItem>
|
||||
{projectDetailUrl && (
|
||||
{actions?.includes("VIEW_ASSIGNMENT") &&
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
|
||||
</DropdownMenuItem>
|
||||
}
|
||||
{actions?.includes('VIEW_PROJECT') && projectDetailUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={projectDetailUrl}>View Project Details</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{!clientId && assignment.client?.id && (
|
||||
{actions?.includes('VIEW_CLIENT') && !clientId && assignment.client?.id && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/task/client-detail/${assignment.client.id}`}>View Client</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{editAssignmentUrl && (
|
||||
{actions?.includes("UPDATE_ASSIGNMEN") && editAssignmentUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={editAssignmentUrl}>Edit Assignment</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onManageTeam && (
|
||||
{actions?.includes("MANAGE_TEAM") && onManageTeam && (
|
||||
<DropdownMenuItem onSelect={() => onManageTeam(assignment)}>
|
||||
Manage Team
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateAdministrationStatus && (
|
||||
{actions?.includes("UPDATE_ADMINISTRATION_STATUS") && onUpdateAdministrationStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateAdministrationStatus(assignment)}>
|
||||
Update Administration Status
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateStatus && (
|
||||
{actions?.includes("UPDATE_TECHNICAL_STATUS") && onUpdateStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
|
||||
Update Technical Status
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onDelete && (
|
||||
{actions?.includes("DELETE_ASSIGNMENT") && onDelete && (
|
||||
<DropdownMenuItem
|
||||
onSelect={() => onDelete(assignment)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
|
||||
@@ -78,6 +78,7 @@ function PhaseStepper({ phaseIndex, progressColor }: { phaseIndex: number; progr
|
||||
interface AssignmentListProps {
|
||||
assignments: IProjectAssignment[];
|
||||
clientId?: string;
|
||||
actions?: string[]
|
||||
onManageTeam?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateStatus?: (assignment: IProjectAssignment) => void;
|
||||
onUpdateAdministrationStatus?: (assignment: IProjectAssignment) => void;
|
||||
@@ -87,6 +88,7 @@ interface AssignmentListProps {
|
||||
export default function AssignmentList({
|
||||
assignments,
|
||||
clientId,
|
||||
actions,
|
||||
onManageTeam,
|
||||
onUpdateStatus,
|
||||
onUpdateAdministrationStatus,
|
||||
@@ -395,7 +397,7 @@ export default function AssignmentList({
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
{promoteAssignmentUrl && (
|
||||
{actions?.includes('PROMOTE_ASSIGNMENT') && promoteAssignmentUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
|
||||
<ArrowUpRight className="w-4 h-4 text-his" />
|
||||
@@ -403,40 +405,42 @@ export default function AssignmentList({
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
|
||||
</DropdownMenuItem>
|
||||
{projectDetailUrl && (
|
||||
{actions?.includes('VIEW_ASSIGNMENT') &&
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
|
||||
</DropdownMenuItem>
|
||||
}
|
||||
{actions?.includes('VIEW_PROJECT') && projectDetailUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={projectDetailUrl}>View Project Details</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{!clientId && assignment.client?.id && (
|
||||
{!clientId && assignment.client?.id && actions?.includes('VIEW_CLIENT') && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/task/client-detail/${assignment.client.id}`}>View Client</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{editAssignmentUrl && (
|
||||
{actions?.includes('UPDATE_ASSIGNMENT') && editAssignmentUrl && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={editAssignmentUrl}>Edit Assignment</Link>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onManageTeam && (
|
||||
{actions?.includes('MANAGE_TEAM') && onManageTeam && (
|
||||
<DropdownMenuItem onSelect={() => onManageTeam(assignment)}>
|
||||
Manage Team
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateAdministrationStatus && (
|
||||
{actions?.includes('UPDATE_ADMINISTRATION_STATUS') && onUpdateAdministrationStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateAdministrationStatus(assignment)}>
|
||||
Update Administration Status
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onUpdateStatus && (
|
||||
{actions?.includes('UPDATE_TECHNICAL_STATUS') && onUpdateStatus && (
|
||||
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
|
||||
Update Technical Status
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{onDelete && (
|
||||
{actions?.includes('DELETE_ASSIGNMENT') && onDelete && (
|
||||
<DropdownMenuItem
|
||||
onSelect={() => onDelete(assignment)}
|
||||
className="text-destructive focus:text-destructive"
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Metadata } from 'next';
|
||||
import { getFilteredClients } from './data';
|
||||
import { getClients } from './utils/queries';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { getNonAdminAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const HomeTask = lazy(() => import('./component/HomeTask'));
|
||||
const Client = lazy(() => import('./component/client/Client'));
|
||||
@@ -40,6 +41,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
}
|
||||
|
||||
export default async function ClientsPage({ searchParams }: Props) {
|
||||
const actions = await getNonAdminAccessPagePermission('/task', 'VIEW')
|
||||
const searchParams_ = await searchParams;
|
||||
|
||||
// const view = searchParams_.view === 'assignments' ? 'assignments' : 'clients';
|
||||
@@ -66,7 +68,7 @@ export default async function ClientsPage({ searchParams }: Props) {
|
||||
</Suspense>
|
||||
|
||||
<Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
||||
<Client clients={filteredClients} initialLayout={layout} />
|
||||
<Client clients={filteredClients} initialLayout={layout} actions={actions} />
|
||||
</Suspense>
|
||||
{/* <Suspense fallback={<div className="animate-pulse h-96 bg-accent rounded-xl" />}>
|
||||
{view === 'clients' ?
|
||||
|
||||
@@ -115,7 +115,7 @@ const ComponentAreaPage: FC<Props> = ({ data, actions }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => actions.includes('UPDATE') || actions.includes('DELETE') && (
|
||||
render: (_, record) => (actions.includes('UPDATE') || actions.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -166,7 +166,7 @@ const ComponentAreaPage: FC<Props> = ({ data, actions }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search company..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
{actions.includes('CREATE') &&
|
||||
{actions?.includes('CREATE') &&
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Area
|
||||
|
||||
@@ -129,7 +129,7 @@ const ComponentCompanyPage: FC<Props> = ({ data, actions }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => actions.includes('EDIT') || actions.includes('DELETE') && (
|
||||
render: (_, record) => (actions.includes('EDIT') || actions.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
||||
@@ -112,7 +112,7 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => actions.includes('UPDATE') || actions.includes('DELETE') && (
|
||||
render: (_, record) => (actions.includes('UPDATE') || actions.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -163,7 +163,7 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search department..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
{actions.includes('CREATE') ?
|
||||
{actions?.includes('CREATE') ?
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Department
|
||||
|
||||
@@ -156,16 +156,16 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
{record.status.code === 'A' ?
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem><Link href={`user/${record.id}`} className='w-full'>View</Link></DropdownMenuItem>
|
||||
{actions.includes('CHANGE_PASSWORD') &&
|
||||
{actions?.includes('CHANGE_PASSWORD') &&
|
||||
<DropdownMenuItem onClick={() => { setShowFormChangePass(true); setSelectedData(record) }}>Change password</DropdownMenuItem>
|
||||
}
|
||||
{actions.includes('RESET_PASSWORD') &&
|
||||
{actions?.includes('RESET_PASSWORD') &&
|
||||
<DropdownMenuItem onClick={() => { setShowResetPass(true), setSelectedData(record) }}>Reset Password</DropdownMenuItem>
|
||||
}
|
||||
{actions.includes('UPDATE') &&
|
||||
{actions?.includes('UPDATE') &&
|
||||
<DropdownMenuItem><Link href={`user/create?is_update=true&id=${record.id}`} className='w-full'>Edit</Link></DropdownMenuItem>
|
||||
}
|
||||
{actions.includes('DELETE') &&
|
||||
{actions?.includes('DELETE') &&
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
@@ -208,7 +208,7 @@ const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search user..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
{actions.includes('CREATE') &&
|
||||
{actions?.includes('CREATE') &&
|
||||
<Link href='user/create'>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost'>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
'use client'
|
||||
|
||||
import { FC, Suspense, useEffect, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { DatePicker, Form, Input, Radio, Select } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import useFetch from '@/hooks/useFetch';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { titleCase } from '@/lib/helper';
|
||||
import PageLoading from '@/components/loader/PageLoading';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type IUser } from '../component/type';
|
||||
import { type IRole } from '@/app/admin/information/user-role/component/type';
|
||||
import { type ICompany } from '../../company/component/type';
|
||||
import { type IArea } from '../../area/component/type';
|
||||
import { type IDivision } from '../../division/component/type';
|
||||
import { type IPosition } from '@/app/admin/information/position/component/type';
|
||||
import { type IEmployeeType } from '@/app/admin/information/employee-type/component/type';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
type Props = {};
|
||||
|
||||
const UserCreate: FC<Props> = ({ }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [isFetching, setIsFetching] = useState(false)
|
||||
const [showConfirm, setShowConfirm] = useState(false)
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams();
|
||||
const axios = useAxiosAuth()
|
||||
|
||||
const isUpdate = searchParams!.get('is_update') as string || ''
|
||||
const id = searchParams!.get('id') as string || ''
|
||||
|
||||
const { data: companyList, isLoading: companyLoading } = useFetch('/company')
|
||||
const { data: areaList, isLoading: areaLoading } = useFetch('/area')
|
||||
const { data: divisionList, isLoading: divisionLoading } = useFetch('/division')
|
||||
const { data: roleList, isLoading: roleLoading } = useFetch('/role')
|
||||
const { data: positionList, isLoading: positionLoading } = useFetch('/position')
|
||||
const { data: employeeTypeList, isLoading: employeeTypeLoading } = useFetch('/employee-type')
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
setIsFetching(true)
|
||||
try {
|
||||
const res = await axios.get(`/user/${id}`)
|
||||
const data: IUser = res.data.data
|
||||
|
||||
form.setFieldsValue(data)
|
||||
|
||||
if (data.company) form.setFieldValue('company_id', data.company.id)
|
||||
if (data.area) form.setFieldValue('area_id', data.area.id)
|
||||
if (data.division) form.setFieldValue('division_id', data.division.id)
|
||||
if (data.role) form.setFieldValue('role_id', data.role.id)
|
||||
if (data.employee_type) form.setFieldValue('employee_type_id', data.employee_type.id)
|
||||
if (data.position) form.setFieldValue('position_id', data.position.id)
|
||||
|
||||
if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday))
|
||||
if (data.contract_expiration_date) form.setFieldValue('contract_expiration_date', dayjs(data.contract_expiration_date))
|
||||
if (data.hire_date) form.setFieldValue('hire_date', dayjs(data.hire_date))
|
||||
if (data.resign_date) form.setFieldValue('resign_date', dayjs(data.resign_date))
|
||||
|
||||
setIsFetching(false)
|
||||
} catch (error: any) {
|
||||
handleError(`Failed fetch data, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpdate) {
|
||||
fetchData()
|
||||
} else {
|
||||
form.resetFields()
|
||||
}
|
||||
}, [isUpdate, form, id])
|
||||
|
||||
|
||||
const handleSubmit = () => {
|
||||
const payload = form.getFieldsValue()
|
||||
if (payload.fullname) payload.fullname = titleCase(payload.fullname)
|
||||
|
||||
!isUpdate ? handleCreate(payload) : handleUpdate(payload)
|
||||
}
|
||||
|
||||
const handleCreate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.post('/user', payload)
|
||||
|
||||
handleSuccess('Data successfully created.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to create, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUpdate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.put('/user/' + id, payload)
|
||||
|
||||
handleSuccess('Data successfully updated.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to update, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSuccess = (message: string) => {
|
||||
toast.success(message)
|
||||
router.replace('/admin/administration/user')
|
||||
router.refresh()
|
||||
form.resetFields()
|
||||
}
|
||||
|
||||
const handleError = (message: string) => {
|
||||
toast.error(message)
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-row items-center sm:space-x-5'>
|
||||
<Link href='/admin/administration/user' className='hidden sm:block'>
|
||||
<Button variant='outline' size='icon'>
|
||||
<i className="ti ti-arrow-left text-xl"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
<div className='space-y-1'>
|
||||
<CardTitle>{isUpdate ? 'Update user' : 'Create new user'}</CardTitle>
|
||||
<CardDescription>{isUpdate ? 'Update user id ' + id : 'Add a new team to join to your department'}</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<Form form={form} onFinish={() => setShowConfirm(true)} scrollToFirstError layout="vertical" size='small'>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-0 gap-x-5 2xl:gap-x-8'>
|
||||
{/* <Label htmlFor="fullname">Fullname</Label> */}
|
||||
<Form.Item name='fullname' labelAlign="left" label='Fullname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="fullname" placeholder="John Doe" />
|
||||
</Form.Item>
|
||||
<Form.Item name='nickname' label='Nickname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="nickname" placeholder="John" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Email' name='email' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email" placeholder="john.nutech@gmail.com" />
|
||||
</Form.Item>
|
||||
{!isUpdate &&
|
||||
<Form.Item label='Password' name='password' rules={[
|
||||
{ required: true, message: 'This field is required' }, { min: 5 }
|
||||
]}>
|
||||
<Input.Password className="input" type="password" id="password" placeholder="********" />
|
||||
</Form.Item>
|
||||
}
|
||||
<Form.Item label='NIK' name='nik' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIK format' },
|
||||
{ len: 11 }
|
||||
]}>
|
||||
<Input className="input" id="nik" placeholder="04012345678" maxLength={11} />
|
||||
</Form.Item>
|
||||
<Form.Item label='NIKTG' name='niktg' rules={[
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIKTG format' },
|
||||
]}>
|
||||
<Input className="input" id="niktg" placeholder="995500" maxLength={8} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Phone Number' name='phone_number' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid phone number' },
|
||||
{ min: 10 }, { max: 13 }
|
||||
]}>
|
||||
<Input className="input" id="phone_number" placeholder="6281234567890" maxLength={13} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Role' name='role_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select role' showSearch allowClear loading={roleLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{roleList?.role?.length > 0 && roleList.role.map((item: IRole, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Company' name='company_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select company' showSearch allowClear loading={companyLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{companyList?.company?.length > 0 && companyList.company.map((item: ICompany, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Area' name='area_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select area' showSearch allowClear loading={areaLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{areaList?.area?.length > 0 && areaList.area.map((item: IArea, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Department' name='division_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select division' showSearch allowClear loading={divisionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{divisionList?.division?.length > 0 && divisionList.division.map((item: IDivision, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Position' name='position_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select position' showSearch allowClear loading={positionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{positionList?.position?.length > 0 && positionList.position.map((item: IPosition, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Employee Type' name='employee_type_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select employee type' showSearch allowClear loading={employeeTypeLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{employeeTypeList?.employee_type?.length > 0 && employeeTypeList.employee_type.map((item: IEmployeeType, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Birthdate' name='birthday'>
|
||||
<DatePicker className='w-full' placeholder='Select date of birth' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Gender' name='gender'>
|
||||
<Radio.Group>
|
||||
<Radio value="male">Male</Radio>
|
||||
<Radio value="female">Female</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Hire Date' name='hire_date'>
|
||||
<DatePicker className='w-full' placeholder='Select date of hire' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Contract Expiration Date' name='contract_expiration_date'>
|
||||
<DatePicker className='w-full' placeholder='Select contract expiration date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Extend Contract' name='is_extend_contract'>
|
||||
<Radio.Group>
|
||||
<Radio value={true}>Yes</Radio>
|
||||
<Radio value={false}>No</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Office Email' name='email_office' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_office" placeholder="john@nutech-integrasi.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Personal Email' name='email_personal' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_personal" placeholder="john@gmail.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Last Education' name='last_education' >
|
||||
<Input className="input" id="last_education" placeholder="S1 Teknik Informatika" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Date' name='resign_date'>
|
||||
<DatePicker className='w-full' placeholder='Select resign date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Reason' name='resign_reason' >
|
||||
<Input.TextArea className="input" id="resign_reason" placeholder="Describe reason of resign" rootClassName='px-3! py-2!' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Post Company' name='post_company'>
|
||||
<Input className="input" id="post_company" placeholder="PT Tokopedia" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div className='flex justify-end items-center'>
|
||||
<Button type='submit'>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{isUpdate && isFetching &&
|
||||
<PageLoading />
|
||||
}
|
||||
|
||||
{showConfirm &&
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This data will be stored on our server, you can change it whenever you want later.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={handleSubmit}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Continue
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserCreate;
|
||||
@@ -1,338 +1,28 @@
|
||||
'use client'
|
||||
|
||||
import { FC, Suspense, useEffect, useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { DatePicker, Form, Input, Radio, Select } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import useFetch from '@/hooks/useFetch';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { titleCase } from '@/lib/helper';
|
||||
import PageLoading from '@/components/loader/PageLoading';
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense } from 'react';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type IUser } from '../component/type';
|
||||
import { type IRole } from '@/app/admin/information/user-role/component/type';
|
||||
import { type ICompany } from '../../company/component/type';
|
||||
import { type IArea } from '../../area/component/type';
|
||||
import { type IDivision } from '../../division/component/type';
|
||||
import { type IPosition } from '@/app/admin/information/position/component/type';
|
||||
import { type IEmployeeType } from '@/app/admin/information/employee-type/component/type';
|
||||
import { toast } from 'sonner';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import UserCreateClient from './UserCreateClient';
|
||||
|
||||
type Props = {};
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
const UserCreate: FC<Props> = ({ }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [isFetching, setIsFetching] = useState(false)
|
||||
const [showConfirm, setShowConfirm] = useState(false)
|
||||
export const metadata: Metadata = {
|
||||
title: "Admin | User Form",
|
||||
description: "Create or update employee user information",
|
||||
};
|
||||
|
||||
const [form] = Form.useForm();
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams();
|
||||
const axios = useAxiosAuth()
|
||||
type Props = {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
};
|
||||
|
||||
const isUpdate = searchParams!.get('is_update') as string || ''
|
||||
const id = searchParams!.get('id') as string || ''
|
||||
|
||||
const { data: companyList, isLoading: companyLoading } = useFetch('/company')
|
||||
const { data: areaList, isLoading: areaLoading } = useFetch('/area')
|
||||
const { data: divisionList, isLoading: divisionLoading } = useFetch('/division')
|
||||
const { data: roleList, isLoading: roleLoading } = useFetch('/role')
|
||||
const { data: positionList, isLoading: positionLoading } = useFetch('/position')
|
||||
const { data: employeeTypeList, isLoading: employeeTypeLoading } = useFetch('/employee-type')
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
setIsFetching(true)
|
||||
try {
|
||||
const res = await axios.get(`/user/${id}`)
|
||||
const data: IUser = res.data.data
|
||||
|
||||
form.setFieldsValue(data)
|
||||
|
||||
if (data.company) form.setFieldValue('company_id', data.company.id)
|
||||
if (data.area) form.setFieldValue('area_id', data.area.id)
|
||||
if (data.division) form.setFieldValue('division_id', data.division.id)
|
||||
if (data.role) form.setFieldValue('role_id', data.role.id)
|
||||
if (data.employee_type) form.setFieldValue('employee_type_id', data.employee_type.id)
|
||||
if (data.position) form.setFieldValue('position_id', data.position.id)
|
||||
|
||||
if (data.birthday) form.setFieldValue('birthday', dayjs(data.birthday))
|
||||
if (data.contract_expiration_date) form.setFieldValue('contract_expiration_date', dayjs(data.contract_expiration_date))
|
||||
if (data.hire_date) form.setFieldValue('hire_date', dayjs(data.hire_date))
|
||||
if (data.resign_date) form.setFieldValue('resign_date', dayjs(data.resign_date))
|
||||
|
||||
setIsFetching(false)
|
||||
} catch (error: any) {
|
||||
handleError(`Failed fetch data, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpdate) {
|
||||
fetchData()
|
||||
} else {
|
||||
form.resetFields()
|
||||
}
|
||||
}, [isUpdate, form, id])
|
||||
|
||||
|
||||
const handleSubmit = () => {
|
||||
const payload = form.getFieldsValue()
|
||||
if (payload.fullname) payload.fullname = titleCase(payload.fullname)
|
||||
|
||||
!isUpdate ? handleCreate(payload) : handleUpdate(payload)
|
||||
}
|
||||
|
||||
const handleCreate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.post('/user', payload)
|
||||
|
||||
handleSuccess('Data successfully created.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to create, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUpdate = async (payload: IUser) => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await axios.put('/user/' + id, payload)
|
||||
|
||||
handleSuccess('Data successfully updated.')
|
||||
} catch (error: any) {
|
||||
handleError(`Data failed to update, (${error.response.data.code || error.response.status || '-'}) ${error.response.data.message || error.response.statusText || error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSuccess = (message: string) => {
|
||||
toast.success(message)
|
||||
router.replace('/admin/administration/user')
|
||||
router.refresh()
|
||||
form.resetFields()
|
||||
}
|
||||
|
||||
const handleError = (message: string) => {
|
||||
toast.error(message)
|
||||
setIsLoading(false)
|
||||
}
|
||||
export default async function UserCreatePage({ searchParams }: Props) {
|
||||
const params = await searchParams;
|
||||
const isUpdate = params?.is_update === 'true';
|
||||
await getAccessPagePermission('/administration/user', isUpdate ? 'UPDATE' : 'CREATE');
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className='flex flex-row items-center sm:space-x-5'>
|
||||
<Link href='/admin/administration/user' className='hidden sm:block'>
|
||||
<Button variant='outline' size='icon'>
|
||||
<i className="ti ti-arrow-left text-xl"></i>
|
||||
</Button>
|
||||
</Link>
|
||||
<div className='space-y-1'>
|
||||
<CardTitle>{isUpdate ? 'Update user' : 'Create new user'}</CardTitle>
|
||||
<CardDescription>{isUpdate ? 'Update user id ' + id : 'Add a new team to join to your department'}</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<Form form={form} onFinish={() => setShowConfirm(true)} scrollToFirstError layout="vertical" size='small'>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 font-medium gap-y-0 gap-x-5 2xl:gap-x-8'>
|
||||
{/* <Label htmlFor="fullname">Fullname</Label> */}
|
||||
<Form.Item name='fullname' labelAlign="left" label='Fullname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="fullname" placeholder="John Doe" />
|
||||
</Form.Item>
|
||||
<Form.Item name='nickname' label='Nickname' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Input className="input" id="nickname" placeholder="John" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Email' name='email' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email" placeholder="john.nutech@gmail.com" />
|
||||
</Form.Item>
|
||||
{!isUpdate &&
|
||||
<Form.Item label='Password' name='password' rules={[
|
||||
{ required: true, message: 'This field is required' }, { min: 5 }
|
||||
]}>
|
||||
<Input.Password className="input" type="password" id="password" placeholder="********" />
|
||||
</Form.Item>
|
||||
}
|
||||
<Form.Item label='NIK' name='nik' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIK format' },
|
||||
{ len: 11 }
|
||||
]}>
|
||||
<Input className="input" id="nik" placeholder="04012345678" maxLength={11} />
|
||||
</Form.Item>
|
||||
<Form.Item label='NIKTG' name='niktg' rules={[
|
||||
{ pattern: /^\d+$/, message: 'Invalid NIKTG format' },
|
||||
]}>
|
||||
<Input className="input" id="niktg" placeholder="995500" maxLength={8} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Phone Number' name='phone_number' rules={[
|
||||
{ required: true, message: 'This field is required' },
|
||||
{ pattern: /^\d+$/, message: 'Invalid phone number' },
|
||||
{ min: 10 }, { max: 13 }
|
||||
]}>
|
||||
<Input className="input" id="phone_number" placeholder="6281234567890" maxLength={13} />
|
||||
</Form.Item>
|
||||
<Form.Item label='Role' name='role_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select role' showSearch allowClear loading={roleLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{roleList?.role?.length > 0 && roleList.role.map((item: IRole, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Company' name='company_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select company' showSearch allowClear loading={companyLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{companyList?.company?.length > 0 && companyList.company.map((item: ICompany, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Area' name='area_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select area' showSearch allowClear loading={areaLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{areaList?.area?.length > 0 && areaList.area.map((item: IArea, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Department' name='division_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select division' showSearch allowClear loading={divisionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{divisionList?.division?.length > 0 && divisionList.division.map((item: IDivision, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.code} - {item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Position' name='position_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select position' showSearch allowClear loading={positionLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{positionList?.position?.length > 0 && positionList.position.map((item: IPosition, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Employee Type' name='employee_type_id' rules={[{ required: true, message: 'This field is required' }]} >
|
||||
<Select placeholder='Select employee type' showSearch allowClear loading={employeeTypeLoading}
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) => option!.children!.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
size='large'
|
||||
>
|
||||
{employeeTypeList?.employee_type?.length > 0 && employeeTypeList.employee_type.map((item: IEmployeeType, key: number) =>
|
||||
<Select.Option value={item.id} key={key}>{item.name}</Select.Option>
|
||||
)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label='Birthdate' name='birthday'>
|
||||
<DatePicker className='w-full' placeholder='Select date of birth' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Gender' name='gender'>
|
||||
<Radio.Group>
|
||||
<Radio value="male">Male</Radio>
|
||||
<Radio value="female">Female</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Hire Date' name='hire_date'>
|
||||
<DatePicker className='w-full' placeholder='Select date of hire' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Contract Expiration Date' name='contract_expiration_date'>
|
||||
<DatePicker className='w-full' placeholder='Select contract expiration date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Extend Contract' name='is_extend_contract'>
|
||||
<Radio.Group>
|
||||
<Radio value={true}>Yes</Radio>
|
||||
<Radio value={false}>No</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label='Office Email' name='email_office' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_office" placeholder="john@nutech-integrasi.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Personal Email' name='email_personal' rules={[
|
||||
{ type: 'email', message: 'The input is not valid E-mail!' }]}
|
||||
>
|
||||
<Input className="input" id="email_personal" placeholder="john@gmail.com" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Last Education' name='last_education' >
|
||||
<Input className="input" id="last_education" placeholder="S1 Teknik Informatika" />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Date' name='resign_date'>
|
||||
<DatePicker className='w-full' placeholder='Select resign date' size='large' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Resign Reason' name='resign_reason' >
|
||||
<Input.TextArea className="input" id="resign_reason" placeholder="Describe reason of resign" rootClassName='px-3! py-2!' />
|
||||
</Form.Item>
|
||||
<Form.Item label='Post Company' name='post_company'>
|
||||
<Input className="input" id="post_company" placeholder="PT Tokopedia" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
<div className='flex justify-end items-center'>
|
||||
<Button type='submit'>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{isUpdate && isFetching &&
|
||||
<PageLoading />
|
||||
}
|
||||
|
||||
{showConfirm &&
|
||||
<AlertDialog open={true}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This data will be stored on our server, you can change it whenever you want later.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={handleSubmit}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Continue
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
}
|
||||
</>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<UserCreateClient />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserCreate;
|
||||
@@ -4,7 +4,7 @@ import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon, PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -17,9 +17,10 @@ import { type ILogName } from './type';
|
||||
|
||||
type Props = {
|
||||
data: ILogName[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<ILogName[]>([])
|
||||
const [selectedData, setSelectedData] = useState<ILogName | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -107,7 +108,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -117,10 +118,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -164,10 +169,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search log name..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Audit
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Audit
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,48 +1,22 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Admin | Log Name",
|
||||
title: "Admin | Audit Trail",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/log-name', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['log-name']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
export default async function DeviceTypePage() {
|
||||
const data = await getData()
|
||||
export default async function AuditTrailPage() {
|
||||
const actions = await getAccessPagePermission('/audit-trail')
|
||||
const data = await fetchData('/log-name', 'no-cache', { tags: ['log-name'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -53,14 +27,17 @@ export default async function DeviceTypePage() {
|
||||
<CardTitle>Log Name</CardTitle>
|
||||
<CardDescription>Here's a list of log audit name!</CardDescription>
|
||||
</div>
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.log_name}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -18,9 +18,10 @@ import { type IDayOff } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IDayOff[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IDayOff[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IDayOff | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -33,7 +34,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (id: string | number) => {
|
||||
const handleDelete = async (id: string | number) => {
|
||||
return axios.delete(`/dayoff/${id}`).then(res => res.data)
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -118,10 +119,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -156,10 +161,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search log name..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -11,7 +12,8 @@ export const metadata: Metadata = {
|
||||
}
|
||||
|
||||
|
||||
export default async function DeviceTypePage() {
|
||||
export default async function DayOffPage() {
|
||||
const actions = await getAccessPagePermission('/day-off')
|
||||
const data = await fetchData('/dayoff')
|
||||
|
||||
return (
|
||||
@@ -26,7 +28,7 @@ export default async function DeviceTypePage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data.day_off} />
|
||||
<ComponentPage data={data.day_off} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -17,9 +17,10 @@ import { type IDeviceType } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IDeviceType[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IDeviceType[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IDeviceType | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -32,7 +33,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (deviceTypeId: string | number) => {
|
||||
const handleDelete = async (deviceTypeId: string | number) => {
|
||||
return axios.delete(`/device-type/${deviceTypeId}`).then(res => res.data)
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -117,10 +118,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -162,12 +167,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search device type..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
<Input placeholder="Search device type..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device Type
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device Type
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -15,35 +14,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Device Type",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/device-type', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['device-type']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
export default async function DeviceTypePage() {
|
||||
const data = await getData()
|
||||
const actions = await getAccessPagePermission('/device/device-type')
|
||||
const data = await fetchData('/device-type', 'no-cache', { tags: ['device-type'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -54,14 +27,17 @@ export default async function DeviceTypePage() {
|
||||
<CardTitle>Device Type</CardTitle>
|
||||
<CardDescription>Here's a list of device types that have been registered!</CardDescription>
|
||||
</div>
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.device_type}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -17,9 +17,10 @@ import { IDevice } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IDevice[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IDevice[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IDevice | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -32,7 +33,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (deviceId: string | number) => {
|
||||
const handleDelete = async (deviceId: string | number) => {
|
||||
return axios.delete(`/device/${deviceId}`).then(res => res.data)
|
||||
|
||||
}
|
||||
@@ -117,7 +118,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -127,10 +128,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -168,10 +173,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
Filter
|
||||
</Button>
|
||||
</div>
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button variant='ghost' size="sm" className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Device
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -15,35 +14,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Device",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/device', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['device']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
export default async function DivisionPage() {
|
||||
const data = await getData()
|
||||
export default async function DevicePage() {
|
||||
const actions = await getAccessPagePermission('/device/device')
|
||||
const data = await fetchData('/device', 'no-cache', { tags: ['device'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -54,14 +27,17 @@ export default async function DivisionPage() {
|
||||
<CardTitle>Device</CardTitle>
|
||||
<CardDescription>Here's a list of devices that have been registered!</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.device}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -17,9 +17,10 @@ import { type IGlobalParameter } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IGlobalParameter[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IGlobalParameter[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IGlobalParameter | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -32,7 +33,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (id: string | number) => {
|
||||
const handleDelete = async (id: string | number) => {
|
||||
return axios.delete(`/global-parameter/${id}`).then(res => res.data)
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -127,10 +128,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -171,12 +176,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search parameters..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
<Input placeholder="Search parameters..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -15,35 +14,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Global Parameter",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/global-parameter', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['global-parameter']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
export default async function GlobalParameterPage() {
|
||||
const data = await getData()
|
||||
const actions = await getAccessPagePermission('/global-parameter')
|
||||
const data = await fetchData('/global-parameter', 'no-cache', { tags: ['global-parameter'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -54,14 +27,17 @@ export default async function GlobalParameterPage() {
|
||||
<CardTitle>Global Parameter</CardTitle>
|
||||
<CardDescription>Here's a list of parameters that have been registered!</CardDescription>
|
||||
</div>
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
{actions.includes('EXPORT') &&
|
||||
<div>
|
||||
<Button className="sm:hidden" size={'icon'}><Download size={20} /></Button>
|
||||
</div>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage
|
||||
data={data.global_parameter}
|
||||
actions={actions}
|
||||
/>
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { type IEmployeeType } from './type';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Employee Type",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/employee-type', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['employee-type']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
export default async function page() {
|
||||
const data = await getData()
|
||||
export default async function EmployeeTypePage() {
|
||||
await getAccessPagePermission('/information/employee-type')
|
||||
const data = await fetchData('/employee-type', 'no-cache', { tags: ['employee-type'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { type IMasterStatus } from './type';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Status",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/status', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['status']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
export default async function page() {
|
||||
const data = await getData()
|
||||
export default async function MasterStatusPage() {
|
||||
await getAccessPagePermission('/information/master-status')
|
||||
const data = await fetchData('/status', 'no-cache', { tags: ['status'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { type IPosition } from './type';
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Employee Position",
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/position', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['position']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
export default async function page() {
|
||||
const data = await getData()
|
||||
export default async function PositionPage() {
|
||||
await getAccessPagePermission('/information/position')
|
||||
const data = await fetchData('/position', 'no-cache', { tags: ['position'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -50,7 +23,7 @@ export default async function page() {
|
||||
<CardHeader className='flex flex-row items-center justify-between space-y-2 sm:space-y-0'>
|
||||
<div>
|
||||
<CardTitle>Position</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of empoyee's position that have been registered!</CardDescription>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of empoyee's position that have been registered!</CardDescription>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { FC, ReactNode, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
type Props = {
|
||||
title?: string
|
||||
description?: string
|
||||
onConfirm: () => Promise<any>
|
||||
okText?: string
|
||||
cancelText?: string
|
||||
contentSuccess?: ReactNode | string
|
||||
onOkSuccess?: () => any
|
||||
};
|
||||
|
||||
const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancelText, contentSuccess, onOkSuccess }) => {
|
||||
const [isLoading, setIsloading] = useState(false)
|
||||
const router = useRouter()
|
||||
|
||||
const confirm = async () => {
|
||||
if (isLoading) return
|
||||
try {
|
||||
setIsloading(true)
|
||||
const res: ResponseData = await onConfirm()
|
||||
setIsloading(false)
|
||||
|
||||
console.log(res)
|
||||
if (!res) return
|
||||
|
||||
if (res.code === '00') {
|
||||
showSuccess()
|
||||
} else {
|
||||
showError(res.message)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
setIsloading(false)
|
||||
showError(error?.message)
|
||||
}
|
||||
}
|
||||
|
||||
const showSuccess = () => {
|
||||
router.refresh()
|
||||
toast.success(contentSuccess || 'Data successfully removed.' as string)
|
||||
onOkSuccess!()
|
||||
};
|
||||
|
||||
const showError = (message?: string) => {
|
||||
toast.error(message)
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{description || 'This action cannot be undone. This will permanently delete this data and remove from our servers.'}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isLoading}>{cancelText || 'Cancel'}</AlertDialogCancel>
|
||||
<AlertDialogAction disabled={isLoading} onClick={confirm}>
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
{okText || 'Continue'}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
export default ConfirmAsync;
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from '@/app/admin/rbac/user-role/component/RoleForm';
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from '@/app/admin/rbac/user-role/component';
|
||||
@@ -1,4 +0,0 @@
|
||||
import { type IRole } from '@/types/rbac';
|
||||
|
||||
export type { IRole };
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
export interface IRole {
|
||||
id: number,
|
||||
name: string,
|
||||
status: {
|
||||
id: number,
|
||||
code: "A" | 'N' | 'X',
|
||||
name: "ACTIVE" | 'INACTIVE' | 'DELETED'
|
||||
},
|
||||
description: string
|
||||
allow_admin?: boolean
|
||||
privilege?: any
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export default function DeprecatedUserRolePage() {
|
||||
redirect('/admin/rbac/user-role');
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -13,35 +12,9 @@ export const metadata: Metadata = {
|
||||
title: "Admin | Master Working Status",
|
||||
}
|
||||
|
||||
async function getData(current_page?: string, limit?: string) {
|
||||
const { BASE_URL_API } = process.env
|
||||
const session = await getServerSession(authOptions)
|
||||
|
||||
const res = await fetch(BASE_URL_API + '/presence/list-status', {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session?.user.access_token}`,
|
||||
},
|
||||
cache: 'no-cache',
|
||||
next: {
|
||||
tags: ['working-status']
|
||||
}
|
||||
})
|
||||
|
||||
const data: ResponseData = await res.json()
|
||||
|
||||
// Recommendation: handle errors
|
||||
if (!res.ok) {
|
||||
// This will activate the closest `error.js` Error Boundary
|
||||
throw new Error(`Failed to fetch data, ${data.code || res.status} ${data.message || res.statusText}`)
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
|
||||
export default async function page() {
|
||||
const data = await getData()
|
||||
export default async function WorkingStatusPage() {
|
||||
await getAccessPagePermission('/information/working-status')
|
||||
const data = await fetchData('/presence/list-status', 'no-cache', { tags: ['working-status'] })
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { forbidden } from "next/navigation";
|
||||
import { ToggleTheme } from "./components/ToggleTheme";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Notification from "./components/Notification";
|
||||
@@ -22,6 +23,10 @@ export const metadata: Metadata = {
|
||||
export default async function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const data = await getAccessData()
|
||||
|
||||
if (!data?.allow_admin_panel) {
|
||||
forbidden()
|
||||
}
|
||||
|
||||
const cleanPath = (path: string): string => {
|
||||
if (!path || path === '/') return ''
|
||||
const sanitized = path.replace(/\/+/g, '/')
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
@@ -19,6 +20,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const ApprovalAutoCheckoutPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/manual/approval-autocheckout')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -33,9 +36,11 @@ const ApprovalAutoCheckoutPage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Approval Auto Checkout</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of employee attendance that forgot to checkout!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import dayjs from 'dayjs';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const ApprovalNonWFOPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/manual/approval')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -32,9 +35,11 @@ const ApprovalNonWFOPage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Approval Attendance</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of approval attendance those working outside the office!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
@@ -15,7 +15,7 @@ export const metadata: Metadata = {
|
||||
type Props = {};
|
||||
|
||||
const ManualPresencePage: FC<Props> = async () => {
|
||||
const actions = await getAccessPagePermission('/manual/manual-presence', 'CREATE')
|
||||
const actions = await getAccessPagePermission('/manual/manual-presence')
|
||||
|
||||
const fetchUser = fetchData('/user')
|
||||
const fetchStatus = fetchData('/presence/list-status')
|
||||
|
||||
@@ -5,10 +5,8 @@ import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
@@ -21,9 +19,10 @@ import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInpu
|
||||
|
||||
type Props = {
|
||||
data: IClient[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IClient[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IClient>()
|
||||
@@ -133,7 +132,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
@@ -143,10 +142,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem><Link href={`/task/client-detail/${record.id}`} className='w-full'>View Details</Link></DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -175,10 +178,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Client
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Client
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
|
||||
title: "Client - Project Assignment | Admin",
|
||||
}
|
||||
export default async function ClientPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/client')
|
||||
const data = await fetchData('/client')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function ClientPage() {
|
||||
<CardTitle>Client Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of clients that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
<ComponentPage data={data} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -18,9 +18,10 @@ import FormEndUser from '@/app/(dashboard)/task/component/FormEndUser';
|
||||
|
||||
type Props = {
|
||||
data: IEndUser[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IEndUser[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IEndUser>()
|
||||
@@ -115,7 +116,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
@@ -124,10 +125,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit End User</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete End User
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit End User</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete End User
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -156,10 +161,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New End User
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New End User
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
|
||||
title: "End User - Project Assignment | Admin",
|
||||
}
|
||||
export default async function EndUserPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/end-user')
|
||||
const data = await fetchData('/end-user')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function EndUserPage() {
|
||||
<CardTitle>End User Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of end users that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
<ComponentPage data={data} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -17,9 +17,10 @@ import FormProject from './FormProject';
|
||||
|
||||
type Props = {
|
||||
data: IProjectAssignment[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IProjectAssignment[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IProjectAssignment>()
|
||||
@@ -135,7 +136,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
||||
@@ -144,10 +145,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Project</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Project
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Project</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Project
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -176,10 +181,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Project
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Project
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
|
||||
title: "Project - Project Assignment | Admin",
|
||||
}
|
||||
export default async function ProjectManagementPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/project-management')
|
||||
const data = await fetchData('/project')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function ProjectManagementPage() {
|
||||
<CardTitle>Project Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of projects that have been registered for project assignment!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data} />
|
||||
<ComponentPage data={data} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -19,9 +19,10 @@ import RbacBadge from '@/components/ui/rbac-badge';
|
||||
|
||||
type Props = {
|
||||
data: IPermission[];
|
||||
actions?: string[];
|
||||
};
|
||||
|
||||
const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPermissionPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IPermission[]>([]);
|
||||
const [selectedData, setSelectedData] = useState<IPermission | undefined>(undefined);
|
||||
const [showFormDialog, setShowFormDialog] = useState(false);
|
||||
@@ -97,7 +98,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
key: 'action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE') && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -107,19 +108,23 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Permission
|
||||
</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Permission
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Permission
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Permission
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -160,18 +165,20 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Permission
|
||||
</Button>
|
||||
{(!actions || actions.includes('CREATE')) && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Permission
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Table
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -27,6 +28,7 @@ async function getPermissions() {
|
||||
}
|
||||
|
||||
export default async function PermissionPage() {
|
||||
const actions = await getAccessPagePermission(['/rbac/action-permissions', '/rbac/action-pemission']);
|
||||
const permissions = await getPermissions();
|
||||
|
||||
return (
|
||||
@@ -42,7 +44,7 @@ export default async function PermissionPage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={permissions} />
|
||||
<ComponentPage data={permissions} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { useRouter } from 'next/navigation';
|
||||
|
||||
type Props = {
|
||||
data: IMenu[];
|
||||
actions?: string[];
|
||||
};
|
||||
|
||||
// Transform flat menu list into hierarchical tree for Antd Table
|
||||
@@ -61,7 +62,7 @@ function buildMenuTree(items: IMenu[]): IMenu[] {
|
||||
return roots;
|
||||
}
|
||||
|
||||
const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
const ComponentMenuPage: FC<Props> = ({ data, actions }) => {
|
||||
const [rawMenus, setRawMenus] = useState<IMenu[]>([]);
|
||||
const [filterData, setFilterData] = useState<IMenu[]>([]);
|
||||
const [selectedData, setSelectedData] = useState<IMenu | undefined>(undefined);
|
||||
@@ -205,7 +206,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
key: 'row_action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -215,19 +216,23 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Menu
|
||||
</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Menu
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedData(record);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit Menu
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Menu
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -267,18 +272,20 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Menu
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
onClick={() => {
|
||||
setSelectedData(undefined);
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Menu
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Table
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -27,6 +28,7 @@ async function getMenus() {
|
||||
}
|
||||
|
||||
export default async function MenuPage() {
|
||||
const actions = await getAccessPagePermission('/rbac/menu');
|
||||
const menus = await getMenus();
|
||||
|
||||
return (
|
||||
@@ -42,7 +44,7 @@ export default async function MenuPage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={menus} />
|
||||
<ComponentPage data={menus} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { type Metadata } from 'next';
|
||||
import Link from 'next/link';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type IRole } from '../component/type';
|
||||
import RolePermissionRow from "../component/role-permission-row";
|
||||
@@ -39,6 +40,7 @@ async function getRoleData(id: string): Promise<IRole | undefined> {
|
||||
}
|
||||
|
||||
const UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
||||
const actions = await getAccessPagePermission('/rbac/user-role', 'VIEW');
|
||||
const { id } = await params;
|
||||
const data: IRole | undefined = await getRoleData(id);
|
||||
|
||||
@@ -109,11 +111,13 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
||||
</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
<Link href={`/admin/rbac/user-role/edit/${id}`}>
|
||||
<Button className="bg-his hover:bg-his/90 text-white font-medium">
|
||||
<PencilLine /> Edit Role
|
||||
</Button>
|
||||
</Link>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<Link href={`/admin/rbac/user-role/edit/${id}`}>
|
||||
<Button className="bg-his hover:bg-his/90 text-white font-medium">
|
||||
<PencilLine /> Edit Role
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 p-4 md:p-6 rounded-lg bg-zinc-50/60 dark:bg-zinc-900/40 border border-zinc-200 dark:border-zinc-800">
|
||||
|
||||
@@ -17,9 +17,10 @@ import { type IRole } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IRole[];
|
||||
actions?: string[];
|
||||
};
|
||||
|
||||
const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
const ComponentRolePage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IRole[]>([]);
|
||||
const [searchText, setSearchText] = useState('');
|
||||
|
||||
@@ -140,7 +141,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
key: 'action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -155,16 +156,20 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
View Details
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/admin/rbac/user-role/edit/${record.id}`}>
|
||||
Edit Role
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Role
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href={`/admin/rbac/user-role/edit/${record.id}`}>
|
||||
Edit Role
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete Role
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -204,16 +209,18 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</div>
|
||||
<Link href="/admin/rbac/user-role/create">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Role
|
||||
</Button>
|
||||
</Link>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Link href="/admin/rbac/user-role/create">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create Role
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Table
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import RoleForm from '../component/RoleForm';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
@@ -6,6 +7,7 @@ export const metadata: Metadata = {
|
||||
description: "Create a new user role with custom menu permissions",
|
||||
};
|
||||
|
||||
export default function CreateRolePage() {
|
||||
export default async function CreateRolePage() {
|
||||
await getAccessPagePermission('/rbac/user-role', 'CREATE');
|
||||
return <RoleForm isUpdate={false} />;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type Metadata } from 'next';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
import RoleForm from '../../component/RoleForm';
|
||||
import { type IRole } from '../../component/type';
|
||||
|
||||
@@ -34,6 +35,7 @@ async function getRoleData(id: string): Promise<IRole | undefined> {
|
||||
}
|
||||
|
||||
export default async function EditRolePage({ params }: Props) {
|
||||
await getAccessPagePermission('/rbac/user-role', 'UPDATE');
|
||||
const { id } = await params;
|
||||
const roleData = await getRoleData(id);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -27,6 +28,7 @@ async function getRoles() {
|
||||
}
|
||||
|
||||
export default async function UserRolePage() {
|
||||
const actions = await getAccessPagePermission('/rbac/user-role');
|
||||
const roles = await getRoles();
|
||||
|
||||
return (
|
||||
@@ -42,7 +44,7 @@ export default async function UserRolePage() {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={roles} />
|
||||
<ComponentPage data={roles} actions={actions} />
|
||||
</Suspense>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -12,9 +12,10 @@ const ExportComponent = lazy(() => import('./Export'));
|
||||
|
||||
type Props = {
|
||||
data: IHistory[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [groupData, setGroupData] = useState<any>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -664,9 +665,11 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<CardTitle>Attendance Distribution</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of all employee attendance distribution!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={groupData} />
|
||||
</Suspense>
|
||||
{actions?.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={groupData} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const AttendanceDistributionPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/distribution')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -28,7 +31,7 @@ const AttendanceDistributionPage: FC<Props> = async ({ searchParams }) => {
|
||||
<div className="flex flex-col">
|
||||
<Card>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ComponentPage data={data.history} />
|
||||
<ComponentPage data={data.history} actions={actions} />
|
||||
</Suspense>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -13,9 +13,10 @@ import useDebounce from '@/hooks/useDebounce';
|
||||
|
||||
type Props = {
|
||||
data: IHistory[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [currentDataTable, setCurrentDataTable] = useState<IHistory[]>([])
|
||||
const [searchText, setSearchText] = useState<string>('')
|
||||
|
||||
@@ -79,15 +80,17 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<CardTitle>Attendance History</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of all employee attendance history!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={exportData} />
|
||||
</Suspense>
|
||||
{actions?.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={exportData} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search report..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
<Input placeholder="Search report..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
</div>
|
||||
<Table
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
@@ -17,6 +18,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const MonthlyPresencePage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/history')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -27,9 +30,7 @@ const MonthlyPresencePage: FC<Props> = async ({ searchParams }) => {
|
||||
<div className="flex flex-col">
|
||||
<Card>
|
||||
<Suspense fallback={<div className='flex justify-center items-center w-full h-[40vh]'><LazyLoading /></div>}>
|
||||
<ComponentPage
|
||||
data={data.history}
|
||||
/>
|
||||
<ComponentPage data={data.history} actions={actions} />
|
||||
</Suspense>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import dayjs from 'dayjs';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const LeavePermitSickReportPage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/leave-permit-sick')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -32,9 +35,11 @@ const LeavePermitSickReportPage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Leave, Permit and Sick Report</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of application form for leave, permit and sick!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.history} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import dayjs from 'dayjs';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getAccessPagePermission } from '@/lib/get-access-data';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
const ExportComponent = lazy(() => import('./component/Export'));
|
||||
@@ -18,6 +19,8 @@ type Props = {
|
||||
};
|
||||
|
||||
const SummaryAttendancePage: FC<Props> = async ({ searchParams }) => {
|
||||
const actions = await getAccessPagePermission('/report/monthly-presence')
|
||||
|
||||
const start_date = (await searchParams)!.start_date
|
||||
const end_date = (await searchParams)!.end_date
|
||||
|
||||
@@ -32,9 +35,11 @@ const SummaryAttendancePage: FC<Props> = async ({ searchParams }) => {
|
||||
<CardTitle>Summary Attendance Report</CardTitle>
|
||||
<CardDescription className='mt-1 sm:block hidden'>Here's a list of summary employee attendance report!</CardDescription>
|
||||
</div>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.report} />
|
||||
</Suspense>
|
||||
{actions.includes('EXPORT') &&
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
<ExportComponent data={data.report} />
|
||||
</Suspense>
|
||||
}
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Suspense fallback={<LazyLoading />}>
|
||||
|
||||
+22
-8
@@ -44,24 +44,38 @@ export const getAccessData = cache(async () => {
|
||||
});
|
||||
|
||||
|
||||
export async function getAccessPagePermission(path: string, action: string = "view") {
|
||||
export async function getAccessPagePermission(path: string | string[], action: string = "view") {
|
||||
const accessData = await getAccessData();
|
||||
|
||||
const normalize = (p: string) => (p || '').trim().replace(/^\/+|\/+$/g, '').toLowerCase();
|
||||
const targetPaths = (Array.isArray(path) ? path : [path]).map(normalize);
|
||||
|
||||
// Check whether the current page is registered
|
||||
const menu = accessData?.role_detail?.find((item: any) => item.menu?.path_url === path);
|
||||
const menu = accessData?.role_detail?.find((item: any) => {
|
||||
const itemPath = normalize(item.menu?.path_url || '');
|
||||
if (!itemPath) return false;
|
||||
if (targetPaths.includes(itemPath)) return true;
|
||||
if (targetPaths.includes('rbac/action-permissions') && itemPath === 'rbac/action-pemission') return true;
|
||||
if (targetPaths.includes('rbac/action-pemission') && itemPath === 'rbac/action-permissions') return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!menu?.menu) {
|
||||
// redirect(redirectPage);
|
||||
forbidden()
|
||||
forbidden();
|
||||
}
|
||||
|
||||
// Role-specific assigned actions take precedence; fallback to menu actions if role actions are absent
|
||||
const permittedActions: string[] = (Array.isArray(menu?.action) && menu.action.length > 0)
|
||||
? menu.action
|
||||
: (Array.isArray(menu?.menu?.action) ? menu.menu.action : []);
|
||||
|
||||
// Check whether the user has permission
|
||||
if (!menu?.menu?.action?.includes(action.toUpperCase())) {
|
||||
// redirect(redirectPage);
|
||||
forbidden()
|
||||
const hasPermission = permittedActions.some((act: string) => act.toUpperCase() === action.toUpperCase());
|
||||
if (!hasPermission) {
|
||||
forbidden();
|
||||
}
|
||||
|
||||
return menu?.menu?.action;
|
||||
return permittedActions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user