feat(FE-170,175): add grading data handling in RecordingForm and update types

This commit is contained in:
rstubryan
2025-11-06 22:40:04 +07:00
parent 62c16bb9d1
commit c45217e98e
2 changed files with 18 additions and 2 deletions
@@ -48,7 +48,7 @@ import {
} from './RecordingForm.schema';
import { isResponseSuccess, isResponseError } from '@/lib/api-helper';
import { cn, formatDate } from '@/lib/helper';
import { formatDate } from '@/lib/helper';
import toast from 'react-hot-toast';
import StepItem from '@/components/steps/StepItem';
@@ -102,6 +102,16 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
);
}, []);
const hasGradingData = useCallback((recording?: Recording) => {
if (!recording || !recording.eggs) return false;
return recording.eggs.some(
(egg) =>
egg.gradings &&
egg.gradings.length > 0 &&
egg.gradings.some((grading) => grading.qty > 0)
);
}, []);
// ===== FORM HANDLERS =====
const createRecordingHandler = useCallback(
async (
@@ -2460,7 +2470,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}}
>
<Icon icon='material-symbols:egg' width={24} height={24} />
Lanjut ke Grading
{hasGradingData(initialValues)
? 'Edit Grading'
: 'Lanjut ke Grading'}
</Button>
)}
+4
View File
@@ -55,6 +55,10 @@ export type RecordingEgg = {
qty: number;
created_by: User;
product_warehouse: ProductWarehouse;
gradings?: {
grade: string;
qty: number;
}[];
};
export type GradingEgg = {