chore: initial project import
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled
This commit is contained in:
84
app/team/[userId]/edit/page.tsx
Normal file
84
app/team/[userId]/edit/page.tsx
Normal file
@ -0,0 +1,84 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { RoleCode } from "@prisma/client";
|
||||
import { ShellPage } from "@/components/page-templates";
|
||||
import { Button, SectionCard } from "@/components/ui";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { updateTeamUser } from "@/lib/admin-crud";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function EditUserPage({ params }: { params: Promise<{ userId: string }> }) {
|
||||
const { userId } = await params;
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const roles = await prisma.role.findMany({
|
||||
where: { tenantId: session.tenantId, code: { in: [RoleCode.ADMIN_CLIENT, RoleCode.AGENT] } },
|
||||
orderBy: { code: "asc" }
|
||||
});
|
||||
const fullUser = await prisma.user.findFirst({
|
||||
where: { id: userId, tenantId: session.tenantId },
|
||||
include: { role: true }
|
||||
});
|
||||
if (!fullUser) {
|
||||
redirect("/team?error=user_not_found");
|
||||
}
|
||||
|
||||
return (
|
||||
<ShellPage shell="admin" title="Edit User" description="Update role dan status user.">
|
||||
<SectionCard title="User form">
|
||||
<form action={updateTeamUser} className="grid gap-4 md:max-w-2xl">
|
||||
<input type="hidden" name="userId" value={fullUser.id} />
|
||||
<input
|
||||
name="fullName"
|
||||
required
|
||||
defaultValue={fullUser.fullName}
|
||||
className="rounded-xl border border-line px-4 py-3"
|
||||
/>
|
||||
<input
|
||||
name="email"
|
||||
required
|
||||
type="email"
|
||||
defaultValue={fullUser.email}
|
||||
className="rounded-xl border border-line px-4 py-3"
|
||||
/>
|
||||
<label className="block text-sm">
|
||||
<span className="text-on-surface-variant">Role</span>
|
||||
<select name="roleId" defaultValue={fullUser.roleId} className="mt-2 w-full rounded-xl border border-line px-4 py-3">
|
||||
{roles.map((role) => (
|
||||
<option key={role.id} value={role.id}>
|
||||
{role.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="block text-sm">
|
||||
<span className="text-on-surface-variant">Status</span>
|
||||
<select name="status" defaultValue={fullUser.status} className="mt-2 w-full rounded-xl border border-line px-4 py-3">
|
||||
<option value="INVITED">Invited</option>
|
||||
<option value="ACTIVE">Active</option>
|
||||
<option value="DISABLED">Disabled</option>
|
||||
</select>
|
||||
</label>
|
||||
<input
|
||||
name="password"
|
||||
type="password"
|
||||
placeholder="Password baru (opsional)"
|
||||
className="md:col-span-2 rounded-xl border border-line px-4 py-3"
|
||||
/>
|
||||
<div className="md:col-span-2 flex gap-3">
|
||||
<Button type="submit" className="rounded-xl">
|
||||
Save changes
|
||||
</Button>
|
||||
<Link href={`/team/${fullUser.id}`} className="text-on-surface-variant hover:underline">
|
||||
Cancel
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
</SectionCard>
|
||||
</ShellPage>
|
||||
);
|
||||
}
|
||||
58
app/team/[userId]/page.tsx
Normal file
58
app/team/[userId]/page.tsx
Normal file
@ -0,0 +1,58 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { ShellPage } from "@/components/page-templates";
|
||||
import { SectionCard } from "@/components/ui";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function UserDetailPage({ params }: { params: Promise<{ userId: string }> }) {
|
||||
const { userId } = await params;
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const user = await prisma.user.findFirst({
|
||||
where: { id: userId, tenantId: session.tenantId },
|
||||
include: { role: true, assignedConversations: true }
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
redirect("/team?error=user_not_found");
|
||||
}
|
||||
|
||||
return (
|
||||
<ShellPage
|
||||
shell="admin"
|
||||
title="User Detail"
|
||||
description="Role, status, assigned conversations, dan snapshot performa."
|
||||
actions={<Link href={`/team/${user.id}/edit`}>Edit user</Link>}
|
||||
>
|
||||
<div className="grid gap-6 xl:grid-cols-2">
|
||||
<SectionCard title="User profile">
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Nama:</strong> {user.fullName}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Email:</strong> {user.email}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Role:</strong> {user.role.name}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Status:</strong> {user.status}
|
||||
</p>
|
||||
<p className="text-sm text-on-surface-variant">
|
||||
<strong>Last login:</strong> {user.lastLoginAt?.toLocaleString() || "-"}
|
||||
</p>
|
||||
</SectionCard>
|
||||
<SectionCard title="Performance snapshot">
|
||||
<p className="text-sm text-on-surface-variant">Handled conversations: {user.assignedConversations.length}</p>
|
||||
<p className="text-sm text-on-surface-variant">Avg response time: -</p>
|
||||
<p className="text-sm text-on-surface-variant">Resolved count: -</p>
|
||||
</SectionCard>
|
||||
</div>
|
||||
</ShellPage>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user