58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
import Header from "./Header";
|
|
import { Suspense, useEffect, useRef, useState } from "react";
|
|
import SuspenseContent from "./SuspenseContent";
|
|
import { useSelector } from 'react-redux';
|
|
import { usePage } from "@inertiajs/react";
|
|
import Swal from "sweetalert2"
|
|
|
|
function PageContent({ children }) {
|
|
const mainContentRef = useRef(null);
|
|
const { pageTitle } = useSelector(state => state.header);
|
|
const { url } = usePage(); // Ambil URL dari Inertia
|
|
const [isLoginPage, setIsLoginPage] = useState(false);
|
|
const { flash } = usePage().props;
|
|
|
|
useEffect(() => {
|
|
if (flash.success) {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Success',
|
|
text: flash.success
|
|
});
|
|
} else if (flash.error) {
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Success',
|
|
text: flash.success
|
|
});
|
|
}
|
|
}, [flash]);
|
|
useEffect(() => {
|
|
mainContentRef.current?.scroll({
|
|
top: 0,
|
|
behavior: "smooth"
|
|
});
|
|
}, [pageTitle]);
|
|
|
|
// Update state saat route berubah
|
|
useEffect(() => {
|
|
setIsLoginPage(url === "/login");
|
|
}, [url]);
|
|
|
|
return (
|
|
<div className="drawer-content flex flex-col">
|
|
{!isLoginPage && <Header />}
|
|
<main className="flex-1 overflow-y-auto md:pt-4 pt-4 px-6 bg-base-200" ref={mainContentRef}>
|
|
<Suspense fallback={<SuspenseContent />}>
|
|
<div className="min-h-screen">
|
|
{children}
|
|
</div>
|
|
</Suspense>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default PageContent;
|
|
|