feat(FE-137): integrate Badge component to display project flock period in RecordingForm

This commit is contained in:
rstubryan
2025-10-27 12:57:00 +07:00
parent 5d376f8783
commit 6dd3593f70
@@ -34,6 +34,7 @@ import { useModal } from '@/components/Modal';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import Card from '@/components/Card'; import Card from '@/components/Card';
import Badge from '@/components/Badge';
interface RecordingFormProps { interface RecordingFormProps {
type?: 'add' | 'edit' | 'detail'; type?: 'add' | 'edit' | 'detail';
@@ -323,6 +324,36 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
[formik.values.stocks, getAvailableStock, type] [formik.values.stocks, getAvailableStock, type]
); );
const getProjectFlockBadgeAdornment = useCallback(
(projectFlockId: number) => {
if (!isResponseSuccess(projectFlocks)) return null;
const projectFlock = projectFlocks.data.find(pf => pf.id === projectFlockId);
if (!projectFlock) return null;
const isAlreadyRecorded = recordedProjectFlockIds.has(projectFlockId);
let color: 'neutral' | 'success' | 'warning' | 'error' = 'neutral';
if (isAlreadyRecorded) {
color = 'warning';
} else {
color = 'success';
}
return (
<Badge
variant="soft"
color={color}
size="sm"
className={{ badge: 'whitespace-nowrap font-semibold text-xs px-2 py-0.5' }}
>
Periode {projectFlock.period}
</Badge>
);
},
[projectFlocks, recordedProjectFlockIds]
);
const hasExceededStock = useMemo(() => { const hasExceededStock = useMemo(() => {
if (type === 'detail') return false; if (type === 'detail') return false;
return ( return (
@@ -712,6 +743,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
} }
isClearable isClearable
isSearchable isSearchable
startAdornment={
formik.values.project_flock_kandang_id
? getProjectFlockBadgeAdornment(formik.values.project_flock_kandang_id)
: undefined
}
/> />
</div> </div>
</div> </div>