refactor(FE): Nest project_flock in Recording and update UI

This commit is contained in:
rstubryan
2026-01-13 16:01:30 +07:00
parent 34d7310cc9
commit e77a43300a
3 changed files with 98 additions and 46 deletions
@@ -678,12 +678,13 @@ const RecordingTable = () => {
{
header: 'Nama Project',
cell: (props) =>
`Project ${props.row.original.project_flock_kandang_id}`,
props.row.original.project_flock?.flock_name || '-',
},
{
header: 'Kategori',
cell: (props) => {
const category = props.row.original.project_flock_category;
const category =
props.row.original.project_flock?.project_flock_category;
if (!category) return '-';
const color = category === 'LAYING' ? 'info' : 'warning';
return (
@@ -706,7 +707,8 @@ const RecordingTable = () => {
{
header: 'Populasi Awal',
cell: (props) =>
props.row.original.total_chick_qty?.toLocaleString() || '-',
props.row.original.project_flock?.total_chick_qty?.toLocaleString() ||
'-',
},
{
header: 'Status Approval',
@@ -252,9 +252,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
: undefined;
const projectFlockKandangDetailUrl = useMemo(() => {
if (type === 'add' || !initialValues?.project_flock_kandang_id) return null;
return `${ProjectFlockKandangApi.basePath}/${initialValues.project_flock_kandang_id}`;
}, [type, initialValues?.project_flock_kandang_id]);
if (
type === 'add' ||
!initialValues?.project_flock?.project_flock_kandang_id
)
return null;
return `${ProjectFlockKandangApi.basePath}/${initialValues.project_flock.project_flock_kandang_id}`;
}, [type, initialValues?.project_flock?.project_flock_kandang_id]);
const { data: projectFlockKandangDetailData } = useSWR(
projectFlockKandangDetailUrl,
@@ -404,12 +408,12 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}, [approvedProjectFlockKandangsData]);
const isLayingCategory =
initialValues?.project_flock_category === 'LAYING' ||
initialValues?.project_flock?.project_flock_category === 'LAYING' ||
projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
const isGrowingCategory =
initialValues?.project_flock_category === 'GROWING' ||
initialValues?.project_flock?.project_flock_category === 'GROWING' ||
projectFlockKandangLookup?.project_flock?.category === 'GROWING' ||
projectFlockKandangDetail?.project_flock?.category === 'GROWING';
@@ -555,7 +559,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
todayRecordings.forEach((recording) => {
const recordingDate = recording.record_datetime?.split('T')[0];
if (recordingDate === today) {
recordedIds.add(recording.project_flock_kandang_id);
recordedIds.add(recording.project_flock.project_flock_kandang_id);
}
});
@@ -1005,7 +1009,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
const hasSameDayRecording = isResponseSuccess(existingRecordings)
? existingRecordings.data?.some(
(recording: Recording) =>
recording.project_flock_kandang_id ===
recording.project_flock.project_flock_kandang_id ===
projectFlockKandangId &&
recording.day === nextDayRecording.next_day
)
@@ -1543,13 +1547,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
<Badge
variant='soft'
color={
initialValues.project_flock_category === 'LAYING'
initialValues.project_flock
?.project_flock_category === 'LAYING'
? 'info'
: 'warning'
}
size='sm'
>
{initialValues.project_flock_category}
{initialValues.project_flock?.project_flock_category}
</Badge>
</p>
</div>
@@ -1579,7 +1584,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{type === 'detail' && initialValues && (
<div
className={`grid gap-6 mb-6 grid-cols-1 ${
initialValues.project_flock_category === 'LAYING'
initialValues.project_flock?.project_flock_category === 'LAYING'
? 'xl:grid-cols-3'
: 'xl:grid-cols-2'
}`}
@@ -1614,8 +1619,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</span>
</td>
<td className='text-center py-3 text-gray-600'>
{initialValues.fcr_std && initialValues.fcr_std > 0
? formatNumber(initialValues.fcr_std)
{initialValues.project_flock?.fcr?.fcr_std &&
initialValues.project_flock?.fcr?.fcr_std > 0
? formatNumber(
initialValues.project_flock?.fcr?.fcr_std
)
: '-'}
</td>
</tr>
@@ -1630,9 +1638,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</span>
</td>
<td className='text-center py-3 text-gray-600'>
{initialValues.feed_intake_std &&
initialValues.feed_intake_std > 0
? formatNumber(initialValues.feed_intake_std)
{initialValues.project_flock?.production_standart
?.feed_intake_std &&
initialValues.project_flock?.production_standart
?.feed_intake_std > 0
? formatNumber(
initialValues.project_flock?.production_standart
?.feed_intake_std
)
: '-'}
</td>
</tr>
@@ -1698,9 +1711,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
colSpan={2}
className='text-center py-3 font-semibold'
>
{initialValues.total_chick_qty &&
initialValues.total_chick_qty > 0
? formatNumber(initialValues.total_chick_qty)
{initialValues.project_flock?.total_chick_qty &&
initialValues.project_flock?.total_chick_qty > 0
? formatNumber(
initialValues.project_flock?.total_chick_qty
)
: '-'}
</td>
</tr>
@@ -1712,7 +1727,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{/* Egg Production Section - Only for LAYING category */}
{type === 'detail' &&
initialValues &&
initialValues.project_flock_category === 'LAYING' && (
initialValues.project_flock?.project_flock_category ===
'LAYING' && (
<div className='border border-gray-200 rounded-lg bg-white'>
<div className='px-4 py-3 border-b border-gray-200'>
<span className='card-title font-bold text-xl'>
@@ -1744,9 +1760,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</span>
</td>
<td className='text-center py-3 text-gray-600'>
{initialValues.egg_mass_std &&
initialValues.egg_mass_std > 0
? formatNumber(initialValues.egg_mass_std)
{initialValues.project_flock?.production_standart
?.egg_mass_std &&
initialValues.project_flock?.production_standart
?.egg_mass_std > 0
? formatNumber(
initialValues.project_flock
?.production_standart?.egg_mass_std
)
: '-'}
</td>
</tr>
@@ -1763,9 +1784,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</span>
</td>
<td className='text-center py-3 text-gray-600'>
{initialValues.egg_weight_std &&
initialValues.egg_weight_std > 0
? formatNumber(initialValues.egg_weight_std)
{initialValues.project_flock?.production_standart
?.egg_weight_std &&
initialValues.project_flock?.production_standart
?.egg_weight_std > 0
? formatNumber(
initialValues.project_flock
?.production_standart?.egg_weight_std
)
: '-'}
</td>
</tr>
@@ -1780,9 +1806,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</span>
</td>
<td className='text-center py-3 text-gray-600'>
{initialValues.hen_day_std !== undefined &&
initialValues.hen_day_std > 0
? `${initialValues.hen_day_std}%`
{initialValues.project_flock?.production_standart
?.hen_day_std !== undefined &&
initialValues.project_flock?.production_standart
?.hen_day_std > 0
? `${initialValues.project_flock?.production_standart?.hen_day_std}%`
: '-'}
</td>
</tr>
@@ -1797,9 +1825,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</span>
</td>
<td className='text-center py-3 text-gray-600'>
{initialValues.hen_house_std !== undefined &&
initialValues.hen_house_std > 0
? `${initialValues.hen_house_std}%`
{initialValues.project_flock?.production_standart
?.hen_house_std !== undefined &&
initialValues.project_flock?.production_standart
?.hen_house_std > 0
? `${initialValues.project_flock?.production_standart?.hen_house_std}%`
: '-'}
</td>
</tr>
+32 -12
View File
@@ -1,34 +1,52 @@
import { BaseApproval, BaseMetadata, User } from '@/types/api/api-general';
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
import { Warehouse } from '@/types/api/master-data/warehouse';
export type ProductionStandard = {
id: number;
week: number;
name: string;
hen_day_std: number;
hen_house_std: number;
feed_intake_std: number;
max_depletion_std: number;
egg_mass_std: number;
egg_weight_std: number;
};
export type FCR = {
id: number;
name: string;
fcr_std: number;
};
export type ProjectFlock = {
project_flock_kandang_id: number;
flock_name: string;
project_flock_category: 'GROWING' | 'LAYING';
period: number;
production_standart: ProductionStandard;
fcr: FCR;
total_chick_qty: number;
};
export type ProductionMetrics = {
total_depletion_qty: number;
cum_depletion_rate: number;
cum_intake: number;
fcr_value: number;
fcr_std?: number;
total_chick_qty: number;
hen_day?: number;
hen_house?: number;
feed_intake?: number;
feed_intake_std?: number;
egg_mass?: number;
egg_weight?: number;
hen_day_std?: number;
hen_house_std?: number;
egg_mass_std?: number;
egg_weight_std?: number;
daily_gain?: number;
avg_daily_gain?: number;
cum_depletion?: number;
};
export type BaseRecording = {
id: number;
project_flock_kandang_id: number;
project_flock: ProjectFlock;
record_datetime: string;
day: number;
project_flock_category?: 'GROWING' | 'LAYING';
} & ProductionMetrics;
export type RecordingDepletion = {
@@ -68,6 +86,8 @@ export type Recording = BaseMetadata &
BaseRecording & {
approval?: BaseApproval;
created_user: User;
warehouse?: Warehouse;
product_category?: 'GROWING' | 'LAYING';
depletions?: RecordingDepletion[];
stocks?: RecordingStock[];
eggs?: RecordingEgg[];