refactor(FE): Remove unused imports and redundant code

This commit is contained in:
rstubryan
2026-02-20 14:17:26 +07:00
parent de0f9ae985
commit 1f2f3acebb
90 changed files with 222 additions and 474 deletions
-2
View File
@@ -1,6 +1,5 @@
'use client';
import { useCallback } from 'react';
import { usePathname } from 'next/navigation';
import Image from 'next/image';
@@ -13,7 +12,6 @@ import PermissionNotFound from '@/components/helper/PermissionNotFound';
import { useUiStore } from '@/stores/ui/ui.store';
import { MAIN_DRAWER_LINKS } from '@/config/constant';
import { isPathActive } from '@/lib/helper';
import { ROUTE_PERMISSIONS } from '@/config/route-permission';
import { useAuth } from '@/services/hooks/useAuth';
+1 -1
View File
@@ -1,4 +1,4 @@
import { HTMLAttributes, ReactNode, useEffect, useState } from 'react';
import { HTMLAttributes, ReactNode, useState } from 'react';
import { cn } from '@/lib/helper';
export interface TabItem {
@@ -1,5 +1,4 @@
import IconSkeleton from '@/components/helper/skeleton/IconSkeleton';
import { Icon } from '@iconify/react';
const DataStateSkeleton = ({
icon,
-1
View File
@@ -4,7 +4,6 @@ import { ChangeEvent } from 'react';
import {
PatternFormat,
NumberFormatBase,
NumberFormatBaseProps,
OnValueChange,
} from 'react-number-format';
import TextInput, { TextInputProps } from '@/components/input/TextInput';
@@ -56,7 +56,7 @@ const ConfirmationModalWithNotes: React.FC<ConfirmationModalWithNotesProps> = ({
closeOnBackdrop={closeOnBackdrop}
primaryButton={{
...primaryButton,
onClick: (e) => {
onClick: () => {
if (primaryButton && primaryButton?.onClick) {
primaryButton?.onClick?.(notes);
} else {
@@ -1,5 +1,5 @@
import Card from '@/components/Card';
import Table, { TABLE_DEFAULT_STYLING } from '@/components/Table';
import Table from '@/components/Table';
import { isResponseSuccess } from '@/lib/api-helper';
import { cn, formatCurrency, formatDate, formatNumber } from '@/lib/helper';
import { ClosingApi } from '@/services/api/closing';
@@ -38,7 +38,7 @@ const OverheadClosingTable = ({
}
);
const { data: overheadKandang, isLoading: isLoadingOverheadKandang } = useSWR(
const { data: overheadKandang } = useSWR(
kandangId
? `${ClosingApi.basePath}/${projectFlockId}/${kandangId}/overhead`
: undefined,
@@ -256,7 +256,7 @@ export const generateDashboardPDF = async ({
pdf.save(fileName);
toast.success('PDF exported successfully!', { id: 'export-pdf' });
} catch (error) {
} catch {
toast.error('Failed to export PDF. Please try again.', {
id: 'export-pdf',
});
@@ -1,6 +1,5 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { CellContext } from '@tanstack/react-table';
import { useSearchParams } from 'next/navigation';
import useSWR from 'swr';
import { useFormik } from 'formik';
@@ -48,9 +48,9 @@ const FormFinanceAddInitialBalance = ({
// ===== Formik =====
const formikInitialValues = useMemo((): InitialBalanceFormValues => {
// Type assertion to handle potential initial_balance_type field
const extendedInitialValues = initialValues as Finance & {
initial_balance_type?: string;
};
// const extendedInitialValues = initialValues as Finance & {
// initial_balance_type?: string;
// };
return {
party_type_option:
@@ -122,8 +122,6 @@ const FormFinanceAddInitialBalance = ({
options: bankOptions,
rawData: bankRawData,
isLoadingOptions: isLoadingBankOptions,
setInputValue: setBankInputValue,
loadMore: loadMoreBankOptions,
} = useSelect<Bank>(BankApi.basePath, 'id', 'name');
// ===== Helper Functions =====
@@ -28,10 +28,7 @@ import { useCallback, useMemo, useState } from 'react';
import toast from 'react-hot-toast';
import Alert from '@/components/Alert';
import { Icon } from '@iconify/react';
import {
FINANCE_INJECTION_STATUS,
FINANCE_INJECTION_TYPE_OPTIONS,
} from '@/config/constant';
import { FINANCE_INJECTION_TYPE_OPTIONS } from '@/config/constant';
interface FormFinanceInjectionProps {
type?: 'add' | 'edit';
@@ -15,7 +15,6 @@ import { Icon } from '@iconify/react';
import { ColumnDef, ColumnSort, SortingState } from '@tanstack/react-table';
import { useCallback, useEffect, useState } from 'react';
import useSWR from 'swr';
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
const InventoryAdjustmentTable = () => {
const {
@@ -14,7 +14,6 @@ import {
InventoryAdjustmentFormSchema,
InventoryAdjustmentFormValues,
} from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.schema';
import useSWR from 'swr';
import {
ProductApi,
ProductCategoryApi,
@@ -33,7 +33,6 @@ import { toast } from 'react-hot-toast';
import { MovementApi } from '@/services/api/inventory';
import FileInput from '@/components/input/FileInput';
import CheckboxInput from '@/components/input/CheckboxInput';
import Badge from '@/components/Badge';
import Card from '@/components/Card';
import { S3_PUBLIC_BASE_URL } from '@/config/constant';
import { getUniqueFormikErrors } from '@/lib/formik-helper';
@@ -15,12 +15,7 @@ import { InventoryProductApi } from '@/services/api/inventory';
import { useTableFilter } from '@/services/hooks/useTableFilter';
import { InventoryProduct } from '@/types/api/inventory/product';
import { Icon } from '@iconify/react';
import {
CellContext,
ColumnDef,
Row,
SortingState,
} from '@tanstack/react-table';
import { CellContext, ColumnDef, SortingState } from '@tanstack/react-table';
import { ChangeEventHandler, useMemo, useState } from 'react';
import useSWR from 'swr';
@@ -1,10 +1,7 @@
import Card from '@/components/Card';
import Table from '@/components/Table';
import { formatNumber } from '@/lib/helper';
import {
InventoryProduct,
ProductWarehouseStock,
} from '@/types/api/inventory/product';
import { ProductWarehouseStock } from '@/types/api/inventory/product';
const StockProductWarehouseTable = ({
productWarehouseStock,
@@ -48,11 +48,7 @@ import RequirePermission from '@/components/helper/RequirePermission';
const MemoizedDeliveryOrderProductTable = memo(DeliveryOrderProductTable);
const MemoizedDeliveryOrderProductForm = memo(DeliveryOrderProductForm);
const DeliveryOrderFormModal = ({
initialValues,
}: {
initialValues?: Marketing;
}) => {
const DeliveryOrderFormModal = ({}: { initialValues?: Marketing }) => {
const router = useRouter();
const searchParams = useSearchParams();
@@ -76,19 +72,14 @@ const DeliveryOrderFormModal = ({
);
};
const { data: marketing, isLoading: isLoadingMarketing } = useSWR(
const { data: marketing } = useSWR(
isModalActionForForm && marketingId
? `detail-marketing-${marketingId}`
: undefined,
() => MarketingApi.getSingle(Number(marketingId))
);
const {
approvals,
rawDataApprovals,
isLoading: isLoadingApproval,
refresh: refreshApproval,
} = useApprovalSteps({
const { rawDataApprovals, refresh: refreshApproval } = useApprovalSteps({
latestApproval: isResponseSuccess(marketing)
? marketing?.data.latest_approval
: undefined,
@@ -284,29 +275,10 @@ const DeliveryOrderFormModal = ({
setIsLoading(false);
};
const memoSalesOrder = formik.values.sales_order;
// ================== HANDLER ==================
const nextButtonHandler = () => {
setStep(step + 1);
};
const prevButtonHandler = () => {
setStep(step - 1);
};
const handleChangeCustomer = useCallback(
(val: OptionType | OptionType[] | null) => {
formik.setFieldValue('customer_id', (val as OptionType)?.value);
formik.setFieldValue('customer', val as OptionType);
},
[]
);
const handleChangeSalesPerson = useCallback(
(val: OptionType | OptionType[] | null) => {
formik.setFieldValue('sales_person_id', (val as OptionType)?.value);
formik.setFieldValue('sales_person', val as OptionType);
},
[]
);
const rejectMarketingHandler = async (notes: string) => {
if (!marketingId) {
toast.error(`Tidak ada data yang valid untuk di reject.`);
@@ -507,18 +479,18 @@ const DeliveryOrderFormModal = ({
}, []);
// ================== MEMOIZED ==================
const isNextButtonDisabled = useMemo(() => {
if (step === 1) {
return Boolean(
!formik.values.customer_id ||
!formik.values.sales_person_id ||
!formik.values.so_date ||
!formik.values.notes
);
}
// const isNextButtonDisabled = useMemo(() => {
// if (step === 1) {
// return Boolean(
// !formik.values.customer_id ||
// !formik.values.sales_person_id ||
// !formik.values.so_date ||
// !formik.values.notes
// );
// }
return true;
}, [step, formik.values]);
// return true;
// }, [step, formik.values]);
const deliveryRejected = useMemo(() => {
return (
isResponseSuccess(marketing) &&
@@ -877,7 +849,7 @@ const DeliveryOrderFormModal = ({
text: 'Oke',
color: 'primary',
className: 'rounded-lg',
onClick: (e) => {
onClick: () => {
closeModalHandler();
},
}}
@@ -25,7 +25,6 @@ import { useMemo, useState } from 'react';
import toast from 'react-hot-toast';
import useSWR from 'swr';
import RequirePermission from '@/components/helper/RequirePermission';
import { useAuth } from '@/services/hooks/useAuth';
import ButtonFilter from '@/components/helper/ButtonFilter';
import Dropdown from '@/components/Dropdown';
import PopoverButton from '@/components/popover/PopoverButton';
@@ -136,7 +135,7 @@ const RowsOptionsMenu = ({
onClick={deleteClickHandler}
variant='ghost'
color='none'
className='relative p-3 overflow-hidden justify-start text-sm font-semibold w-full text-error before:content-[""] before:absolute before:h-0.25 before:p-3 before:top-0 before:left-0 before:right-0 before:border-t before:border-base-content/5'
className='relative p-3 overflow-hidden justify-start text-sm font-semibold w-full text-error before:content-[""] before:absolute before:h-px before:p-3 before:top-0 before:left-0 before:right-0 before:border-t before:border-base-content/5'
>
<Icon icon='heroicons:trash' width={20} height={20} />
Delete Item
@@ -149,14 +148,11 @@ const RowsOptionsMenu = ({
};
const MarketingTable = () => {
const [search, setSearch] = useState('');
const [approveAction, setApproveAction] = useState<'APPROVED' | 'REJECTED'>(
'APPROVED'
);
const [selectedItem, setSelectedItem] = useState<Marketing | null>(null);
const [rowSelection, setRowSelection] = useState<Record<string, boolean>>({});
const { permissionCheck } = useAuth();
const router = useRouter();
const deleteModal = useModal();
@@ -530,7 +526,7 @@ const MarketingTable = () => {
</RequirePermission>
{idsToProcess.length > 0 && (
<>
<div className='divider divider-horizontal w-0.25 p-0 m-0 bg-base-content/10 text-base-content/10 before:bg-base-content/10 before:w-0.25 after:bg-base-content/10 after:w-0.25'></div>
<div className='divider divider-horizontal w-px p-0 m-0 bg-base-content/10 text-base-content/10 before:bg-base-content/10 before:w-px after:bg-base-content/10 after:w-px'></div>
<RequirePermission permissions='lti.marketing.sales_order.approve'>
<Button
color='error'
@@ -569,7 +565,7 @@ const MarketingTable = () => {
<div className='flex flex-row gap-3'>
<ButtonFilter
values={(() => {
const { page, pageSize, ...rest } = tableFilterState;
const { ...rest } = tableFilterState;
return rest;
})()}
onClick={() => {
@@ -81,7 +81,7 @@ const SalesOrderFormModal = ({
);
};
const { data: marketing, isLoading: isLoadingMarketing } = useSWR(
const { data: marketing } = useSWR(
isModalActionForForm && marketingId
? `detail-marketing-${marketingId}`
: undefined,
@@ -750,7 +750,7 @@ const SalesOrderFormModal = ({
text: 'Oke',
color: 'primary',
className: 'rounded-lg',
onClick: (e) => {
onClick: () => {
closeModalHandler();
},
}}
@@ -34,7 +34,6 @@ const DeliveryOrderProductForm = ({
salesOrders,
initialValues,
exisitingValues,
onSubmitForm,
onUpdateForm,
isLoading,
}: {
@@ -96,12 +95,12 @@ const DeliveryOrderProductForm = ({
);
// Options Week dari minggu 1 - 22
const optionsWeek = useMemo(() => {
return Array.from({ length: 22 }, (_, i) => ({
value: i + 1,
label: `Week ${i + 1}`,
}));
}, []);
// const optionsWeek = useMemo(() => {
// return Array.from({ length: 22 }, (_, i) => ({
// value: i + 1,
// label: `Week ${i + 1}`,
// }));
// }, []);
const options = exisitingValues
?.map((item) => {
@@ -139,12 +139,12 @@ const SalesOrderProductForm = ({
} = useSelect<Kandang>(WarehouseApi.basePath, 'id', 'name');
// Options Week dari minggu 1 - 22
const optionsWeek = useMemo(() => {
return Array.from({ length: 22 }, (_, i) => ({
value: i + 1,
label: `Week ${i + 1}`,
}));
}, []);
// const optionsWeek = useMemo(() => {
// return Array.from({ length: 22 }, (_, i) => ({
// value: i + 1,
// label: `Week ${i + 1}`,
// }));
// }, []);
const {
options: warehouseSourceOptions,
@@ -49,7 +49,7 @@ const DeliveryOrderExport = ({
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}, 150);
} catch (error) {
} catch {
toast.error('Failed to generate PDF. Please try again.');
} finally {
setIsGeneratingPDF(false);
@@ -1,7 +1,7 @@
import Button from '@/components/Button';
import { Marketing } from '@/types/api/marketing/marketing';
import { Icon } from '@iconify/react';
import { Document, Image, Page, pdf, Text, View } from '@react-pdf/renderer';
import { Document, Page, pdf, Text, View } from '@react-pdf/renderer';
import { useMemo, useState } from 'react';
import { formatDate, formatNumber } from '@/lib/helper';
import pdfStyles from '@/components/pages/marketing/pdf/styles/MarketingPDFStyles';
@@ -43,7 +43,7 @@ const SalesOrderExport = ({ data }: SalesOrderExportProps) => {
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}, 150);
} catch (error) {
} catch {
toast.error('Failed to generate PDF. Please try again.');
} finally {
setIsGeneratingPDF(false);
@@ -162,7 +162,7 @@ const PDFDocument = ({ data }: { data: Marketing }) => {
</View>
</View>
{data?.sales_order?.map((item, index) => {
const isLastItem = index === (data?.sales_order?.length || 0) - 1;
// const isLastItem = index === (data?.sales_order?.length || 0) - 1;
return (
<View
key={index}
@@ -1,7 +1,7 @@
'use client';
import { useModal } from '@/components/Modal';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { isResponseError } from '@/lib/api-helper';
import { CustomerApi } from '@/services/api/master-data';
import {
CreateCustomerPayload,
@@ -27,7 +27,6 @@ import SelectInput, {
OptionType,
useSelect,
} from '@/components/input/SelectInput';
import useSWR from 'swr';
import { UserApi } from '@/services/api/user';
import { TYPE_OPTIONS } from '@/config/constant';
import RequirePermission from '@/components/helper/RequirePermission';
@@ -4,7 +4,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useFormik } from 'formik';
import { toast } from 'react-hot-toast';
import useSWR from 'swr';
import { Icon } from '@iconify/react';
import Button from '@/components/Button';
@@ -22,7 +21,7 @@ import {
KandangFormValues,
UpdateKandangFormSchema,
} from '@/components/pages/master-data/kandang/form/KandangForm.schema';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { isResponseError } from '@/lib/api-helper';
import {
Kandang,
CreateKandangPayload,
@@ -4,7 +4,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useFormik } from 'formik';
import { toast } from 'react-hot-toast';
import useSWR from 'swr';
import { Icon } from '@iconify/react';
import Button from '@/components/Button';
@@ -22,7 +21,7 @@ import {
LocationFormValues,
UpdateLocationFormSchema,
} from '@/components/pages/master-data/location/form/LocationForm.schema';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { isResponseError } from '@/lib/api-helper';
import {
Location,
CreateLocationPayload,
@@ -4,7 +4,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useFormik } from 'formik';
import { toast } from 'react-hot-toast';
import useSWR from 'swr';
import { Icon } from '@iconify/react';
import Button from '@/components/Button';
@@ -22,7 +21,7 @@ import {
NonstockFormValues,
UpdateNonstockFormSchema,
} from '@/components/pages/master-data/nonstock/form/NonstockForm.schema';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { isResponseError } from '@/lib/api-helper';
import {
Nonstock,
CreateNonstockPayload,
@@ -1,7 +1,6 @@
'use client';
import Button from '@/components/Button';
import { FormHeader } from '@/components/helper/form/FormHeader';
import Table, { TABLE_DEFAULT_STYLING } from '@/components/Table';
import { ProductionStandard } from '@/types/api/master-data/production-standard';
import { Icon } from '@iconify/react';
@@ -82,14 +81,11 @@ const ProductionStandardTable = () => {
>(undefined);
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
const {
data: productionStandards,
isLoading: productionStandardsLoading,
mutate: refreshProductionStandards,
} = useSWR(
`${ProductionStandardApi.basePath}`,
ProductionStandardApi.getAllFetcher
);
const { data: productionStandards, mutate: refreshProductionStandards } =
useSWR(
`${ProductionStandardApi.basePath}`,
ProductionStandardApi.getAllFetcher
);
const confirmationModalDeleteClickHandler = async () => {
setIsDeleteLoading(true);
@@ -4,7 +4,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { useRouter } from 'next/navigation';
import { useFormik } from 'formik';
import { toast } from 'react-hot-toast';
import useSWR from 'swr';
import { Icon } from '@iconify/react';
import Button from '@/components/Button';
@@ -22,7 +21,7 @@ import {
WarehouseFormValues,
UpdateWarehouseFormSchema,
} from '@/components/pages/master-data/warehouse/form/WarehouseForm.schema';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { isResponseError } from '@/lib/api-helper';
import {
Warehouse,
CreateWarehousePayload,
@@ -1,12 +1,8 @@
'use client';
import Card from '@/components/Card';
import { FormHeader } from '@/components/helper/form/FormHeader';
import Table from '@/components/Table';
import { formatNumber } from '@/lib/helper';
import { Kandang } from '@/types/api/master-data/kandang';
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
import Tabs from '@/components/Tabs';
import { useState } from 'react';
import ApprovalSteps, {
useApprovalSteps,
@@ -15,7 +11,6 @@ import ChickinFormView from '@/components/pages/production/chickin/form/tabs/Chi
import ChickinLogsView from '@/components/pages/production/chickin/form/tabs/ChickLogsView';
import DrawerHeader from '@/components/helper/drawer/DrawerHeader';
import { Icon } from '@iconify/react';
import Badge from '@/components/Badge';
import StatusBadge from '@/components/helper/StatusBadge';
import { CHICKINS_APPROVAL_LINE } from '@/config/approval-line';
import RequirePermission from '@/components/helper/RequirePermission';
@@ -1,10 +1,8 @@
'use client';
import Card from '@/components/Card';
import Table from '@/components/Table';
import {
ChickinFormValues,
ChickinRequestFormValues,
ChickinSchema,
} from '@/components/pages/production/chickin/form/ChickinForm.schema';
import DateInput from '@/components/input/DateInput';
@@ -60,11 +60,7 @@ const ProjectFlockConfirmationModal = ({
: '',
limit: '500',
}).toString()}`;
const {
data: kandang,
isLoading: isLoadingKandang,
mutate: refreshKandang,
} = useSWR(kandangUrl, KandangApi.getAllFetcher);
const { data: kandang } = useSWR(kandangUrl, KandangApi.getAllFetcher);
const notesChangeHandler: ChangeEventHandler<HTMLTextAreaElement> = (e) => {
setNotes(e.target.value);
@@ -85,7 +81,7 @@ const ProjectFlockConfirmationModal = ({
text: primaryButton?.text ?? 'Oke',
color: primaryButton?.color ?? 'primary',
className: 'rounded-lg',
onClick: (e) => {
onClick: () => {
if (withNote) {
primaryButton?.onClick?.(notes);
} else if (primaryButton && primaryButton?.onClick) {
@@ -1,22 +1,16 @@
'use client';
import Badge from '@/components/Badge';
import Button from '@/components/Button';
import FloatingActionsButton from '@/components/FloatingActionsButton';
import CheckboxInput from '@/components/input/CheckboxInput';
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
import SelectInput, {
OptionType,
useSelect,
} from '@/components/input/SelectInput';
import { OptionType, useSelect } from '@/components/input/SelectInput';
import { useModal } from '@/components/Modal';
import ConfirmationModal from '@/components/modal/ConfirmationModal';
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
import Table from '@/components/Table';
import Dropdown from '@/components/Dropdown';
import { ROWS_OPTIONS } from '@/config/constant';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { cn, formatDate, formatTitleCase } from '@/lib/helper';
import { cn, formatDate } from '@/lib/helper';
import { AreaApi, KandangApi, LocationApi } from '@/services/api/master-data';
import { ProjectFlockApi } from '@/services/api/production/project-flock';
import { useTableFilter } from '@/services/hooks/useTableFilter';
@@ -183,14 +177,6 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
.filter((id) => rowSelection[id])
.map((id) => parseInt(id));
const [selectedArea, setSelectedArea] = useState<OptionType | null>(null);
const [selectedLocation, setSelectedLocation] = useState<OptionType | null>(
null
);
const [selectedKandang, setSelectedKandang] = useState<OptionType | null>(
null
);
const [periodInputValue, setPeriodInputValue] = useState<number | null>(null);
const [sorting, setSorting] = useState<SortingState>([]);
const deleteModal = useModal();
const confirmModal = useModal();
@@ -232,26 +218,6 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
{ revalidateOnMount: true }
);
// ===== Fetch Data Select =====
const {
options: optionsArea,
isLoadingOptions: isLoadingArea,
setInputValue: setAreaSelectInputValue,
loadMore: loadMoreArea,
} = useSelect(AreaApi.basePath, 'id', 'name');
const {
options: optionsLocation,
isLoadingOptions: isLoadingLocation,
setInputValue: setLocationSelectInputValue,
loadMore: loadMoreLocation,
} = useSelect(LocationApi.basePath, 'id', 'name');
const {
options: optionsKandang,
isLoadingOptions: isLoadingKandang,
setInputValue: setKandangSelectInputValue,
loadMore: loadMoreKandang,
} = useSelect(KandangApi.basePath, 'id', 'name');
// ====== HANDLER ======
const confirmationModalDeleteClickHandler = async () => {
setIsDeleteLoading(true);
@@ -4,7 +4,6 @@ import Button from '@/components/Button';
import Card from '@/components/Card';
import DrawerHeader from '@/components/helper/drawer/DrawerHeader';
import Table from '@/components/Table';
import Badge from '@/components/Badge';
import StatusBadge from '@/components/helper/StatusBadge';
import { formatDate, formatNumber, formatTitleCase } from '@/lib/helper';
import { ProjectFlock } from '@/types/api/production/project-flock';
@@ -21,7 +20,6 @@ import { useProjectFlockClosingStore } from '@/stores/production/project-flock-c
import { useMemo } from 'react';
import toast from 'react-hot-toast';
import { useRouter } from 'next/navigation';
import { ApprovalApi } from '@/services/api/approval';
import RequirePermission from '@/components/helper/RequirePermission';
import { Color } from '@/types/theme';
@@ -60,24 +58,10 @@ const ProjectFlockClosingForm = ({
() => ProjectFlockKandangApi.checkClosing(projectFlockKandang.id)
);
const { data: projectFlockKandangApprovals } = useSWR(
`${ApprovalApi.basePath}?module_name=PROJECT_FLOCK_KANDANGS&module_id=${projectFlockKandang.id}`,
() =>
ApprovalApi.getAllFetcher(
`${ApprovalApi.basePath}?module_name=PROJECT_FLOCK_KANDANGS&module_id=${projectFlockKandang.id}`
)
);
const isKandangClosed = useMemo(() => {
return projectFlockKandang.kandang?.status === 'NON_ACTIVE';
}, [projectFlockKandang]);
const isCanClose = useMemo(() => {
return isResponseSuccess(projectFlockKandangApprovals)
? projectFlockKandangApprovals?.data?.[0]?.step_number <= 2
: true;
}, [projectFlockKandangApprovals]);
const handleCloseClick = () => {
const closingCallback = async (action: 'close' | 'unclose') => {
const deleteProjectFlockRes = await ProjectFlockKandangApi.closing(
@@ -1,4 +1,3 @@
import Badge from '@/components/Badge';
import Button from '@/components/Button';
import Card from '@/components/Card';
import { RadioGroup, RadioGroupItem } from '@/components/input/RadioInput';
@@ -42,19 +41,6 @@ const ProjectFlockDetail = ({
(kandang) => kandang.id === Number(selectedKandangId)
);
const { data: projectFlockKandang, isLoading: projectFlockKandangLoading } =
useSWR(
selectedKandangId
? `${ProjectFlockKandangApi.basePath}/get-detail/${selectedKandangId}`
: null,
selectedKandangId
? () =>
ProjectFlockKandangApi.getSingle(
Number(selectedKandang?.project_flock_kandang_id)
)
: null
);
const { data: projectFlockApprovalResponse } = useSWR(
projectFlock.id ? ['approval-project-flock', projectFlock.id] : undefined,
([, id]) => ProjectFlockApi.getApprovalLineHistory(Number(id))
@@ -39,7 +39,6 @@ import { FLOCK_CATEGORY_OPTIONS } from '@/config/constant';
import { useModal } from '@/components/Modal';
import ConfirmationModal from '@/components/modal/ConfirmationModal';
import NumberInput from '@/components/input/NumberInput';
import Card from '@/components/Card';
import ProjectFlockKandangTable from '@/components/pages/production/project-flock/form/ProjectFlockKandangTable';
import { Nonstock } from '@/types/api/master-data/nonstock';
import { useUiStore } from '@/stores/ui/ui.store';
@@ -209,7 +208,6 @@ export const ProjectFlockFormConfirmationTable = ({
const ProjectFlockForm = ({
formType = 'add',
initialValues,
refreshProjectFlocks,
}: ProjectFlockFormProps) => {
// State
const router = useRouter();
@@ -228,7 +226,7 @@ const ProjectFlockForm = ({
const [disabledLocation, setDisabledLocation] = useState(
initialValues?.location?.id ? false : true
);
const [openSelectKandangs, setOpenSelectKandangs] = useState(
const [, setOpenSelectKandangs] = useState(
initialValues?.kandangs && initialValues?.kandangs?.length > 0
);
const [optionsKandang, setOptionsKandang] = useState<Kandang[]>(
@@ -475,9 +473,9 @@ const ProjectFlockForm = ({
formikSetValues(formikInitialValues);
};
const [formikLastValues, setFormikLastValues] = useState<
ProjectFlockFormValues | undefined
>(undefined);
const [, setFormikLastValues] = useState<ProjectFlockFormValues | undefined>(
undefined
);
// Formik InitialValue
const formikInitialValues = useMemo<ProjectFlockFormValues>(() => {
@@ -486,9 +484,9 @@ const ProjectFlockForm = ({
0,
initialValues?.flock_name?.lastIndexOf(' ')
) ?? '';
const optionFind = optionsFlock.find((flock) => {
return flock.label == trimFlock;
}) as OptionType;
// const optionFind = optionsFlock.find((flock) => {
// return flock.label == trimFlock;
// }) as OptionType;
return {
flock:
optionsFlock.find((flock) => {
@@ -1,28 +1,21 @@
'use client';
import Badge from '@/components/Badge';
import Card from '@/components/Card';
import StatusBadge from '@/components/helper/StatusBadge';
import CheckboxInput from '@/components/input/CheckboxInput';
import PillBadge from '@/components/PillBadge';
import Table from '@/components/Table';
import { cn } from '@/lib/helper';
import { Kandang } from '@/types/api/master-data/kandang';
import {
ProjectFlock,
ProjectFlockPeriods,
} from '@/types/api/production/project-flock';
import { Icon } from '@iconify/react';
import { OnChangeFn, Row } from '@tanstack/react-table';
import { useMemo } from 'react';
import { OnChangeFn } from '@tanstack/react-table';
const ProjectFlockKandangTable = ({
listPeriods,
listKandang,
rowSelection,
setRowSelection,
selectedIds,
initialValues,
formType = 'add',
}: {
listPeriods: ProjectFlockPeriods;
@@ -55,7 +55,7 @@ const TransferToLayingConfirmationModalTable = ({
transferToLayingId
? ['detail-transfer-to-laying', String(transferToLayingId)]
: undefined,
([_, id]) => TransferToLayingApi.getSingle(Number(id))
([id]) => TransferToLayingApi.getSingle(Number(id))
);
const confirmationTableColumns: ColumnDef<TransferToLayingConfirmationTableDataType>[] =
@@ -230,7 +230,7 @@ const TransferToLayingConfirmationModal = ({
text: primaryButton?.text ?? 'Oke',
color: primaryButton?.color ?? 'primary',
className: 'rounded-lg',
onClick: (e) => {
onClick: () => {
if (withNote) {
primaryButton?.onClick?.(notes);
} else if (primaryButton && primaryButton?.onClick) {
@@ -40,10 +40,7 @@ const TransferToLayingDetailModal = () => {
? transferToLayingResponse.data
: undefined;
const {
data: transferToLayingApprovalResponse,
isLoading: isLoadingTransferToLayingApproval,
} = useSWR(
const { data: transferToLayingApprovalResponse } = useSWR(
transferToLayingId
? ['approval-transfer-to-laying', transferToLayingId]
: undefined,
@@ -60,13 +60,12 @@ const TransferToLayingFormModal = () => {
);
};
const { data: transferToLaying, isLoading: isLoadingTransferToLaying } =
useSWR(
isModalActionForForm && transferToLayingId
? ['detail-transfer-to-laying', transferToLayingId]
: undefined,
([, id]) => TransferToLayingApi.getSingle(Number(id))
);
const { data: transferToLaying } = useSWR(
isModalActionForForm && transferToLayingId
? ['detail-transfer-to-laying', transferToLayingId]
: undefined,
([, id]) => TransferToLayingApi.getSingle(Number(id))
);
/**
* Step 1: General Information
@@ -178,7 +177,7 @@ const TransferToLayingFormModal = () => {
[router]
);
const [formikInitialValues, setFormikInitialValues] = useState(
const [formikInitialValues] = useState(
getTransferToLayingFormInitialValues()
);
@@ -238,10 +237,7 @@ const TransferToLayingFormModal = () => {
)
: undefined;
const {
data: flockSourceKandangsAvailability,
isLoading: isLoadingFlockSourceKandangsAvailability,
} = useSWR(
const { data: flockSourceKandangsAvailability } = useSWR(
formik.values.flockSource
? [
'transfer-to-laying',
@@ -297,10 +293,7 @@ const TransferToLayingFormModal = () => {
return { available: countAvailable, unavailable: countUnavailable };
}, [mappedFlockSourceKandangsAvailability]);
const {
data: flockDestinationKandangsMaxTargetQty,
isLoading: isLoadingFlockDestinationKandangsMaxTargetQty,
} = useSWR(
const { data: flockDestinationKandangsMaxTargetQty } = useSWR(
formik.values.flockDestination
? [
'transfer-to-laying',
@@ -2,9 +2,6 @@ import * as Yup from 'yup';
import { TransferToLaying } from '@/types/api/production/transfer-to-laying';
import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying';
import { formatDate, formatNumber } from '@/lib/helper';
import { ProjectFlock } from '@/types/api/production/project-flock';
import { ProjectFlockApi } from '@/services/api/production/project-flock';
import { isResponseSuccess } from '@/lib/api-helper';
type TransferToLayingFormSchemaType = {
transfer_date?: string;
@@ -153,11 +153,9 @@ const PurchaseOrderAcceptApprovalForm = ({
// ===== SELECT INPUT DATA =====
const {
setInputValue: setExpeditionsSelectInputValue,
options: expeditionVendors,
isLoadingOptions: isLoadingExpeditions,
loadMore: loadMoreExpeditions,
hasMore: hasMoreExpeditions,
} = useSelect<Supplier>(SupplierApi.basePath, 'id', 'name', 'search', {
category: 'BOP',
flag: 'EKSPEDISI',
@@ -343,19 +341,6 @@ const PurchaseOrderAcceptApprovalForm = ({
) => {
const numValue = typeof value === 'string' ? parseFloat(value) || 0 : value;
formik.setFieldValue(`items.${idx}.${field}`, numValue);
if (field === 'received_qty' || field === 'transport_per_item') {
const receivedQty =
field === 'received_qty'
? numValue
: parseFloat(formik.values.items?.[idx]?.received_qty as string) || 0;
const transportPerItem =
field === 'transport_per_item'
? numValue
: parseFloat(
formik.values.items?.[idx]?.transport_per_item as string
) || 0;
}
};
return (
@@ -55,7 +55,7 @@ const PurchaseRequestForm = ({
const deleteModal = useModal();
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
const [locationSelectInputValue, setLocationSelectInputValue] = useState('');
const [, setLocationSelectInputValue] = useState('');
const [selectedPurchaseItems, setSelectedPurchaseItems] = useState<number[]>(
[]
);
@@ -149,7 +149,6 @@ const PurchaseRequestForm = ({
isLoadingOptions: isLoadingSuppliers,
rawData: supplierRawData,
loadMore: loadMoreSuppliers,
hasMore: hasMoreSuppliers,
} = useSelect<Supplier>(SupplierApi.basePath, 'id', 'name', 'search', {
category: 'SAPRONAK',
});
@@ -164,7 +163,6 @@ const PurchaseRequestForm = ({
options: locationOptions,
isLoadingOptions: isLoadingLocations,
loadMore: loadMoreLocations,
hasMore: hasMoreLocations,
} = useSelect(LocationApi.basePath, 'id', 'name', '', {
area_id:
selectedArea != ''
@@ -173,12 +171,10 @@ const PurchaseRequestForm = ({
});
const {
inputValue: warehouseSelectInputValue,
setInputValue: setWarehouseSelectInputValue,
options: warehouseOptions,
isLoadingOptions: isLoadingWarehouses,
loadMore: loadMoreWarehouses,
hasMore: hasMoreWarehouses,
} = useSelect(WarehouseApi.basePath, 'id', 'name', 'search', {
area_id:
selectedArea != ''
@@ -651,7 +647,7 @@ const PurchaseRequestForm = ({
{formik.values.items?.map((item, idx) => (
<tr key={`purchase-item-${idx}`}>
{type !== 'detail' && (
<td className='!align-middle'>
<td className='align-middle!'>
<CheckboxInput
name={`purchase-item-${idx}`}
checked={selectedPurchaseItems.includes(idx)}
@@ -84,7 +84,6 @@ interface PurchaseOrderDetailProps {
}
const PurchaseOrderDetail = ({
type = 'detail',
initialValues,
refetchData,
}: PurchaseOrderDetailProps) => {
@@ -1042,7 +1041,7 @@ const PurchaseOrderDetail = ({
ref={staffApprovalModal.ref}
closeOnBackdrop
className={{
modalBox: 'w-full max-w-screen-2xl max-h-[90vh] overflow-y-auto',
modalBox: 'w-full max-w-2xl max-h-[90vh] overflow-y-auto',
}}
>
<PurchaseOrderStaffApprovalForm
@@ -1061,7 +1060,7 @@ const PurchaseOrderDetail = ({
ref={acceptApprovalModal.ref}
closeOnBackdrop
className={{
modalBox: 'w-full max-w-screen-2xl max-h-[90vh] overflow-y-auto',
modalBox: 'w-full max-w-2xl max-h-[90vh] overflow-y-auto',
}}
>
<PurchaseOrderAcceptApprovalForm
@@ -1079,7 +1078,7 @@ const PurchaseOrderDetail = ({
ref={editModal.ref}
closeOnBackdrop
className={{
modalBox: 'w-full max-w-screen-2xl max-h-[90vh] overflow-y-auto',
modalBox: 'w-full max-w-2xl max-h-[90vh] overflow-y-auto',
}}
>
<PurchaseOrderStaffApprovalForm
@@ -1098,7 +1097,7 @@ const PurchaseOrderDetail = ({
ref={penerimaanBarangModal.ref}
closeOnBackdrop
className={{
modalBox: 'w-full max-w-screen-2xl max-h-[90vh] overflow-y-auto',
modalBox: 'w-full max-w-2xl max-h-[90vh] overflow-y-auto',
}}
>
<PurchaseOrderAcceptApprovalForm
@@ -1,6 +1,6 @@
import * as XLSX from 'xlsx';
import { ReportExpense } from '@/types/api/report/report-expense';
import { formatCurrency, formatDate } from '@/lib/helper';
import { formatDate } from '@/lib/helper';
export const generateReportExpenseExcel = async (
data: ReportExpense[]
@@ -65,7 +65,7 @@ const getTableColumns = (
header: 'No',
flex: 0.5,
align: 'center',
cell: ({ row, index }) => index + 1,
cell: ({ index }) => index + 1,
footer: 'Total',
},
{
@@ -49,7 +49,7 @@ const getTableColumns = (total?: DebtSupplier['total']): PdfColumn[] => {
header: 'No',
flex: 0.5,
align: 'center',
cell: ({ row, index }) => index + 1,
cell: ({ index }) => index + 1,
footer: 'Total',
},
{
@@ -2,7 +2,7 @@
import ExcelJS from 'exceljs';
import { formatDate } from '@/lib/helper';
import { DebtRow, DebtSupplier } from '@/types/api/report/debt-supplier';
import { DebtSupplier } from '@/types/api/report/debt-supplier';
interface DebtSupplierExportExcelParams {
data: DebtSupplier[];
@@ -1,7 +1,6 @@
import DataStateSkeleton from '@/components/helper/skeleton/DataStateSkeleton';
import Table from '@/components/Table';
import { DebtRow } from '@/types/api/report/debt-supplier';
import { Icon } from '@iconify/react';
import { ColumnDef } from '@tanstack/react-table';
const DebtSupplierSkeleton = ({
@@ -129,7 +129,7 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
filterModal.closeModal();
setIsSubmitted(true);
},
onReset: (values) => {
onReset: () => {
setFilterParams({
start_date: undefined,
end_date: undefined,
@@ -170,10 +170,6 @@ const DebtSupplierTab = ({ tabId }: DebtSupplierTabProps) => {
: [],
[debtSupplier]
);
const meta =
isResponseSuccess(debtSupplier) && debtSupplier?.meta
? debtSupplier.meta
: null;
// ===== EXPORT DATA FETCHER =====
const debtSupplierExport = useCallback(async (): Promise<
@@ -61,7 +61,7 @@ const getTableColumns = (
header: 'No',
flex: 0.5,
align: 'center',
cell: ({ row, index }) => index + 1,
cell: ({ index }) => index + 1,
footer: 'Total',
},
{
@@ -336,11 +336,6 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
[purchasePerSupplier]
);
const meta =
isResponseSuccess(purchasePerSupplier) && purchasePerSupplier?.meta
? purchasePerSupplier.meta
: null;
// ===== EXPORT DATA FETCHER =====
const logisticPurchasePerSupplierExport = useCallback(async (): Promise<
LogisticPurchasePerSupplierReport[] | null
@@ -52,7 +52,7 @@ const getTableColumns = (
header: 'No',
flex: 0.5,
align: 'center',
cell: ({ row, index }) => index + 1,
cell: ({ index }) => index + 1,
},
{
key: 'so_date',
@@ -142,7 +142,7 @@ const getDetailColumns = (
header: 'No',
flex: 0.5,
align: 'center',
cell: ({ row, index }) => index + 1,
cell: ({ index }) => index + 1,
footer: 'TOTAL',
},
{
@@ -324,11 +324,6 @@ const HppPerKandangTab = ({ tabId }: HppPerKandangTabProps) => {
[hppPerKandang]
);
const period =
isResponseSuccess(hppPerKandang) && hppPerKandang?.data?.period
? hppPerKandang.data.period
: undefined;
// ===== EXPORT DATA FETCHER =====
const hppPerKandangExport =
useCallback(async (): Promise<HppPerKandangReport | null> => {
@@ -28,7 +28,6 @@ const ProductionResultProjectFlockKandangTable = ({
setPage,
setPageSize,
toQueryString: getTableFilterQueryString,
reset: resetFilter,
} = useTableFilter({
initial: {
filter_by: '',