From 26d89c35a5ded831d833c7c2fc6a2b1d700abaec Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Tue, 20 Jan 2026 17:07:24 +0700 Subject: [PATCH] chore: adjust TransferToLayingsTable styling --- .../TransferToLayingsTable.tsx | 309 ++++++++---------- 1 file changed, 145 insertions(+), 164 deletions(-) diff --git a/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx b/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx index 727d49cd..309c42b2 100644 --- a/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx +++ b/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx @@ -1,6 +1,6 @@ 'use client'; -import { ChangeEventHandler, useState } from 'react'; +import { ChangeEventHandler, useEffect, useState } from 'react'; import useSWR from 'swr'; import { CellContext, @@ -20,33 +20,32 @@ import SelectInput, { OptionType, useSelect, } from '@/components/input/SelectInput'; -import RowDropdownOptions from '@/components/table/RowDropdownOptions'; -import RowCollapseOptions from '@/components/table/RowCollapseOptions'; -import TextInput from '@/components/input/TextInput'; import CheckboxInput from '@/components/input/CheckboxInput'; -import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper'; import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes'; import RequirePermission from '@/components/helper/RequirePermission'; +import DateInput from '@/components/input/DateInput'; +import PopoverButton from '@/components/popover/PopoverButton'; import { TransferToLaying } from '@/types/api/production/transfer-to-laying'; import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying'; import { cn, formatDate } from '@/lib/helper'; import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; import { useTableFilter } from '@/services/hooks/useTableFilter'; -import { ROWS_OPTIONS } from '@/config/constant'; import { Flock } from '@/types/api/master-data/flock'; -import { FlockApi } from '@/services/api/master-data'; -import PillBadge from '@/components/PillBadge'; +import { ProjectFlockApi } from '@/services/api/production'; +import Badge from '@/components/Badge'; +import { Color } from '@/types/theme'; +import PopoverContent from '@/components/popover/PopoverContent'; const RowOptionsMenu = ({ - type = 'dropdown', props, + popoverPosition = 'bottom', approveClickHandler, rejectClickHandler, deleteClickHandler, }: { - type: 'dropdown' | 'collapse'; props: CellContext; + popoverPosition: 'bottom' | 'top'; approveClickHandler: () => void; rejectClickHandler: () => void; deleteClickHandler: () => void; @@ -60,80 +59,99 @@ const RowOptionsMenu = ({ const showApproveButton = showEditButton; const showRejectButton = showEditButton; + const popoverId = `transferToLaying#${props.row.original.id}`; + const popoverAnchorName = `--anchor-transferToLaying#${props.row.original.id}`; + return ( - - - - +
+ + + - {showEditButton && ( - - - - )} + +
+ + + - {/* TODO: apply RBAC */} - {showApproveButton && ( - - - - )} - {showRejectButton && ( - - - - )} - {showDeleteButton && ( - - - - )} - + {showEditButton && ( + + + + )} + + {showApproveButton && ( + + + + )} + + {showRejectButton && ( + + + + )} + + {showDeleteButton && ( + +
+ +
+ )} +
+
+
); }; @@ -150,6 +168,8 @@ const TransferToLayingsTable = () => { transferDate: '', flockSource: '', flockDestination: '', + filter_by: '', + sort_by: '', }, paramMap: { page: 'page', @@ -157,6 +177,8 @@ const TransferToLayingsTable = () => { transferDate: 'transfer_date', flockSource: 'flock_source', flockDestination: 'flock_destination', + filter_by: 'filter_by', + sort_by: 'sort_by', }, }); @@ -181,7 +203,7 @@ const TransferToLayingsTable = () => { isLoadingOptions: isLoadingFlockSourceOptions, loadMore: loadMoreFlockSource, hasMore: hasMoreFlockSource, - } = useSelect(FlockApi.basePath, 'id', 'name'); + } = useSelect(ProjectFlockApi.basePath, 'id', 'flock_name'); const { setInputValue: setFlockDestinationInputValue, @@ -189,7 +211,7 @@ const TransferToLayingsTable = () => { isLoadingOptions: isLoadingFlockDestinationOptions, loadMore: loadMoreFlockDestination, hasMore: hasMoreFlockDestination, - } = useSelect(FlockApi.basePath, 'id', 'name'); + } = useSelect(ProjectFlockApi.basePath, 'id', 'flock_name'); // Flocks value const [selectedFlockSource, setSelectedFlockSource] = @@ -244,13 +266,6 @@ const TransferToLayingsTable = () => { ); }, }, - { - header: '#', - cell: (props) => - tableFilterState.pageSize * (tableFilterState.page - 1) + - props.row.index + - 1, - }, { accessorKey: 'transfer_date', header: 'Tanggal Transfer', @@ -274,6 +289,7 @@ const TransferToLayingsTable = () => { { accessorKey: 'notes', header: 'Alasan Transfer', + enableSorting: false, }, { header: 'Status', @@ -282,34 +298,39 @@ const TransferToLayingsTable = () => { props.row.original.approval.action === 'REJECTED'; let latestApprovalStepName = props.row.original.approval.step_name; - let pillBadgeColor: 'yellow' | 'green' | 'gray' | 'red' = 'gray'; + let badgeColor: Color = 'neutral'; switch (latestApprovalStepName.toLowerCase()) { case 'pengajuan': - pillBadgeColor = 'yellow'; + badgeColor = 'neutral'; break; case 'disetujui': - pillBadgeColor = 'green'; + badgeColor = 'success'; break; } if (isLatestApprovalRejected) { - pillBadgeColor = 'red'; + badgeColor = 'error'; latestApprovalStepName = 'Ditolak'; } return ( - + + + {latestApprovalStepName} + ); }, }, { - header: 'Aksi', + id: 'actions', cell: (props) => { const currentPageSize = props.table.getPaginationRowModel().rows.length; const currentPageRows = props.table.getPaginationRowModel().flatRows; @@ -346,31 +367,13 @@ const TransferToLayingsTable = () => { }; return ( - <> - {currentPageSize > 3 && ( - - - - )} - - {currentPageSize <= 3 && ( - - - - )} - + ); }, }, @@ -503,20 +506,19 @@ const TransferToLayingsTable = () => { ); }; - // track sorting - // useEffect(() => { - // const isNameSorted = sorting.find((sortItem) => sortItem.id === 'name'); - - // if (!isNameSorted) { - // updateFilter('nameSort', ''); - // } else { - // updateFilter('nameSort', isNameSorted.desc ? 'desc' : 'asc'); - // } - // }, [sorting, updateFilter]); + useEffect(() => { + if (sorting.length === 1) { + updateFilter('filter_by', sorting[0].id); + updateFilter('sort_by', sorting[0].desc ? 'desc' : 'asc'); + } else { + updateFilter('filter_by', ''); + updateFilter('sort_by', ''); + } + }, [sorting]); return ( <> -
+
@@ -583,12 +585,10 @@ const TransferToLayingsTable = () => {
- { wrapper: 'col-span-12 sm:col-span-3', }} /> - -
@@ -657,26 +643,21 @@ const TransferToLayingsTable = () => { : 0 } onPageChange={setPage} + onPageSizeChange={setPageSize} isLoading={isLoading} sorting={sorting} setSorting={setSorting} rowSelection={rowSelection} setRowSelection={setRowSelection} enableRowSelection={tableEnableRowSelectionHandler} + withCheckbox className={{ containerClassName: cn({ - 'mb-20': + 'w-full mb-20': isResponseSuccess(transferToLayings) && transferToLayings?.data?.length === 0, }), - tableWrapperClassName: 'overflow-x-auto min-h-full!', - 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', + headerColumnClassName: 'text-nowrap', }} />