Merge branch 'fix/daily-checklist-empty-kandang-flag' into 'development'

[FIX/FE] Daily Checklist Empty Kandang Flag

See merge request mbugroup/lti-web-client!422
This commit is contained in:
Rivaldi A N S
2026-04-22 15:58:01 +00:00
4 changed files with 79 additions and 6 deletions
@@ -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() {
<Select
value={selectedCategory}
onValueChange={setSelectedCategory}
disabled={!isChecklistStatusDraft}
disabled={!isChecklistStatusDraft || emptyKandang}
>
<SelectTrigger
id='category'
@@ -1053,6 +1084,39 @@ export function DailyChecklistContent() {
</div>
</div>
<div className='mb-6 pb-6 border-b border-gray-200'>
<div className='flex flex-col gap-4 md:flex-row md:items-end md:gap-6'>
<label className='flex items-center gap-2 text-sm font-medium text-gray-900'>
<input
type='checkbox'
checked={emptyKandang}
onChange={(e) => setEmptyKandang(e.target.checked)}
disabled={!isChecklistStatusDraft}
className='checkbox-clean'
/>
<span>Kandang Kosong</span>
</label>
{emptyKandang && (
<div className='w-full md:max-w-md'>
<Label htmlFor='empty_kandang_end_date'>
Tanggal Akhir Kandang Kosong{' '}
<span className='text-red-500'>*</span>
</Label>
<div className='mt-1.5'>
<DatePicker
date={emptyKandangEndDate}
onDateChange={setEmptyKandangEndDate}
disabled={!isChecklistStatusDraft}
placeholder='Pilih tanggal akhir kandang kosong'
formatDisplay={formatDateForDisplay}
/>
</div>
</div>
)}
</div>
</div>
{/* Phase Selection Section */}
{dailyChecklistId && (
<div className='mb-6 pb-6 border-b border-gray-200'>
@@ -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() {
@@ -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;
}
+4
View File
@@ -12,6 +12,8 @@ export type BaseDailyChecklist = {
status: string;
category: string;
date: string;
empty_kandang?: boolean;
empty_kandang_end_date?: string | null;
kandang?: Pick<BaseKandang, 'id' | 'name' | 'status' | 'capacity'>;
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 = {