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 Swal from "sweetalert2";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { deleteUserLevel } from "@/service/tenant";
|
||||||
|
|
||||||
const useTableColumns = () => {
|
const useTableColumns = () => {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
|
|
@ -38,7 +39,7 @@ const useTableColumns = () => {
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "aliasName",
|
accessorKey: "aliasName",
|
||||||
header: "Name",
|
header: "Name",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
|
|
@ -64,7 +65,7 @@ const useTableColumns = () => {
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "parentLevelName",
|
accessorKey: "parentLevelName",
|
||||||
header: "Parent Level",
|
header: "Parent Level",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
|
|
@ -185,19 +186,16 @@ const useTableColumns = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
|
|
||||||
async function doDelete(id: any) {
|
async function doDelete(id: number) {
|
||||||
const data = { id };
|
const response = await deleteUserLevel(id);
|
||||||
const response = await deleteMedia(data);
|
|
||||||
if (response?.error) {
|
if (response?.error) {
|
||||||
error(response.message);
|
error(response.message || "Gagal menghapus data");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
success();
|
|
||||||
}
|
|
||||||
|
|
||||||
function success() {
|
|
||||||
MySwal.fire({
|
MySwal.fire({
|
||||||
title: "Sukses",
|
title: "Sukses",
|
||||||
|
text: "User Level berhasil dihapus.",
|
||||||
icon: "success",
|
icon: "success",
|
||||||
confirmButtonColor: "#3085d6",
|
confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
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) => {
|
const handleDeleteMedia = (id: any) => {
|
||||||
MySwal.fire({
|
MySwal.fire({
|
||||||
title: "Hapus Data",
|
title: "Hapus Data",
|
||||||
|
|
@ -230,7 +245,9 @@ const useTableColumns = () => {
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (userLevelId !== undefined && roleId !== undefined) {
|
if (userLevelId !== undefined && roleId !== undefined) {
|
||||||
setIsMabesApprover(Number(userLevelId) === 216 && Number(roleId) === 3);
|
setIsMabesApprover(
|
||||||
|
Number(userLevelId) === 216 && Number(roleId) === 3
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, [userLevelId, roleId]);
|
}, [userLevelId, roleId]);
|
||||||
|
|
||||||
|
|
@ -246,22 +263,22 @@ const useTableColumns = () => {
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="p-0 hover:text-black" align="end">
|
<DropdownMenuContent className="p-0 hover:text-black" align="end">
|
||||||
<Link
|
{/* <Link
|
||||||
href={`/admin/content/image/detail/${row.original.id}`}
|
href={`/admin/settings/tenant/detail/${row.original.id}`}
|
||||||
className="hover:text-black"
|
className="hover:text-black"
|
||||||
>
|
>
|
||||||
<DropdownMenuItem className="p-2 border-b text-default-700 rounded-none">
|
<DropdownMenuItem className="p-2 border-b text-default-700 rounded-none">
|
||||||
<Eye className="w-4 h-4 me-1.5" />
|
<Eye className="w-4 h-4 me-1.5" />
|
||||||
View
|
View
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link> */}
|
||||||
{/* {(Number(row.original.uploadedById) === Number(userId) || isMabesApprover) && ( */}
|
{/* {(Number(row.original.uploadedById) === Number(userId) || isMabesApprover) && ( */}
|
||||||
<Link href={`/admin/content/image/update/${row.original.id}`}>
|
<Link href={`/admin/settings/tenant/update/${row.original.id}`}>
|
||||||
<DropdownMenuItem className="p-2 border-b text-default-700 rounded-none">
|
<DropdownMenuItem className="p-2 border-b text-default-700 rounded-none">
|
||||||
<SquarePen className="w-4 h-4 me-1.5" />
|
<SquarePen className="w-4 h-4 me-1.5" />
|
||||||
Edit
|
Edit
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
{/* )} */}
|
{/* )} */}
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => handleDeleteMedia(row.original.id)}
|
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 [isDropdownOpen, setDropdownOpen] = useState(false);
|
||||||
const [showProfileMenu, setShowProfileMenu] = useState(false);
|
const [showProfileMenu, setShowProfileMenu] = useState(false);
|
||||||
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// const roleId = getCookiesDecrypt("urie");
|
// const roleId = getCookiesDecrypt("urie");
|
||||||
// console.log("roleId", roleId);
|
// console.log("roleId", roleId);
|
||||||
|
|
@ -81,24 +80,64 @@ export default function Navbar() {
|
||||||
// }
|
// }
|
||||||
// }, []);
|
// }, []);
|
||||||
|
|
||||||
const roleId = getCookiesDecrypt("urie");
|
// const roleId = getCookiesDecrypt("urie");
|
||||||
const isLoggedIn = roleId !== null;
|
// 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
|
const filteredNavItems = isLoggedIn
|
||||||
? NAV_ITEMS.filter((item) => item.label !== "Mengikuti")
|
? NAV_ITEMS.filter((item) => item.label !== "Mengikuti")
|
||||||
: NAV_ITEMS;
|
: NAV_ITEMS;
|
||||||
|
|
||||||
|
// 🚪 Fungsi logout
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
|
// Hapus semua cookie dengan kemungkinan variasi path dan domain
|
||||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
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 = "/";
|
// Ubah state login jadi false agar tampilan langsung berubah
|
||||||
|
setIsLoggedIn(false);
|
||||||
// setUser(null);
|
|
||||||
setShowProfileMenu(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 username = Cookies.get("username");
|
||||||
const fullname = Cookies.get("ufne");
|
const fullname = Cookies.get("ufne");
|
||||||
// const router = useRouter();
|
// const router = useRouter();
|
||||||
|
|
@ -215,8 +254,8 @@ export default function Navbar() {
|
||||||
>
|
>
|
||||||
<div className="w-9 h-9 rounded-full overflow-hidden border">
|
<div className="w-9 h-9 rounded-full overflow-hidden border">
|
||||||
<Image
|
<Image
|
||||||
src="/contributor.png"
|
src="/avatar-profile.png"
|
||||||
alt={username as string}
|
alt={username || "User avatar"}
|
||||||
width={36}
|
width={36}
|
||||||
height={36}
|
height={36}
|
||||||
className="object-cover"
|
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