mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
feat(FE-170,174,175): implement next day recording functionality in RecordingForm
This commit is contained in:
@@ -32,6 +32,7 @@ import {
|
|||||||
UpdateGrowingRecordingPayload,
|
UpdateGrowingRecordingPayload,
|
||||||
UpdateLayingRecordingPayload,
|
UpdateLayingRecordingPayload,
|
||||||
Recording,
|
Recording,
|
||||||
|
NextDayRecording,
|
||||||
} from '@/types/api/production/recording';
|
} from '@/types/api/production/recording';
|
||||||
import { type BaseApiResponse } from '@/types/api/api-general';
|
import { type BaseApiResponse } from '@/types/api/api-general';
|
||||||
import { ProjectFlockKandangLookup } from '@/types/api/production/project-flock';
|
import { ProjectFlockKandangLookup } from '@/types/api/production/project-flock';
|
||||||
@@ -93,13 +94,15 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
|
|
||||||
const [isApproveLoading, setIsApproveLoading] = useState(false);
|
const [isApproveLoading, setIsApproveLoading] = useState(false);
|
||||||
const [isRejectLoading, setIsRejectLoading] = useState(false);
|
const [isRejectLoading, setIsRejectLoading] = useState(false);
|
||||||
const [approvalNotes, setApprovalNotes] = useState('');
|
const [, setApprovalNotes] = useState('');
|
||||||
const [recordingFormErrorMessage, setRecordingFormErrorMessage] =
|
const [recordingFormErrorMessage, setRecordingFormErrorMessage] =
|
||||||
useState('');
|
useState('');
|
||||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
const [newRecordingData, setNewRecordingData] = useState<Recording | null>(
|
const [newRecordingData, setNewRecordingData] = useState<Recording | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
const [nextDayRecording, setNextDayRecording] =
|
||||||
|
useState<NextDayRecording | null>(null);
|
||||||
|
|
||||||
const approveModal = useModal();
|
const approveModal = useModal();
|
||||||
const rejectModal = useModal();
|
const rejectModal = useModal();
|
||||||
@@ -382,6 +385,38 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
RecordingApi.getAllFetcher
|
RecordingApi.getAllFetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const nextDayRecordingUrl = useMemo(() => {
|
||||||
|
if (!selectedProjectFlock) return null;
|
||||||
|
const projectFlockId =
|
||||||
|
typeof selectedProjectFlock.value === 'string'
|
||||||
|
? parseInt(selectedProjectFlock.value, 10)
|
||||||
|
: selectedProjectFlock.value;
|
||||||
|
return `${RecordingApi.basePath}/next-day?project_flock_id=${projectFlockId}`;
|
||||||
|
}, [selectedProjectFlock]);
|
||||||
|
|
||||||
|
const { data: nextDayRecordingData } = useSWR(
|
||||||
|
nextDayRecordingUrl,
|
||||||
|
nextDayRecordingUrl
|
||||||
|
? () => {
|
||||||
|
const projectFlockId =
|
||||||
|
typeof selectedProjectFlock!.value === 'string'
|
||||||
|
? parseInt(selectedProjectFlock!.value, 10)
|
||||||
|
: selectedProjectFlock!.value;
|
||||||
|
return RecordingApi.nextDayRecording(projectFlockId);
|
||||||
|
}
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (nextDayRecordingData?.status === 'success') {
|
||||||
|
setNextDayRecording(
|
||||||
|
nextDayRecordingData.data as unknown as NextDayRecording
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setNextDayRecording(null);
|
||||||
|
}
|
||||||
|
}, [nextDayRecordingData]);
|
||||||
|
|
||||||
const { data: stockProducts, isLoading: isLoadingStockProducts } = useSWR(
|
const { data: stockProducts, isLoading: isLoadingStockProducts } = useSWR(
|
||||||
stockProductsUrl,
|
stockProductsUrl,
|
||||||
ProductWarehouseApi.getAllFetcher
|
ProductWarehouseApi.getAllFetcher
|
||||||
@@ -1057,12 +1092,33 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const projectFlockKandangId =
|
const projectFlockKandangId =
|
||||||
projectFlockKandangLookup.project_flock_kandang_id;
|
projectFlockKandangLookup.project_flock_kandang_id;
|
||||||
|
|
||||||
if (
|
if (type === 'add') {
|
||||||
type === 'add' &&
|
if (recordedProjectFlockKandangIds.has(projectFlockKandangId)) {
|
||||||
recordedProjectFlockKandangIds.has(projectFlockKandangId)
|
toast.error('Project Flock Kandang ini sudah direcord hari ini!');
|
||||||
) {
|
return;
|
||||||
toast.error('Project Flock Kandang ini sudah direcord hari ini!');
|
}
|
||||||
return;
|
|
||||||
|
if (
|
||||||
|
nextDayRecording &&
|
||||||
|
nextDayRecording.project_flock_kandang_id === projectFlockKandangId
|
||||||
|
) {
|
||||||
|
const hasSameDayRecording = isResponseSuccess(existingRecordings)
|
||||||
|
? existingRecordings.data?.some(
|
||||||
|
(recording: Recording) =>
|
||||||
|
recording.project_flock_kandang_id ===
|
||||||
|
projectFlockKandangId &&
|
||||||
|
recording.day === nextDayRecording.next_day
|
||||||
|
)
|
||||||
|
: false;
|
||||||
|
|
||||||
|
if (hasSameDayRecording) {
|
||||||
|
toast.error(
|
||||||
|
`Recording untuk hari ${nextDayRecording.next_day} sudah ada.
|
||||||
|
Tidak bisa membuat recording duplikat, mohon perbarui recording yang sudah ada terlebih dahulu.`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formik.values.project_flock_kandang_id !== projectFlockKandangId) {
|
if (formik.values.project_flock_kandang_id !== projectFlockKandangId) {
|
||||||
@@ -1083,6 +1139,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
type,
|
type,
|
||||||
recordedProjectFlockKandangIds,
|
recordedProjectFlockKandangIds,
|
||||||
formik.values.project_flock_kandang_id,
|
formik.values.project_flock_kandang_id,
|
||||||
|
nextDayRecording,
|
||||||
|
existingRecordings,
|
||||||
|
today,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
UpdateRecordingPayload,
|
UpdateRecordingPayload,
|
||||||
CreateGradingPayload,
|
CreateGradingPayload,
|
||||||
UpdateGradingPayload,
|
UpdateGradingPayload,
|
||||||
|
NextDayRecording,
|
||||||
} from '@/types/api/production/recording';
|
} from '@/types/api/production/recording';
|
||||||
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
|
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
|
||||||
|
|
||||||
@@ -95,6 +96,17 @@ export class RecordingService extends BaseApiService<
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async nextDayRecording(
|
||||||
|
projectFlockId: number
|
||||||
|
): Promise<BaseApiResponse<NextDayRecording> | undefined> {
|
||||||
|
return await this.customRequest<BaseApiResponse<NextDayRecording>>(`next-day`, {
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
project_flock_id: projectFlockId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RecordingApi = new RecordingService('/production/recordings');
|
export const RecordingApi = new RecordingService('/production/recordings');
|
||||||
|
|||||||
+5
@@ -87,6 +87,11 @@ export type Recording = BaseMetadata &
|
|||||||
grading_eggs?: GradingEgg[];
|
grading_eggs?: GradingEgg[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type NextDayRecording = {
|
||||||
|
project_flock_kandang_id: number;
|
||||||
|
next_day: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type CreateGrowingRecordingPayload = {
|
export type CreateGrowingRecordingPayload = {
|
||||||
project_flock_kandang_id: number;
|
project_flock_kandang_id: number;
|
||||||
body_weights: {
|
body_weights: {
|
||||||
|
|||||||
Reference in New Issue
Block a user