diff --git a/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx b/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx
index 309c42b2..3298b0fc 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, useEffect, useState } from 'react';
+import { useEffect, useMemo, useState } from 'react';
import useSWR from 'swr';
import {
CellContext,
@@ -12,30 +12,28 @@ import toast from 'react-hot-toast';
import { Icon } from '@iconify/react';
import Table from '@/components/Table';
-import DebouncedTextInput from '@/components/input/DebouncedTextInput';
import Button from '@/components/Button';
import { useModal } from '@/components/Modal';
import ConfirmationModal from '@/components/modal/ConfirmationModal';
-import SelectInput, {
- OptionType,
- useSelect,
-} from '@/components/input/SelectInput';
import CheckboxInput from '@/components/input/CheckboxInput';
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 Badge from '@/components/Badge';
+import PopoverContent from '@/components/popover/PopoverContent';
+import Dropdown from '@/components/Dropdown';
+import StatusBadge from '@/components/helper/StatusBadge';
+import TransferToLayingFilterModal from '@/components/pages/production/transfer-to-laying/TransferToLayingFilterModal';
-import { TransferToLaying } from '@/types/api/production/transfer-to-laying';
+import {
+ TransferToLaying,
+ TransferToLayingFilter,
+} 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 { Flock } from '@/types/api/master-data/flock';
-import { ProjectFlockApi } from '@/services/api/production';
-import Badge from '@/components/Badge';
import { Color } from '@/types/theme';
-import PopoverContent from '@/components/popover/PopoverContent';
const RowOptionsMenu = ({
props,
@@ -56,8 +54,8 @@ const RowOptionsMenu = ({
const showDeleteButton = showEditButton;
- const showApproveButton = showEditButton;
- const showRejectButton = showEditButton;
+ // const showApproveButton = showEditButton;
+ // const showRejectButton = showEditButton;
const popoverId = `transferToLaying#${props.row.original.id}`;
const popoverAnchorName = `--anchor-transferToLaying#${props.row.original.id}`;
@@ -78,7 +76,7 @@ const RowOptionsMenu = ({
id={popoverId}
anchorName={popoverAnchorName}
position={popoverPosition === 'bottom' ? 'bottom-start' : 'left'}
- className='rounded-xl border border-base-content/5 shadow-sm'
+ className='w-full max-w-40 rounded-xl border border-base-content/5 shadow-sm'
>
@@ -107,7 +105,7 @@ const RowOptionsMenu = ({
)}
- {showApproveButton && (
+ {/* {showApproveButton && (
- )}
+ )} */}
{showDeleteButton && (
@@ -165,18 +163,22 @@ const TransferToLayingsTable = () => {
} = useTableFilter({
initial: {
search: '',
- transferDate: '',
+ startDate: '',
+ endDate: '',
flockSource: '',
flockDestination: '',
+ status: '',
filter_by: '',
sort_by: '',
},
paramMap: {
page: 'page',
pageSize: 'limit',
- transferDate: 'transfer_date',
+ startDate: 'start_date',
+ endDate: 'end_date',
flockSource: 'flock_source',
flockDestination: 'flock_destination',
+ status: 'status',
filter_by: 'filter_by',
sort_by: 'sort_by',
},
@@ -191,34 +193,36 @@ const TransferToLayingsTable = () => {
TransferToLayingApi.getAllFetcher
);
+ const filterCount = useMemo(() => {
+ let count = 0;
+
+ if (tableFilterState.startDate && tableFilterState.endDate) {
+ count += 1;
+ }
+
+ if (tableFilterState.flockSource.length > 0) {
+ count += 1;
+ }
+
+ if (tableFilterState.flockDestination.length > 0) {
+ count += 1;
+ }
+
+ if (tableFilterState.status.length > 0) {
+ count += 1;
+ }
+
+ return count;
+ }, [tableFilterState]);
+
+ const isFilterActive = filterCount > 0;
+
// Modal hooks
+ const filterModal = useModal();
const deleteModal = useModal();
const approveModal = useModal();
const rejectModal = useModal();
- // Flocks data
- const {
- setInputValue: setFlockSourceInputValue,
- options: flockSourceOptions,
- isLoadingOptions: isLoadingFlockSourceOptions,
- loadMore: loadMoreFlockSource,
- hasMore: hasMoreFlockSource,
- } = useSelect(ProjectFlockApi.basePath, 'id', 'flock_name');
-
- const {
- setInputValue: setFlockDestinationInputValue,
- options: flockDestinationOptions,
- isLoadingOptions: isLoadingFlockDestinationOptions,
- loadMore: loadMoreFlockDestination,
- hasMore: hasMoreFlockDestination,
- } = useSelect(ProjectFlockApi.basePath, 'id', 'flock_name');
-
- // Flocks value
- const [selectedFlockSource, setSelectedFlockSource] =
- useState(null);
- const [selectedFlockDestination, setSelectedFlockDestination] =
- useState(null);
-
const [selectedTransferToLaying, setSelectedTransferToLaying] = useState<
TransferToLaying | undefined
>(undefined);
@@ -315,18 +319,7 @@ const TransferToLayingsTable = () => {
latestApprovalStepName = 'Ditolak';
}
- return (
-
-
- {latestApprovalStepName}
-
- );
+ return ;
},
},
{
@@ -337,7 +330,7 @@ const TransferToLayingsTable = () => {
const currentRowRelativeIndex =
currentPageRows.findIndex((r) => r.id === props.row.id) + 1;
- const isLast2Rows = currentRowRelativeIndex > currentPageSize - 3;
+ const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2;
const approveClickHandler = () => {
setSelectedTransferToLaying(props.row.original);
@@ -472,38 +465,25 @@ const TransferToLayingsTable = () => {
setIsRejectLoading(false);
};
- const searchChangeHandler: ChangeEventHandler = (e) => {
- updateFilter('search', e.target.value);
+ const filterSubmitHandler = (values: TransferToLayingFilter) => {
+ updateFilter('startDate', values.startDate);
+ updateFilter('endDate', values.endDate);
+ updateFilter('flockSource', values.flockSource.join(','));
+ updateFilter('flockDestination', values.flockDestination.join(','));
+ updateFilter('status', values.status.join(','));
};
- const pageSizeChangeHandler = (val: OptionType | OptionType[] | null) => {
- const newVal = val as OptionType;
-
- setPageSize(newVal.value as number);
+ const filterResetHandler = () => {
+ updateFilter('startDate', '');
+ updateFilter('endDate', '');
+ updateFilter('flockSource', '');
+ updateFilter('flockDestination', '');
+ updateFilter('status', '');
};
- const transferDateChangeHandler: ChangeEventHandler = (
- e
- ) => {
- updateFilter('transferDate', e.target.value);
- };
-
- const flockSourceChangeHandler = (val: OptionType | OptionType[] | null) => {
- setSelectedFlockSource(val as OptionType);
- updateFilter(
- 'flockSource',
- val ? ((val as OptionType).value as string) : ''
- );
- };
-
- const flockDestinationChangeHandler = (
- val: OptionType | OptionType[] | null
- ) => {
- setSelectedFlockDestination(val as OptionType);
- updateFilter(
- 'flockDestination',
- val ? ((val as OptionType).value as string) : ''
- );
+ // TODO: add export to excel functionality
+ const exportToExcelHandler = () => {
+ toast.error('Not implemented yet');
};
useEffect(() => {
@@ -518,111 +498,132 @@ const TransferToLayingsTable = () => {
return (
<>
-
-
-
-
-
-
-
+
+
+
+
+
+
- {selectedRowIds.length > 0 && (
- <>
-
-
-
+ {selectedRowIds.length > 0 && (
+ <>
+
-
-
-
- >
- )}
-
+
+
+
-
+
+
+
+ >
+ )}
-
-
+
+
-
+ trigger={
+
+ }
+ >
+
+
@@ -652,7 +653,7 @@ const TransferToLayingsTable = () => {
enableRowSelection={tableEnableRowSelectionHandler}
withCheckbox
className={{
- containerClassName: cn({
+ containerClassName: cn('p-3', {
'w-full mb-20':
isResponseSuccess(transferToLayings) &&
transferToLayings?.data?.length === 0,
@@ -662,15 +663,23 @@ const TransferToLayingsTable = () => {
/>
+
+
{
{