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