refactor(FE): Refactor PurchaseTable to use Popover for row options menu

This commit is contained in:
rstubryan
2026-02-25 12:08:31 +07:00
parent 8be33b230b
commit 0af7b172a0
+60 -82
View File
@@ -12,10 +12,9 @@ import DebouncedTextInput from '@/components/input/DebouncedTextInput';
import Button from '@/components/Button'; import Button from '@/components/Button';
import { useModal } from '@/components/Modal'; import { useModal } from '@/components/Modal';
import ConfirmationModal from '@/components/modal/ConfirmationModal'; import ConfirmationModal from '@/components/modal/ConfirmationModal';
import PopoverButton from '@/components/popover/PopoverButton';
import PopoverContent from '@/components/popover/PopoverContent';
import SelectInput, { OptionType } from '@/components/input/SelectInput'; import SelectInput, { OptionType } from '@/components/input/SelectInput';
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
import RequirePermission from '@/components/helper/RequirePermission'; import RequirePermission from '@/components/helper/RequirePermission';
import StatusBadge from '@/components/helper/StatusBadge'; import StatusBadge from '@/components/helper/StatusBadge';
@@ -69,59 +68,72 @@ const getStatusBadgeColor = (status: string): Color => {
return statusBadgeColorMap[status] || 'neutral'; return statusBadgeColorMap[status] || 'neutral';
}; };
// ===== INTERFACES ===== // ===== ROW OPTIONS MENU =====
interface RowOptionsMenuProps {
type: 'dropdown' | 'collapse';
props: CellContext<Purchase, unknown>;
deleteClickHandler: () => void;
}
const RowOptionsMenu = ({ const RowOptionsMenu = ({
type = 'dropdown', popoverPosition = 'bottom',
props, props,
deleteClickHandler, deleteClickHandler,
}: RowOptionsMenuProps) => { }: {
popoverPosition: 'bottom' | 'top';
props: CellContext<Purchase, unknown>;
deleteClickHandler: () => void;
}) => {
const popoverId = `purchase#${props.row.original.id}`;
const popoverAnchorName = `--anchor-purchase#${props.row.original.id}`;
const closePopover = () => {
document.getElementById(popoverId)?.hidePopover();
};
return ( return (
<RowOptionsMenuWrapper type={type}> <div className='relative'>
<PopoverButton
tabIndex={0}
variant='ghost'
color='none'
popoverTarget={popoverId}
anchorName={popoverAnchorName}
>
<Icon icon='material-symbols:more-vert' width={16} height={16} />
</PopoverButton>
<PopoverContent
id={popoverId}
anchorName={popoverAnchorName}
position={popoverPosition === 'bottom' ? 'bottom-start' : 'left'}
className='w-full max-w-40 rounded-xl border border-base-content/5 shadow-sm'
>
<div className='flex flex-col bg-base-100 rounded-xl'>
<RequirePermission permissions='lti.purchase.detail'> <RequirePermission permissions='lti.purchase.detail'>
<Button <Button
href={`/purchase/detail/?purchaseId=${props.row.original.id}`} href={`/purchase/detail/?purchaseId=${props.row.original.id}`}
variant='ghost' variant='ghost'
color='primary' color='none'
className='justify-start text-sm' className='p-3 justify-start text-sm font-semibold w-full'
onClick={closePopover}
> >
<Icon icon='mdi:eye-outline' width={16} height={16} /> <Icon icon='heroicons:eye' width={20} height={20} />
Detail Detail
</Button> </Button>
</RequirePermission> </RequirePermission>
{/*<Button*/}
{/* href={`/purchase/detail/edit/?purchaseId=${props.row.original.id}`}*/}
{/* variant='ghost'*/}
{/* color='warning'*/}
{/* className='justify-start text-sm'*/}
{/*>*/}
{/* <Icon icon='material-symbols:edit-outline' width={16} height={16} />*/}
{/* Edit*/}
{/*</Button>*/}
<RequirePermission permissions='lti.purchase.delete'> <RequirePermission permissions='lti.purchase.delete'>
<Button <Button
onClick={deleteClickHandler} onClick={() => {
deleteClickHandler();
closePopover();
}}
variant='ghost' variant='ghost'
color='error' color='error'
className='justify-start text-sm text-error focus-visible:text-error-content hover:text-error-content' className='p-3 justify-start text-sm font-semibold w-full focus-visible:text-error-content hover:text-error-content'
> >
<Icon <Icon icon='mdi:delete-outline' width={20} height={20} />
icon='material-symbols:delete-outline-rounded'
width={16}
height={16}
className='justify-start text-sm'
/>
Delete Delete
</Button> </Button>
</RequirePermission> </RequirePermission>
</RowOptionsMenuWrapper> </div>
</PopoverContent>
</div>
); );
}; };
@@ -346,27 +358,11 @@ const PurchaseTable = () => {
}; };
return ( return (
<>
{currentPageSize > 2 && (
<RowDropdownOptions isLast2Rows={isLast2Rows}>
<RowOptionsMenu <RowOptionsMenu
type='dropdown' popoverPosition={isLast2Rows ? 'top' : 'bottom'}
props={props} props={props}
deleteClickHandler={deleteClickHandler} deleteClickHandler={deleteClickHandler}
/> />
</RowDropdownOptions>
)}
{currentPageSize <= 2 && (
<RowCollapseOptions>
<RowOptionsMenu
type='collapse'
props={props}
deleteClickHandler={deleteClickHandler}
/>
</RowCollapseOptions>
)}
</>
); );
}, },
}, },
@@ -405,15 +401,14 @@ const PurchaseTable = () => {
return ( return (
<> <>
<div className='w-full p-0 sm:p-4'> <div className='w-full'>
<div className='flex flex-col gap-2 mb-4'> <div className='w-full p-3 flex flex-row justify-between gap-3 flex-wrap border-b border-base-content/10'>
<div className='w-full flex flex-col xl:flex-row justify-between items-end xl:items-center gap-2'> <div className='w-fit flex flex-row gap-3 flex-wrap'>
<div className='w-full flex flex-row gap-2'>
<RequirePermission permissions='lti.purchase.create'> <RequirePermission permissions='lti.purchase.create'>
<Button <Button
href='/purchase/add' href='/purchase/add'
color='primary' color='primary'
className='px-3 py-2.5 w-fit text-sm text-base-100 rounded-lg shadow-sm' className='px-3 py-2.5 w-fit text-sm text-base-100 rounded-xl shadow-button-soft'
> >
<Icon icon='heroicons:plus' width={20} height={20} /> <Icon icon='heroicons:plus' width={20} height={20} />
Add Purchase Add Purchase
@@ -421,6 +416,7 @@ const PurchaseTable = () => {
</RequirePermission> </RequirePermission>
</div> </div>
<div className='flex flex-1 flex-row justify-start sm:justify-end items-center gap-3 flex-wrap'>
<DebouncedTextInput <DebouncedTextInput
name='search' name='search'
placeholder='Search' placeholder='Search'
@@ -441,23 +437,10 @@ const PurchaseTable = () => {
}} }}
/> />
</div> </div>
<div className='flex flex-wrap justify-end gap-4'>
<SelectInput
label='Baris'
options={ROWS_OPTIONS}
value={{
label: String(tableFilterState.pageSize),
value: tableFilterState.pageSize,
}}
onChange={pageSizeChangeHandler}
className={{
wrapper: 'w-full sm:w-24',
}}
/>
</div>
</div> </div>
{/* Table Section */}
<div className='flex flex-col mb-4'>
<Table<Purchase> <Table<Purchase>
data={ data={
isResponseSuccess(purchaseRequests) ? purchaseRequests?.data : [] isResponseSuccess(purchaseRequests) ? purchaseRequests?.data : []
@@ -475,26 +458,21 @@ const PurchaseTable = () => {
: 0 : 0
} }
onPageChange={setPage} onPageChange={setPage}
onPageSizeChange={setPageSize}
isLoading={isLoading} isLoading={isLoading}
sorting={sorting} sorting={sorting}
setSorting={setSorting} setSorting={setSorting}
className={{ className={{
containerClassName: cn({ containerClassName: cn('p-3', {
'mb-20': 'w-full mb-20':
isResponseSuccess(purchaseRequests) && isResponseSuccess(purchaseRequests) &&
purchaseRequests?.data?.length === 0, purchaseRequests?.data?.length === 0,
}), }),
tableWrapperClassName: 'overflow-x-auto min-h-full!', headerColumnClassName: 'text-nowrap',
tableClassName: 'font-inter w-full table-auto min-h-full!',
headerRowClassName: 'border-b border-b-gray-200',
headerColumnClassName:
'px-6 py-3 text-xs font-semibold text-gray-500 last:flex last:flex-row last:justify-end',
bodyRowClassName: 'border-b border-b-gray-200',
bodyColumnClassName:
'px-6 py-3 last:flex last:flex-row last:justify-end',
}} }}
/> />
</div> </div>
</div>
{/* ===== MODAL COMPONENTS ===== */} {/* ===== MODAL COMPONENTS ===== */}
<ConfirmationModal <ConfirmationModal