mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
refactor(FE): Remove unused imports and redundant code
This commit is contained in:
@@ -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;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user