fix(FE-51-54): fixing bug and layout form adjustment

This commit is contained in:
randy-ar
2025-10-11 23:26:30 +07:00
parent 1fd4b2aba5
commit f662f2951e
10 changed files with 70 additions and 167 deletions
@@ -1,11 +1,8 @@
'use client';
import Button from '@/components/Button';
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
import SelectInput, { OptionType } from '@/components/input/SelectInput';
import Table from '@/components/Table';
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
import { ROWS_OPTIONS } from '@/config/constant';
import { isResponseSuccess } from '@/lib/api-helper';
import { cn } from '@/lib/helper';
@@ -14,45 +11,13 @@ import { useTableFilter } from '@/services/hooks/useTableFilter';
import { InventoryAdjustment } from '@/types/api/inventory/adjustment';
import { Icon } from '@iconify/react';
import {
CellContext,
ColumnDef,
ColumnSort,
SortingState,
} from '@tanstack/react-table';
import { ChangeEventHandler, useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import useSWR from 'swr';
const RowOptionsMenu = ({
type = 'dropdown',
props,
}: {
type: 'dropdown' | 'collapse';
props: CellContext<InventoryAdjustment, unknown>;
}) => {
return (
<div
tabIndex={type === 'dropdown' ? 0 : undefined}
className={cn(
{
'dropdown-content': type === 'dropdown',
'mt-2': type === 'collapse',
},
'p-2.5 mr-2 flex flex-col gap-1 bg-base-100 rounded-box z-10 border border-black/10 shadow'
)}
>
<Button
href={`/inventory/adjustment/detail?inventoryAdjustmentId=${props.row.original.id}`}
variant='ghost'
color='primary'
className='justify-start text-sm'
>
<Icon icon='mdi:eye-outline' width={16} height={16} />
Detail
</Button>
</div>
);
};
const InventoryAdjustmentTable = () => {
const {
state: tableFilterState,
@@ -82,15 +47,12 @@ const InventoryAdjustmentTable = () => {
const {
data: inventoryAdjustments,
isLoading,
mutate: refreshInventoryAdjustments,
} = useSWR(
`${inventoryAdjustmentApi.basePath}${getTableFilterQueryString()}`,
inventoryAdjustmentApi.getAllFetcher
);
// State
const [selectedInventoryAdjustment, setSelectedInventoryAdjustment] =
useState<InventoryAdjustment | undefined>(undefined);
const [sorting, setSorting] = useState<SortingState>([]);
// Columns
@@ -170,40 +132,9 @@ const InventoryAdjustmentTable = () => {
header: 'Oleh',
accessorFn: (row) => row.created_user?.name ?? '-',
},
// {
// id: 'actions',
// header: 'Aksi',
// cell: (props) => {
// const currentPageSize = props.table.getPaginationRowModel().rows.length;
// const currentPageRows = props.table.getPaginationRowModel().flatRows;
// const currentRowRelativeIndex =
// currentPageRows.findIndex((r) => r.id === props.row.id) + 1;
// const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2;
// return (
// <>
// {currentPageSize > 2 && (
// <RowDropdownOptions isLast2Rows={isLast2Rows}>
// <RowOptionsMenu type='dropdown' props={props} />
// </RowDropdownOptions>
// )}
// {currentPageSize <= 2 && (
// <RowCollapseOptions>
// <RowOptionsMenu type='dropdown' props={props} />
// </RowCollapseOptions>
// )}
// </>
// );
// },
// },
];
// Handler
const searchChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
updateFilter('search', e.target.value);
};
const pageSizeChangeHandler = (val: OptionType | OptionType[] | null) => {
const newVal = val as OptionType;
setPageSize(newVal.value as number);
@@ -240,7 +171,7 @@ const InventoryAdjustmentTable = () => {
updateSortingFilter('productSort', productSortFilter);
updateSortingFilter('warehouseSort', warehouseSortFilter);
updateSortingFilter('stockSort', stockSortFilter);
}, [sorting]);
}, [sorting, updateSortingFilter]);
// Utils Function
const formatNumber = (value: string) => {
@@ -259,7 +190,7 @@ const InventoryAdjustmentTable = () => {
<div className='flex flex-row'>
<Button href='/inventory/adjustment/add' color='primary'>
<Icon icon='ic:round-plus' width={24} height={24} />
Tambah Stock Adjustment
Tambah
</Button>
{/* <DebouncedTextInput