mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
feat(FE-170,174,175): add tooltip for grading button based on consumable eggs validation
This commit is contained in:
@@ -15,6 +15,7 @@ import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
|||||||
import CheckboxInput from '@/components/input/CheckboxInput';
|
import CheckboxInput from '@/components/input/CheckboxInput';
|
||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
import { useModal } from '@/components/Modal';
|
import { useModal } from '@/components/Modal';
|
||||||
|
import Tooltip from '@/components/Tooltip';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ProjectFlockKandangApi,
|
ProjectFlockKandangApi,
|
||||||
@@ -950,6 +951,54 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
);
|
);
|
||||||
}, [formik.values.stocks, getStockUsageError, type]);
|
}, [formik.values.stocks, getStockUsageError, type]);
|
||||||
|
|
||||||
|
const hasConsumableEggs = useMemo(() => {
|
||||||
|
if (!isLayingCategory) return false;
|
||||||
|
const layingValues = formik.values as RecordingLayingFormValues;
|
||||||
|
if (!layingValues.eggs || layingValues.eggs.length === 0) return false;
|
||||||
|
|
||||||
|
return layingValues.eggs.some((egg) => {
|
||||||
|
if (!egg.product_warehouse_id || Number(egg.qty) <= 0) return false;
|
||||||
|
|
||||||
|
const product = eggProducts.find(
|
||||||
|
(opt) => opt.value === egg.product_warehouse_id
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!product) return false;
|
||||||
|
|
||||||
|
const productName = product.label.toLowerCase();
|
||||||
|
return (
|
||||||
|
productName.includes('konsumsi') &&
|
||||||
|
productName.includes('baik') &&
|
||||||
|
Number(egg.qty) > 0
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}, [isLayingCategory, formik.values, eggProducts]);
|
||||||
|
|
||||||
|
const hasConsumableEggsInRecording = useCallback((recording?: Recording) => {
|
||||||
|
if (!recording || !recording.eggs || recording.eggs.length === 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return recording.eggs.some((egg) => {
|
||||||
|
if (!egg.product_warehouse || !egg.product_warehouse.product)
|
||||||
|
return false;
|
||||||
|
if (Number(egg.qty) <= 0) return false;
|
||||||
|
|
||||||
|
const productName = egg.product_warehouse.product.name.toLowerCase();
|
||||||
|
return (
|
||||||
|
productName.includes('konsumsi') &&
|
||||||
|
productName.includes('baik') &&
|
||||||
|
Number(egg.qty) > 0
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const hasConsumableEggsInCurrentRecording = useMemo(() => {
|
||||||
|
return (
|
||||||
|
hasConsumableEggsInRecording(initialValues) ||
|
||||||
|
hasConsumableEggsInRecording(newRecordingData || undefined)
|
||||||
|
);
|
||||||
|
}, [initialValues, newRecordingData, hasConsumableEggsInRecording]);
|
||||||
|
|
||||||
const isRepeaterInputError = (
|
const isRepeaterInputError = (
|
||||||
arrayName: 'body_weights' | 'stocks' | 'depletions' | 'eggs',
|
arrayName: 'body_weights' | 'stocks' | 'depletions' | 'eggs',
|
||||||
column: string,
|
column: string,
|
||||||
@@ -2606,29 +2655,42 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
</div>
|
</div>
|
||||||
<div className='flex flex-row justify-end gap-2'>
|
<div className='flex flex-row justify-end gap-2'>
|
||||||
{type === 'detail' && isLayingCategory && (
|
{type === 'detail' && isLayingCategory && (
|
||||||
<Button
|
<Tooltip
|
||||||
type='button'
|
content={
|
||||||
color='primary'
|
hasConsumableEggsInCurrentRecording
|
||||||
onClick={() => {
|
? 'Lanjut ke proses grading untuk telur konsumsi baik'
|
||||||
const recordingId =
|
: 'Hanya bisa melanjutkan ke grading jika ada Telur Konsumsi Baik'
|
||||||
newRecordingData?.id || initialValues?.id;
|
}
|
||||||
if (recordingId) {
|
position='top'
|
||||||
router.push(
|
color={
|
||||||
`/production/recording/grading/add?recording_id=${recordingId}`
|
hasConsumableEggsInCurrentRecording ? 'info' : 'warning'
|
||||||
);
|
}
|
||||||
} else {
|
|
||||||
toast.error(
|
|
||||||
'Recording ID tidak ditemukan. Silakan refresh halaman.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Icon icon='material-symbols:egg' width={24} height={24} />
|
<Button
|
||||||
{hasGradingData(initialValues) ||
|
type='button'
|
||||||
hasGradingData(newRecordingData || undefined)
|
color='primary'
|
||||||
? 'Edit Grading'
|
disabled={!hasConsumableEggsInCurrentRecording}
|
||||||
: 'Lanjut ke Grading'}
|
onClick={() => {
|
||||||
</Button>
|
const recordingId =
|
||||||
|
newRecordingData?.id || initialValues?.id;
|
||||||
|
if (recordingId) {
|
||||||
|
router.push(
|
||||||
|
`/production/recording/grading/add?recording_id=${recordingId}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
toast.error(
|
||||||
|
'Recording ID tidak ditemukan. Silakan refresh halaman.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon icon='material-symbols:egg' width={24} height={24} />
|
||||||
|
{hasGradingData(initialValues) ||
|
||||||
|
hasGradingData(newRecordingData || undefined)
|
||||||
|
? 'Edit Grading'
|
||||||
|
: 'Lanjut ke Grading'}
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{type === 'edit' && (
|
{type === 'edit' && (
|
||||||
@@ -2683,66 +2745,77 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
{isLayingCategory && (
|
{isLayingCategory && (
|
||||||
<Button
|
<Tooltip
|
||||||
type='button'
|
content={
|
||||||
color='info'
|
hasConsumableEggs
|
||||||
className='px-4'
|
? 'Lanjut ke proses grading untuk telur konsumsi baik'
|
||||||
isLoading={formik.isSubmitting}
|
: 'Hanya bisa melanjutkan ke grading jika ada Telur Konsumsi Baik'
|
||||||
disabled={
|
|
||||||
hasExceededStock ||
|
|
||||||
!formik.isValid ||
|
|
||||||
formik.isSubmitting
|
|
||||||
}
|
}
|
||||||
onClick={async () => {
|
position='top'
|
||||||
if (!formik.isValid) {
|
color={hasConsumableEggs ? 'info' : 'warning'}
|
||||||
await formik.validateForm();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setRecordingFormErrorMessage('');
|
|
||||||
formik.setSubmitting(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (isLayingCategory) {
|
|
||||||
const layingValues =
|
|
||||||
formik.values as RecordingLayingFormValues;
|
|
||||||
const layingPayload =
|
|
||||||
createLayingPayload(layingValues);
|
|
||||||
|
|
||||||
const recordingData =
|
|
||||||
await createRecordingHandlerWithRedirect(
|
|
||||||
layingPayload as CreateLayingRecordingPayload,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
if (recordingData?.id) {
|
|
||||||
toast.success(
|
|
||||||
'Recording berhasil disimpan! Mengalihkan ke form Grading...'
|
|
||||||
);
|
|
||||||
setTimeout(() => {
|
|
||||||
router.push(
|
|
||||||
`/production/recording/grading/add?recording_id=${recordingData.id}`
|
|
||||||
);
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error creating recording:', error);
|
|
||||||
toast.error(
|
|
||||||
'Gagal membuat recording. Silakan coba lagi.'
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
formik.setSubmitting(false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Icon
|
<Button
|
||||||
icon='material-symbols:egg'
|
type='button'
|
||||||
width={24}
|
color='info'
|
||||||
height={24}
|
className='px-4'
|
||||||
/>
|
isLoading={formik.isSubmitting}
|
||||||
Next Step: Grading
|
disabled={
|
||||||
</Button>
|
hasExceededStock ||
|
||||||
|
!formik.isValid ||
|
||||||
|
formik.isSubmitting ||
|
||||||
|
!hasConsumableEggs
|
||||||
|
}
|
||||||
|
onClick={async () => {
|
||||||
|
if (!formik.isValid) {
|
||||||
|
await formik.validateForm();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRecordingFormErrorMessage('');
|
||||||
|
formik.setSubmitting(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isLayingCategory) {
|
||||||
|
const layingValues =
|
||||||
|
formik.values as RecordingLayingFormValues;
|
||||||
|
const layingPayload =
|
||||||
|
createLayingPayload(layingValues);
|
||||||
|
|
||||||
|
const recordingData =
|
||||||
|
await createRecordingHandlerWithRedirect(
|
||||||
|
layingPayload as CreateLayingRecordingPayload,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
if (recordingData?.id) {
|
||||||
|
toast.success(
|
||||||
|
'Recording berhasil disimpan! Mengalihkan ke form Grading...'
|
||||||
|
);
|
||||||
|
setTimeout(() => {
|
||||||
|
router.push(
|
||||||
|
`/production/recording/grading/add?recording_id=${recordingData.id}`
|
||||||
|
);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error creating recording:', error);
|
||||||
|
toast.error(
|
||||||
|
'Gagal membuat recording. Silakan coba lagi.'
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
formik.setSubmitting(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:egg'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
Next Step: Grading
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user