fix: button delete in table user level
This commit is contained in:
parent
24c0adfa8d
commit
266a1cacf6
|
|
@ -19,6 +19,7 @@ import { error } from "@/lib/swal";
|
|||
import Swal from "sweetalert2";
|
||||
import withReactContent from "sweetalert2-react-content";
|
||||
import Link from "next/link";
|
||||
import { deleteUserLevel } from "@/service/tenant";
|
||||
|
||||
const useTableColumns = () => {
|
||||
const MySwal = withReactContent(Swal);
|
||||
|
|
@ -38,7 +39,7 @@ const useTableColumns = () => {
|
|||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
{
|
||||
accessorKey: "aliasName",
|
||||
header: "Name",
|
||||
cell: ({ row }) => (
|
||||
|
|
@ -64,7 +65,7 @@ const useTableColumns = () => {
|
|||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
{
|
||||
accessorKey: "parentLevelName",
|
||||
header: "Parent Level",
|
||||
cell: ({ row }) => (
|
||||
|
|
@ -185,19 +186,16 @@ const useTableColumns = () => {
|
|||
const router = useRouter();
|
||||
const MySwal = withReactContent(Swal);
|
||||
|
||||
async function doDelete(id: any) {
|
||||
const data = { id };
|
||||
const response = await deleteMedia(data);
|
||||
async function doDelete(id: number) {
|
||||
const response = await deleteUserLevel(id);
|
||||
if (response?.error) {
|
||||
error(response.message);
|
||||
return false;
|
||||
error(response.message || "Gagal menghapus data");
|
||||
return;
|
||||
}
|
||||
success();
|
||||
}
|
||||
|
||||
function success() {
|
||||
MySwal.fire({
|
||||
title: "Sukses",
|
||||
text: "User Level berhasil dihapus.",
|
||||
icon: "success",
|
||||
confirmButtonColor: "#3085d6",
|
||||
confirmButtonText: "OK",
|
||||
|
|
@ -208,6 +206,23 @@ const useTableColumns = () => {
|
|||
});
|
||||
}
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
MySwal.fire({
|
||||
title: "Yakin ingin menghapus?",
|
||||
text: "Data ini tidak dapat dikembalikan!",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Ya, hapus",
|
||||
cancelButtonText: "Batal",
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#3085d6",
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
doDelete(id);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const handleDeleteMedia = (id: any) => {
|
||||
MySwal.fire({
|
||||
title: "Hapus Data",
|
||||
|
|
@ -230,7 +245,9 @@ const useTableColumns = () => {
|
|||
|
||||
React.useEffect(() => {
|
||||
if (userLevelId !== undefined && roleId !== undefined) {
|
||||
setIsMabesApprover(Number(userLevelId) === 216 && Number(roleId) === 3);
|
||||
setIsMabesApprover(
|
||||
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||
);
|
||||
}
|
||||
}, [userLevelId, roleId]);
|
||||
|
||||
|
|
@ -246,22 +263,22 @@ const useTableColumns = () => {
|
|||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="p-0 hover:text-black" align="end">
|
||||
<Link
|
||||
href={`/admin/content/image/detail/${row.original.id}`}
|
||||
{/* <Link
|
||||
href={`/admin/settings/tenant/detail/${row.original.id}`}
|
||||
className="hover:text-black"
|
||||
>
|
||||
<DropdownMenuItem className="p-2 border-b text-default-700 rounded-none">
|
||||
<Eye className="w-4 h-4 me-1.5" />
|
||||
View
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
</Link> */}
|
||||
{/* {(Number(row.original.uploadedById) === Number(userId) || isMabesApprover) && ( */}
|
||||
<Link href={`/admin/content/image/update/${row.original.id}`}>
|
||||
<DropdownMenuItem className="p-2 border-b text-default-700 rounded-none">
|
||||
<SquarePen className="w-4 h-4 me-1.5" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
<Link href={`/admin/settings/tenant/update/${row.original.id}`}>
|
||||
<DropdownMenuItem className="p-2 border-b text-default-700 rounded-none">
|
||||
<SquarePen className="w-4 h-4 me-1.5" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
{/* )} */}
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDeleteMedia(row.original.id)}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
import React from 'react'
|
||||
|
||||
const page = () => {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default page
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import React from 'react'
|
||||
|
||||
const page = () => {
|
||||
return (
|
||||
<div>page</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default page
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import React from 'react'
|
||||
|
||||
const TenantDetailForm = () => {
|
||||
return (
|
||||
<div>TenantDetailForm</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default TenantDetailForm
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import React from 'react'
|
||||
|
||||
const TenantUpdateForm = () => {
|
||||
return (
|
||||
<div>TenantUpdateForm</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default TenantUpdateForm
|
||||
|
|
@ -36,10 +36,9 @@ export default function Navbar() {
|
|||
|
||||
const [isDropdownOpen, setDropdownOpen] = useState(false);
|
||||
const [showProfileMenu, setShowProfileMenu] = useState(false);
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
const pathname = usePathname();
|
||||
|
||||
|
||||
|
||||
// useEffect(() => {
|
||||
// const roleId = getCookiesDecrypt("urie");
|
||||
// console.log("roleId", roleId);
|
||||
|
|
@ -81,24 +80,64 @@ export default function Navbar() {
|
|||
// }
|
||||
// }, []);
|
||||
|
||||
const roleId = getCookiesDecrypt("urie");
|
||||
const isLoggedIn = roleId !== null;
|
||||
// const roleId = getCookiesDecrypt("urie");
|
||||
// const isLoggedIn = roleId !== null;
|
||||
|
||||
// 🔍 Fungsi untuk mengecek apakah user sedang login
|
||||
const checkLoginStatus = () => {
|
||||
const roleId = getCookiesDecrypt("urie");
|
||||
const fullname = Cookies.get("ufne");
|
||||
return roleId && fullname ? true : false;
|
||||
};
|
||||
|
||||
// 🔄 Cek status login saat pertama kali load
|
||||
useEffect(() => {
|
||||
setIsLoggedIn(checkLoginStatus());
|
||||
}, []);
|
||||
|
||||
// const filteredNavItems = isLoggedIn
|
||||
// ? NAV_ITEMS.filter((item) => item.label !== "Mengikuti")
|
||||
// : NAV_ITEMS;
|
||||
|
||||
// 🔁 Gunakan isLoggedIn untuk menentukan navigasi
|
||||
const filteredNavItems = isLoggedIn
|
||||
? NAV_ITEMS.filter((item) => item.label !== "Mengikuti")
|
||||
: NAV_ITEMS;
|
||||
|
||||
// 🚪 Fungsi logout
|
||||
const handleLogout = () => {
|
||||
// Hapus semua cookie dengan kemungkinan variasi path dan domain
|
||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
||||
Cookies.remove(cookieName);
|
||||
Cookies.remove(cookieName, { path: "/" });
|
||||
Cookies.remove(cookieName, {
|
||||
path: "",
|
||||
domain: window.location.hostname,
|
||||
});
|
||||
Cookies.remove(cookieName, {
|
||||
path: "/",
|
||||
domain: window.location.hostname,
|
||||
});
|
||||
});
|
||||
|
||||
window.location.href = "/";
|
||||
|
||||
// setUser(null);
|
||||
// Ubah state login jadi false agar tampilan langsung berubah
|
||||
setIsLoggedIn(false);
|
||||
setShowProfileMenu(false);
|
||||
|
||||
// Redirect ke homepage
|
||||
window.location.href = "/";
|
||||
};
|
||||
|
||||
// const handleLogout = () => {
|
||||
// Object.keys(Cookies.get()).forEach((cookieName) => {
|
||||
// Cookies.remove(cookieName);
|
||||
// });
|
||||
|
||||
// window.location.href = "/";
|
||||
|
||||
// // setUser(null);
|
||||
// setShowProfileMenu(false);
|
||||
// };
|
||||
|
||||
const username = Cookies.get("username");
|
||||
const fullname = Cookies.get("ufne");
|
||||
// const router = useRouter();
|
||||
|
|
@ -215,8 +254,8 @@ export default function Navbar() {
|
|||
>
|
||||
<div className="w-9 h-9 rounded-full overflow-hidden border">
|
||||
<Image
|
||||
src="/contributor.png"
|
||||
alt={username as string}
|
||||
src="/avatar-profile.png"
|
||||
alt={username || "User avatar"}
|
||||
width={36}
|
||||
height={36}
|
||||
className="object-cover"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
import { httpDeleteInterceptor } from "./http-config/http-interceptor-service";
|
||||
|
||||
export async function deleteUserLevel(id: number) {
|
||||
const url = `user-levels/${id}`;
|
||||
return await httpDeleteInterceptor(url);
|
||||
}
|
||||
Loading…
Reference in New Issue