diff --git a/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx b/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx index 1a9b4406..e0a95cd0 100644 --- a/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx +++ b/src/figma-make/components/pages/daily-checklist/DailyChecklistContent.tsx @@ -59,6 +59,7 @@ const CATEGORIES = [ { value: 'pullet_close', label: 'Pullet Close' }, { value: 'produksi_open', label: 'Produksi Open' }, { value: 'produksi_close', label: 'Produksi Close' }, + { value: 'empty_kandang', label: 'Kandang Kosong' }, ]; const TIME_TYPE_ORDER = ['Umum', 'Pagi', 'Siang', 'Sore', 'Malam']; @@ -94,6 +95,8 @@ export function DailyChecklistContent() { const [selectedCategory, setSelectedCategory] = useState( searchParams.get('category') || '' ); + const [emptyKandang, setEmptyKandang] = useState(false); + const [emptyKandangEndDate, setEmptyKandangEndDate] = useState(''); const { options: kandangOptions, @@ -225,6 +228,22 @@ export function DailyChecklistContent() { } }, [date, kandangId, selectedCategory, pathname, router, searchParams]); + useEffect(() => { + if (!emptyKandang) { + setEmptyKandangEndDate(''); + setSelectedCategory(''); + return; + } + + setSelectedCategory('empty_kandang'); + }, [emptyKandang]); + + useEffect(() => { + if (selectedCategory === 'empty_kandang') { + setEmptyKandang(true); + } + }, [selectedCategory]); + // Format date for display const formatDateForDisplay = (dateStr: string) => { if (!dateStr) return 'Pilih tanggal'; @@ -246,7 +265,7 @@ export function DailyChecklistContent() { // Check for existing checklist when unique key changes useEffect(() => { const checkAndLoadChecklist = async () => { - if (!date || !kandangId || !selectedCategory) { + if (!date || !kandangId || (!emptyKandang && !selectedCategory)) { setDailyChecklistId(null); setChecklistStatus('DRAFT'); // setIsEditMode(false); @@ -257,12 +276,24 @@ export function DailyChecklistContent() { return; } + if (emptyKandang && !emptyKandangEndDate) { + setDailyChecklistId(null); + setChecklistStatus('DRAFT'); + setSelectedPhaseIds([]); + setActivitiesByPhase({}); + setTaskIdsByPhaseActivityId({}); + setAssignments({}); + return; + } + try { const checklist = await DailyChecklistApi.create({ date, kandang_id: Number(kandangId), - category: selectedCategory, + category: emptyKandang ? 'empty_kandang' : selectedCategory, status: 'DRAFT', + empty_kandang: emptyKandang, + empty_kandang_end_date: emptyKandang ? emptyKandangEndDate : '', }); if (isResponseError(checklist)) { @@ -313,7 +344,7 @@ export function DailyChecklistContent() { }; checkAndLoadChecklist(); - }, [date, kandangId, selectedCategory]); + }, [date, kandangId, selectedCategory, emptyKandang, emptyKandangEndDate]); // Load activities and tasks when phases change useEffect(() => { @@ -1034,7 +1065,7 @@ export function DailyChecklistContent() { setEmptyKandang(e.target.checked)} + disabled={!isChecklistStatusDraft} + className='checkbox-clean' + /> + Kandang Kosong + + + {emptyKandang && ( +
+ +
+ +
+
+ )} + + + {/* Phase Selection Section */} {dailyChecklistId && (
diff --git a/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx b/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx index b8e81fa9..ae00d17a 100644 --- a/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx +++ b/src/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent.tsx @@ -60,6 +60,7 @@ const CATEGORY_LABELS: { [key: string]: string } = { pullet_close: 'Pullet Close', produksi_open: 'Produksi Open', produksi_close: 'Produksi Close', + empty_kandang: 'Kandang Kosong', }; export function ListDailyChecklistContent() { diff --git a/src/figma-make/components/pages/master-data/employee/MasterEmployeeContent.tsx b/src/figma-make/components/pages/master-data/employee/MasterEmployeeContent.tsx index 9944ed21..37c81057 100644 --- a/src/figma-make/components/pages/master-data/employee/MasterEmployeeContent.tsx +++ b/src/figma-make/components/pages/master-data/employee/MasterEmployeeContent.tsx @@ -217,7 +217,9 @@ export function MasterEmployeeContent() { 'Error creating employee:', createEmployeeResponse.message ); - toast.error('Gagal menambahkan ABK'); + toast.error( + 'Gagal menambahkan ABK: ' + createEmployeeResponse.message + ); return; } @@ -238,7 +240,9 @@ export function MasterEmployeeContent() { 'Error updating employee:', updateEmployeeResponse.message ); - toast.error('Gagal menambahkan ABK'); + toast.error( + 'Gagal memperbarui ABK: ' + updateEmployeeResponse.message + ); return; } diff --git a/src/types/api/daily-checklist/daily-checklist.d.ts b/src/types/api/daily-checklist/daily-checklist.d.ts index 5c9cae07..5c7d3b26 100644 --- a/src/types/api/daily-checklist/daily-checklist.d.ts +++ b/src/types/api/daily-checklist/daily-checklist.d.ts @@ -12,6 +12,8 @@ export type BaseDailyChecklist = { status: string; category: string; date: string; + empty_kandang?: boolean; + empty_kandang_end_date?: string | null; kandang?: Pick; total_phase: number; total_activity: number; @@ -57,6 +59,8 @@ export type CreateDailyChecklistPayload = { kandang_id: number; category: string; status: string; + empty_kandang: boolean; + empty_kandang_end_date: string; }; export type PerformanceOverviewItem = {