- Updated paginated methods in multiple services to accept a highlight parameter for filtering results. - Modified notification URLs to include the highlight parameter for specific entity IDs. - Enhanced frontend components to display a message when filtered by notification, with an option to show all entries. - Implemented mark as read functionality in the notification bell component upon clicking a notification. - Updated multiple index pages to handle the highlight prop and display relevant messages.
166 lines
5.5 KiB
TypeScript
166 lines
5.5 KiB
TypeScript
import { Head, router } from '@inertiajs/react';
|
|
import { useState } from 'react';
|
|
import type { PaginationState } from '@/components/data-display';
|
|
import { DataTable } from '@/components/data-display';
|
|
import { DeleteConfirmDialog } from '@/components/dialogs';
|
|
import { PageHeader } from '@/components/layout';
|
|
import { useCan } from '@/hooks/use-can';
|
|
import { useServerTable } from '@/hooks/use-server-table';
|
|
import { MONTH_NAMES } from '@/lib/constants';
|
|
import {
|
|
index as payrollPeriodsIndex,
|
|
show as payrollPeriodShow,
|
|
close,
|
|
reopen,
|
|
} from '@/routes/admin/finance/payroll-periods';
|
|
import { createPayrollPeriodColumns } from './columns';
|
|
import type { PayrollPeriod } from './columns';
|
|
|
|
type Props = {
|
|
payrollPeriods: {
|
|
data: PayrollPeriod[];
|
|
current_page: number;
|
|
last_page: number;
|
|
per_page: number;
|
|
total: number;
|
|
};
|
|
highlight?: number;
|
|
};
|
|
|
|
export default function PayrollPeriodIndex({ payrollPeriods, highlight }: Props) {
|
|
const { can, hasAnyRole } = useCan();
|
|
const canViewAll = hasAnyRole(['developer', 'owner', 'direktur', 'admin-toko']);
|
|
const [closing, setClosing] = useState<PayrollPeriod | null>(null);
|
|
const [reopening, setReopening] = useState<PayrollPeriod | null>(null);
|
|
|
|
const pagination: PaginationState = {
|
|
current_page: payrollPeriods.current_page,
|
|
last_page: payrollPeriods.last_page,
|
|
per_page: payrollPeriods.per_page,
|
|
total: payrollPeriods.total,
|
|
};
|
|
|
|
const {
|
|
search,
|
|
handlePageChange,
|
|
handlePerPageChange,
|
|
handleSearchChange,
|
|
} = useServerTable({
|
|
route: () => payrollPeriodsIndex.url(),
|
|
pagination,
|
|
});
|
|
|
|
function handleClose() {
|
|
if (!closing) {
|
|
return;
|
|
}
|
|
|
|
router.post(
|
|
close(closing.id),
|
|
{},
|
|
{
|
|
onSuccess: () => setClosing(null),
|
|
},
|
|
);
|
|
}
|
|
|
|
function handleReopen() {
|
|
if (!reopening) {
|
|
return;
|
|
}
|
|
|
|
router.post(
|
|
reopen(reopening.id),
|
|
{},
|
|
{
|
|
onSuccess: () => setReopening(null),
|
|
},
|
|
);
|
|
}
|
|
|
|
const columns = createPayrollPeriodColumns({
|
|
showUrl: (id) => payrollPeriodShow(id).url,
|
|
handleClose: (period) => setClosing(period),
|
|
handleReopen: (period) => setReopening(period),
|
|
can,
|
|
canViewAll,
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<Head title="Gaji" />
|
|
|
|
<div className="flex h-full flex-1 flex-col gap-6 overflow-x-auto p-4 md:p-6">
|
|
<PageHeader
|
|
title="Gaji"
|
|
description={
|
|
highlight && (
|
|
<p className="mt-1 text-sm text-muted-foreground">
|
|
Menampilkan periode gaji dari notifikasi.
|
|
<button
|
|
onClick={() => {
|
|
router.get(
|
|
payrollPeriodsIndex.url(),
|
|
{},
|
|
{
|
|
replace: true,
|
|
preserveState: true,
|
|
},
|
|
);
|
|
}}
|
|
className="ml-1 text-primary underline underline-offset-4 hover:text-primary/80"
|
|
>
|
|
Tampilkan semua
|
|
</button>
|
|
</p>
|
|
)
|
|
}
|
|
/>
|
|
|
|
<DataTable
|
|
columns={columns}
|
|
data={payrollPeriods.data}
|
|
searchKey="year"
|
|
|
|
emptyText="Belum ada periode gaji."
|
|
pagination={pagination}
|
|
onPageChange={handlePageChange}
|
|
onPerPageChange={handlePerPageChange}
|
|
onSearchChange={handleSearchChange}
|
|
searchValue={search}
|
|
/>
|
|
|
|
<DeleteConfirmDialog
|
|
target={closing}
|
|
onOpenChange={(open) => {
|
|
if (!open) {
|
|
setClosing(null);
|
|
}
|
|
}}
|
|
title="Tutup Periode Gaji"
|
|
description={(period) =>
|
|
`Apakah Anda yakin ingin menutup periode gaji ${MONTH_NAMES[period.month]} ${period.year}? Semua gaji harus sudah dibayar sebelum periode ditutup.`
|
|
}
|
|
confirmLabel="Tutup"
|
|
onConfirm={handleClose}
|
|
/>
|
|
|
|
<DeleteConfirmDialog
|
|
target={reopening}
|
|
onOpenChange={(open) => {
|
|
if (!open) {
|
|
setReopening(null);
|
|
}
|
|
}}
|
|
title="Buka Periode Gaji"
|
|
description={(period) =>
|
|
`Apakah Anda yakin ingin membuka kembali periode gaji ${MONTH_NAMES[period.month]} ${period.year}?`
|
|
}
|
|
confirmLabel="Buka"
|
|
onConfirm={handleReopen}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|