mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-208): remove unused supplier state and handlers in PurchaseTable
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { ChangeEventHandler, useCallback, useMemo, useState } from 'react';
|
import { ChangeEventHandler, useCallback, useState } from 'react';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
import { CellContext, ColumnDef, SortingState } from '@tanstack/react-table';
|
import { CellContext, ColumnDef, SortingState } from '@tanstack/react-table';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
@@ -11,13 +11,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 SelectInput, {
|
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||||
OptionType,
|
|
||||||
useSelect,
|
|
||||||
} from '@/components/input/SelectInput';
|
|
||||||
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
import TextInput from '@/components/input/TextInput';
|
|
||||||
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
|
||||||
|
|
||||||
import { cn, formatDate, formatCurrency } from '@/lib/helper';
|
import { cn, formatDate, formatCurrency } from '@/lib/helper';
|
||||||
@@ -27,7 +23,6 @@ import { useTableFilter } from '@/services/hooks/useTableFilter';
|
|||||||
import { ROWS_OPTIONS } from '@/config/constant';
|
import { ROWS_OPTIONS } from '@/config/constant';
|
||||||
import { Purchase } from '@/types/api/purchase/purchase';
|
import { Purchase } from '@/types/api/purchase/purchase';
|
||||||
import { PurchaseRequestApi } from '@/services/api/purchase';
|
import { PurchaseRequestApi } from '@/services/api/purchase';
|
||||||
import { SupplierApi } from '@/services/api/master-data';
|
|
||||||
|
|
||||||
// ===== INTERFACES =====
|
// ===== INTERFACES =====
|
||||||
interface RowOptionsMenuProps {
|
interface RowOptionsMenuProps {
|
||||||
@@ -83,9 +78,6 @@ const RowOptionsMenu = ({
|
|||||||
|
|
||||||
const PurchaseTable = () => {
|
const PurchaseTable = () => {
|
||||||
// ===== STATE MANAGEMENT =====
|
// ===== STATE MANAGEMENT =====
|
||||||
const [selectedSupplier, setSelectedSupplier] = useState<OptionType | null>(
|
|
||||||
null
|
|
||||||
);
|
|
||||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
const [selectedPurchase, setSelectedPurchase] = useState<Purchase | null>(
|
const [selectedPurchase, setSelectedPurchase] = useState<Purchase | null>(
|
||||||
null
|
null
|
||||||
@@ -116,13 +108,6 @@ const PurchaseTable = () => {
|
|||||||
// ===== MODAL HOOKS =====
|
// ===== MODAL HOOKS =====
|
||||||
const deleteModal = useModal();
|
const deleteModal = useModal();
|
||||||
|
|
||||||
// ===== USE SELECT HOOKS =====
|
|
||||||
const {
|
|
||||||
setInputValue: setSupplierInputValue,
|
|
||||||
options: supplierOptions,
|
|
||||||
isLoadingOptions: isLoadingSupplierOptions,
|
|
||||||
} = useSelect(SupplierApi.basePath, 'id', 'name');
|
|
||||||
|
|
||||||
// ===== API DATA FETCHING =====
|
// ===== API DATA FETCHING =====
|
||||||
const {
|
const {
|
||||||
data: purchaseRequests,
|
data: purchaseRequests,
|
||||||
@@ -253,24 +238,6 @@ const PurchaseTable = () => {
|
|||||||
[setPageSize]
|
[setPageSize]
|
||||||
);
|
);
|
||||||
|
|
||||||
const poDateChangeHandler: ChangeEventHandler<HTMLInputElement> = useCallback(
|
|
||||||
(e) => {
|
|
||||||
updateFilter('poDate', e.target.value);
|
|
||||||
},
|
|
||||||
[updateFilter]
|
|
||||||
);
|
|
||||||
|
|
||||||
const supplierChangeHandler = useCallback(
|
|
||||||
(val: OptionType | OptionType[] | null) => {
|
|
||||||
setSelectedSupplier(val as OptionType);
|
|
||||||
updateFilter(
|
|
||||||
'supplier',
|
|
||||||
val ? ((val as OptionType).value as string) : ''
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[updateFilter]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='w-full p-0 sm:p-4'>
|
<div className='w-full p-0 sm:p-4'>
|
||||||
@@ -299,35 +266,7 @@ const PurchaseTable = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex flex-wrap justify-between gap-4'>
|
<div className='flex flex-wrap justify-end gap-4'>
|
||||||
<div className='flex flex-wrap gap-4'>
|
|
||||||
<TextInput
|
|
||||||
required
|
|
||||||
type='date'
|
|
||||||
label='Tanggal PO'
|
|
||||||
name='po_date'
|
|
||||||
placeholder='Masukkan tanggal PO'
|
|
||||||
value={tableFilterState.poDate}
|
|
||||||
onChange={poDateChangeHandler}
|
|
||||||
className={{
|
|
||||||
wrapper: 'w-full sm:w-48',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SelectInput
|
|
||||||
label='Vendor'
|
|
||||||
options={supplierOptions}
|
|
||||||
isLoading={isLoadingSupplierOptions}
|
|
||||||
value={selectedSupplier}
|
|
||||||
onChange={supplierChangeHandler}
|
|
||||||
onInputChange={setSupplierInputValue}
|
|
||||||
isClearable
|
|
||||||
className={{
|
|
||||||
wrapper: 'w-full sm:w-56',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<SelectInput
|
<SelectInput
|
||||||
label='Baris'
|
label='Baris'
|
||||||
options={ROWS_OPTIONS}
|
options={ROWS_OPTIONS}
|
||||||
|
|||||||
Reference in New Issue
Block a user