diff --git a/src/app/production/project-flock/chickin/add/kandang/page.tsx b/src/app/production/project-flock/chickin/add/kandang/page.tsx
index 0805f010..a22039d1 100644
--- a/src/app/production/project-flock/chickin/add/kandang/page.tsx
+++ b/src/app/production/project-flock/chickin/add/kandang/page.tsx
@@ -16,8 +16,12 @@ export default function AddChickinKandang() {
data: projectFlockKandang,
isLoading: isLoading,
mutate: refreshProjectFlockKandang,
- } = useSWR(projectFlockKandangId, (id: number) =>
- ProjectFlockKandangApi.getSingle(id)
+ } = useSWR(
+ `get-single-project-flock-kandang/${projectFlockKandangId}`,
+ async () =>
+ ProjectFlockKandangApi.getSingle(
+ parseInt(projectFlockKandangId as string)
+ )
);
if (!projectFlockKandangId) {
diff --git a/src/app/production/project-flock/detail/page.tsx b/src/app/production/project-flock/detail/page.tsx
index 28a577ff..91d4dfd5 100644
--- a/src/app/production/project-flock/detail/page.tsx
+++ b/src/app/production/project-flock/detail/page.tsx
@@ -2,11 +2,8 @@
import ProjectFlockForm from '@/components/pages/production/project-flock/form/ProjectFlockForm';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
-import { FlockApi } from '@/services/api/master-data';
import { ProjectFlockApi } from '@/services/api/production/project-flock';
-import { ProjectFlock } from '@/types/api/production/project-flock';
import { useRouter, useSearchParams } from 'next/navigation';
-import { useState } from 'react';
import useSWR from 'swr';
const ProjectFlockDetail = () => {
@@ -15,22 +12,12 @@ const ProjectFlockDetail = () => {
const projectFlockId = searchParams.get('projectFlockId');
- const [projectName, setProjectName] = useState();
-
const {
data: projectFlock,
isLoading: isLoadingProjectFlock,
mutate: refreshProjectFlock,
} = useSWR(projectFlockId, (id: number) => ProjectFlockApi.getSingle(id));
- const {
- data: approvalLines,
- isLoading: isLoadingApprovalLines,
- mutate: refreshApprovalLines,
- } = useSWR('approvals', (id: number) =>
- ProjectFlockApi.getApprovalLines((projectFlockId ?? 0) as number)
- );
-
if (!projectFlockId) {
router.back();
@@ -51,15 +38,13 @@ const ProjectFlockDetail = () => {
return (
- {isLoadingProjectFlock ||
- (isLoadingApprovalLines && (
-
- ))}
- {isResponseSuccess(projectFlock) && isResponseSuccess(approvalLines) && (
+ {isLoadingProjectFlock && (
+
+ )}
+ {isResponseSuccess(projectFlock) && (
)}
diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx
index ea53d2c9..a242b1e4 100644
--- a/src/components/Modal.tsx
+++ b/src/components/Modal.tsx
@@ -16,7 +16,7 @@ export const useModal = () => {
const openModal = useCallback(() => {
if (!ref.current) return;
- ref.current.showModal();
+ ref.current.show();
setOpen(true);
}, []);
@@ -30,7 +30,6 @@ export const useModal = () => {
open ? closeModal() : openModal();
}, [open, closeModal, openModal]);
- // Gunakan useEffect agar event listener tidak didaftarkan berulang kali
useEffect(() => {
const dialog = ref.current;
if (!dialog) return;
@@ -48,7 +47,6 @@ export const useModal = () => {
interface ModalProps {
ref: RefObject
;
- id?: string;
children?: ReactNode;
closeOnBackdrop?: boolean;
className?: {
@@ -57,13 +55,7 @@ interface ModalProps {
};
}
-const Modal = ({
- ref,
- id,
- children,
- closeOnBackdrop,
- className,
-}: ModalProps) => {
+const Modal = ({ ref, children, closeOnBackdrop, className }: ModalProps) => {
const handleBackdropClick = (e: React.MouseEvent) => {
if (closeOnBackdrop && e.target === ref.current) {
ref.current?.close();
@@ -73,7 +65,6 @@ const Modal = ({
return (
}
data={
- isResponseSuccess(listProjectFlockKandang)
+ projectFlock && isResponseSuccess(listProjectFlockKandang)
? listProjectFlockKandang.data
: []
}
@@ -293,6 +301,8 @@ const ProjectFlockChickinDetail = ({
.replace(/_/g, ' ')
.replace(/\b\w/g, (char) => char.toUpperCase())}
/>
+ ) : projectFlock?.approval?.step_number === 1 ? (
+
) : (
);
@@ -310,6 +320,7 @@ const ProjectFlockChickinDetail = ({
handleChickinClick(props.row.original);
}}
className='p-1'
+ disabled={projectFlock?.approval?.step_number === 1}
>
| undefined
>;
@@ -59,16 +54,11 @@ interface ProjectFlockFormProps {
const ProjectFlockForm = ({
formType = 'add',
initialValues,
- initialApprovals,
refreshProjectFlocks,
}: ProjectFlockFormProps) => {
// State
const router = useRouter();
- const projectFlockSteps = APPROVAL_WORKFLOWS.find(
- (step) => step.key === 'PROJECT_FLOCKS'
- );
-
const [projectFlockFormErrorMessage, setProjectFlockFormErrorMessage] =
useState('');
const [selectedArea, setSelectedArea] = useState('');
@@ -120,34 +110,28 @@ const ProjectFlockForm = ({
}, [initialValues]);
// Fetch Data
- const {
- rawData: flocks,
- isLoadingOptions: isLoadingFlocks,
- options: optionsFlock,
- } = useSelect(FlockApi.basePath, 'id', 'name');
+ const { isLoadingOptions: isLoadingFlocks, options: optionsFlock } =
+ useSelect(FlockApi.basePath, 'id', 'name');
- const {
- options: optionsArea,
- isLoadingOptions: isLoadingAreas,
- rawData: areas,
- } = useSelect(AreaApi.basePath, 'id', 'name');
+ const { options: optionsArea, isLoadingOptions: isLoadingAreas } = useSelect(
+ AreaApi.basePath,
+ 'id',
+ 'name'
+ );
- const {
- options: optionsLocation,
- isLoadingOptions: isLoadingLocations,
- rawData: locations,
- } = useSelect(LocationApi.basePath, 'id', 'name', '', {
- area_id:
- selectedArea != ''
- ? selectedArea
- : ((initialValues?.area?.id ?? '') as string),
- });
+ const { options: optionsLocation, isLoadingOptions: isLoadingLocations } =
+ useSelect(LocationApi.basePath, 'id', 'name', '', {
+ area_id:
+ selectedArea != ''
+ ? selectedArea
+ : ((initialValues?.area?.id ?? '') as string),
+ });
- const {
- options: optionsFcr,
- isLoadingOptions: isLoadingFcrs,
- rawData: fcrs,
- } = useSelect(FcrApi.basePath, 'id', 'name');
+ const { options: optionsFcr, isLoadingOptions: isLoadingFcrs } = useSelect(
+ FcrApi.basePath,
+ 'id',
+ 'name'
+ );
const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
search: '',
@@ -164,6 +148,16 @@ const ProjectFlockForm = ({
(id: string) => ProjectFlockApi.getNextPeriod(id)
);
+ const {
+ approvals,
+ isLoading: approvalsLoading,
+ refresh: refreshApprovals,
+ } = useApprovalSteps({
+ moduleUrl: `/production/project-flocks/${initialValues?.id}`,
+ moduleName: 'PROJECT_FLOCKS',
+ moduleId: initialValues?.id.toString() ?? '',
+ });
+
useEffect(() => {
if (isResponseSuccess(kandang)) {
if (selectedLocation) {
@@ -516,6 +510,7 @@ const ProjectFlockForm = ({
if (isResponseError(approveProjectFlockRes)) {
toast.error(approveProjectFlockRes?.message as string);
}
+ refreshApprovals();
confirmModal.closeModal();
setIsApproveLoading(false);
};
@@ -558,79 +553,8 @@ const ProjectFlockForm = ({
)}
- {formType == 'detail' && initialApprovals && (
-
-
- {projectFlockSteps?.steps.map((step, idx) => {
- const approvalLogs = initialApprovals.find(
- (approve) => approve.step_number == step.step_number
- );
- return (
-
- {approvalLogs &&
- approvalLogs?.approvals?.map((approval, idx) => {
- return (
-
-
- Status: {approval.step_name}
-
- Oleh: {approval.action_by.name}
-
-
- Tanggal:{' '}
- {formatDate(
- approval.action_at,
- 'DD-MM-yyyy HH:mm:ss'
- )}
-
-
-
- );
- })}
-
- }
- >
- {step.step_number <=
- (initialValues?.approval.step_number ?? 0) ? (
-
- ) : (
-
- )}
-
- }
- >
- {step.step_name}
-
- );
- })}
-
-
+ {approvals && !approvalsLoading && (
+
)}
{formType == 'detail' && (
@@ -675,32 +599,12 @@ const ProjectFlockForm = ({
);
}}
>
+
Chickin
)}
)}
-
- {JSON.stringify(formik.values)}
-
-
- {JSON.stringify(formik.initialValues)}
-
-
- {JSON.stringify(formik.errors)}
-