mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
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:
@@ -59,6 +59,7 @@ const CATEGORIES = [
|
|||||||
{ value: 'pullet_close', label: 'Pullet Close' },
|
{ value: 'pullet_close', label: 'Pullet Close' },
|
||||||
{ value: 'produksi_open', label: 'Produksi Open' },
|
{ value: 'produksi_open', label: 'Produksi Open' },
|
||||||
{ value: 'produksi_close', label: 'Produksi Close' },
|
{ value: 'produksi_close', label: 'Produksi Close' },
|
||||||
|
{ value: 'empty_kandang', label: 'Kandang Kosong' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const TIME_TYPE_ORDER = ['Umum', 'Pagi', 'Siang', 'Sore', 'Malam'];
|
const TIME_TYPE_ORDER = ['Umum', 'Pagi', 'Siang', 'Sore', 'Malam'];
|
||||||
@@ -94,6 +95,8 @@ export function DailyChecklistContent() {
|
|||||||
const [selectedCategory, setSelectedCategory] = useState(
|
const [selectedCategory, setSelectedCategory] = useState(
|
||||||
searchParams.get('category') || ''
|
searchParams.get('category') || ''
|
||||||
);
|
);
|
||||||
|
const [emptyKandang, setEmptyKandang] = useState(false);
|
||||||
|
const [emptyKandangEndDate, setEmptyKandangEndDate] = useState('');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
options: kandangOptions,
|
options: kandangOptions,
|
||||||
@@ -225,6 +228,22 @@ export function DailyChecklistContent() {
|
|||||||
}
|
}
|
||||||
}, [date, kandangId, selectedCategory, pathname, router, searchParams]);
|
}, [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
|
// Format date for display
|
||||||
const formatDateForDisplay = (dateStr: string) => {
|
const formatDateForDisplay = (dateStr: string) => {
|
||||||
if (!dateStr) return 'Pilih tanggal';
|
if (!dateStr) return 'Pilih tanggal';
|
||||||
@@ -246,7 +265,7 @@ export function DailyChecklistContent() {
|
|||||||
// Check for existing checklist when unique key changes
|
// Check for existing checklist when unique key changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkAndLoadChecklist = async () => {
|
const checkAndLoadChecklist = async () => {
|
||||||
if (!date || !kandangId || !selectedCategory) {
|
if (!date || !kandangId || (!emptyKandang && !selectedCategory)) {
|
||||||
setDailyChecklistId(null);
|
setDailyChecklistId(null);
|
||||||
setChecklistStatus('DRAFT');
|
setChecklistStatus('DRAFT');
|
||||||
// setIsEditMode(false);
|
// setIsEditMode(false);
|
||||||
@@ -257,12 +276,24 @@ export function DailyChecklistContent() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (emptyKandang && !emptyKandangEndDate) {
|
||||||
|
setDailyChecklistId(null);
|
||||||
|
setChecklistStatus('DRAFT');
|
||||||
|
setSelectedPhaseIds([]);
|
||||||
|
setActivitiesByPhase({});
|
||||||
|
setTaskIdsByPhaseActivityId({});
|
||||||
|
setAssignments({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const checklist = await DailyChecklistApi.create({
|
const checklist = await DailyChecklistApi.create({
|
||||||
date,
|
date,
|
||||||
kandang_id: Number(kandangId),
|
kandang_id: Number(kandangId),
|
||||||
category: selectedCategory,
|
category: emptyKandang ? 'empty_kandang' : selectedCategory,
|
||||||
status: 'DRAFT',
|
status: 'DRAFT',
|
||||||
|
empty_kandang: emptyKandang,
|
||||||
|
empty_kandang_end_date: emptyKandang ? emptyKandangEndDate : '',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isResponseError(checklist)) {
|
if (isResponseError(checklist)) {
|
||||||
@@ -313,7 +344,7 @@ export function DailyChecklistContent() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
checkAndLoadChecklist();
|
checkAndLoadChecklist();
|
||||||
}, [date, kandangId, selectedCategory]);
|
}, [date, kandangId, selectedCategory, emptyKandang, emptyKandangEndDate]);
|
||||||
|
|
||||||
// Load activities and tasks when phases change
|
// Load activities and tasks when phases change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -1034,7 +1065,7 @@ export function DailyChecklistContent() {
|
|||||||
<Select
|
<Select
|
||||||
value={selectedCategory}
|
value={selectedCategory}
|
||||||
onValueChange={setSelectedCategory}
|
onValueChange={setSelectedCategory}
|
||||||
disabled={!isChecklistStatusDraft}
|
disabled={!isChecklistStatusDraft || emptyKandang}
|
||||||
>
|
>
|
||||||
<SelectTrigger
|
<SelectTrigger
|
||||||
id='category'
|
id='category'
|
||||||
@@ -1053,6 +1084,39 @@ export function DailyChecklistContent() {
|
|||||||
</div>
|
</div>
|
||||||
</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 */}
|
{/* Phase Selection Section */}
|
||||||
{dailyChecklistId && (
|
{dailyChecklistId && (
|
||||||
<div className='mb-6 pb-6 border-b border-gray-200'>
|
<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',
|
pullet_close: 'Pullet Close',
|
||||||
produksi_open: 'Produksi Open',
|
produksi_open: 'Produksi Open',
|
||||||
produksi_close: 'Produksi Close',
|
produksi_close: 'Produksi Close',
|
||||||
|
empty_kandang: 'Kandang Kosong',
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ListDailyChecklistContent() {
|
export function ListDailyChecklistContent() {
|
||||||
|
|||||||
@@ -217,7 +217,9 @@ export function MasterEmployeeContent() {
|
|||||||
'Error creating employee:',
|
'Error creating employee:',
|
||||||
createEmployeeResponse.message
|
createEmployeeResponse.message
|
||||||
);
|
);
|
||||||
toast.error('Gagal menambahkan ABK');
|
toast.error(
|
||||||
|
'Gagal menambahkan ABK: ' + createEmployeeResponse.message
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +240,9 @@ export function MasterEmployeeContent() {
|
|||||||
'Error updating employee:',
|
'Error updating employee:',
|
||||||
updateEmployeeResponse.message
|
updateEmployeeResponse.message
|
||||||
);
|
);
|
||||||
toast.error('Gagal menambahkan ABK');
|
toast.error(
|
||||||
|
'Gagal memperbarui ABK: ' + updateEmployeeResponse.message
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export type BaseDailyChecklist = {
|
|||||||
status: string;
|
status: string;
|
||||||
category: string;
|
category: string;
|
||||||
date: string;
|
date: string;
|
||||||
|
empty_kandang?: boolean;
|
||||||
|
empty_kandang_end_date?: string | null;
|
||||||
kandang?: Pick<BaseKandang, 'id' | 'name' | 'status' | 'capacity'>;
|
kandang?: Pick<BaseKandang, 'id' | 'name' | 'status' | 'capacity'>;
|
||||||
total_phase: number;
|
total_phase: number;
|
||||||
total_activity: number;
|
total_activity: number;
|
||||||
@@ -57,6 +59,8 @@ export type CreateDailyChecklistPayload = {
|
|||||||
kandang_id: number;
|
kandang_id: number;
|
||||||
category: string;
|
category: string;
|
||||||
status: string;
|
status: string;
|
||||||
|
empty_kandang: boolean;
|
||||||
|
empty_kandang_end_date: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PerformanceOverviewItem = {
|
export type PerformanceOverviewItem = {
|
||||||
|
|||||||
Reference in New Issue
Block a user