staggingweb #25
@@ -93,6 +93,7 @@ function ListUser({ search }: { search: string }) {
|
|||||||
const success = await stateUser.update.submit({
|
const success = await stateUser.update.submit({
|
||||||
id: userId,
|
id: userId,
|
||||||
roleId: newRoleId,
|
roleId: newRoleId,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -136,9 +137,10 @@ function ListUser({ search }: { search: string }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredData = (data || []).filter(
|
const filteredData = (data || []).filter((item) => {
|
||||||
(item) => item.roleId !== "0" // asumsikan id role SUPERADMIN = "0"
|
return item.roleId !== "0" && item.roleId !== "1";
|
||||||
);
|
});
|
||||||
|
|
||||||
|
|
||||||
if (loading || !data) {
|
if (loading || !data) {
|
||||||
return (
|
return (
|
||||||
@@ -183,7 +185,7 @@ function ListUser({ search }: { search: string }) {
|
|||||||
<Select
|
<Select
|
||||||
placeholder="Pilih role"
|
placeholder="Pilih role"
|
||||||
data={stateRole.findMany.data
|
data={stateRole.findMany.data
|
||||||
.filter(r => r.id !== "0") // ❌ Sembunyikan SUPERADMIN
|
.filter(r => r.id !== "0" && r.id !== "1") // ❌ Sembunyikan SUPERADMIN dan DEVELOPER
|
||||||
.map(r => ({
|
.map(r => ({
|
||||||
label: r.name,
|
label: r.name,
|
||||||
value: r.id,
|
value: r.id,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default async function userUpdate(context: Context) {
|
|||||||
|
|
||||||
const currentUser = await prisma.user.findUnique({
|
const currentUser = await prisma.user.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
select: { roleId: true, isActive: true }
|
select: { roleId: true, isActive: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!currentUser) {
|
if (!currentUser) {
|
||||||
@@ -31,7 +31,15 @@ export default async function userUpdate(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isRoleChanged = roleId && currentUser.roleId !== roleId;
|
const isRoleChanged = roleId && currentUser.roleId !== roleId;
|
||||||
const isActiveChanged = isActive !== undefined && currentUser.isActive !== isActive;
|
const isActiveChanged =
|
||||||
|
isActive !== undefined && currentUser.isActive !== isActive;
|
||||||
|
|
||||||
|
// ✅ Jika role berubah, hapus semua akses menu yang ada
|
||||||
|
if (isRoleChanged) {
|
||||||
|
await prisma.userMenuAccess.deleteMany({
|
||||||
|
where: { userId: id }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Update user
|
// Update user
|
||||||
const updatedUser = await prisma.user.update({
|
const updatedUser = await prisma.user.update({
|
||||||
@@ -48,10 +56,11 @@ export default async function userUpdate(context: Context) {
|
|||||||
nomor: true,
|
nomor: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
roleId: true,
|
roleId: true,
|
||||||
role: { select: { name: true } }
|
role: { select: { name: true } },
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// ✅ HAPUS SEMUA SESI USER DI DATABASE
|
// ✅ HAPUS SEMUA SESI USER DI DATABASE
|
||||||
if (isRoleChanged) {
|
if (isRoleChanged) {
|
||||||
await prisma.userSession.deleteMany({ where: { userId: id } });
|
await prisma.userSession.deleteMany({ where: { userId: id } });
|
||||||
@@ -65,8 +74,10 @@ export default async function userUpdate(context: Context) {
|
|||||||
message: isRoleChanged
|
message: isRoleChanged
|
||||||
? `Role ${updatedUser.username} diubah. User akan logout otomatis.`
|
? `Role ${updatedUser.username} diubah. User akan logout otomatis.`
|
||||||
: isActiveChanged
|
: isActiveChanged
|
||||||
? `${updatedUser.username} ${isActive ? 'diaktifkan' : 'dinonaktifkan'}.`
|
? `${updatedUser.username} ${
|
||||||
: "User berhasil diupdate"
|
isActive ? "diaktifkan" : "dinonaktifkan"
|
||||||
|
}.`
|
||||||
|
: "User berhasil diupdate",
|
||||||
};
|
};
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("❌ Error update user:", e);
|
console.error("❌ Error update user:", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user