mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE): Add week calculation utility and improve state resets
This commit is contained in:
@@ -243,6 +243,23 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
const [isProductionStandardModalOpen, setIsProductionStandardModalOpen] =
|
const [isProductionStandardModalOpen, setIsProductionStandardModalOpen] =
|
||||||
useState(false);
|
useState(false);
|
||||||
|
|
||||||
|
const calculateWeek = useCallback(
|
||||||
|
(day: number): number => {
|
||||||
|
if (
|
||||||
|
productionStandards?.details &&
|
||||||
|
productionStandards.details.length > 0
|
||||||
|
) {
|
||||||
|
const firstWeek = productionStandards.details[0].week;
|
||||||
|
|
||||||
|
const weekOffset = Math.ceil(day / 7) - 1;
|
||||||
|
return firstWeek + weekOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.ceil(day / 7);
|
||||||
|
},
|
||||||
|
[productionStandards]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkProductionStandardModalOpen = () => {
|
const checkProductionStandardModalOpen = () => {
|
||||||
const isOpen = productionStandardModal.ref.current?.open || false;
|
const isOpen = productionStandardModal.ref.current?.open || false;
|
||||||
@@ -441,13 +458,24 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
() => ProductionStandardApi.getSingle(productionStandardId!)
|
() => ProductionStandardApi.getSingle(productionStandardId!)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { data: productionStandardForAdd } = useSWR(
|
||||||
|
type === 'add' && productionStandardId
|
||||||
|
? `production-standard-add-${productionStandardId}`
|
||||||
|
: null,
|
||||||
|
() => ProductionStandardApi.getSingle(productionStandardId!)
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (productionStandard?.status === 'success') {
|
if (productionStandard?.status === 'success') {
|
||||||
setProductionStandards(
|
setProductionStandards(
|
||||||
productionStandard.data as ProductionStandard | null
|
productionStandard.data as ProductionStandard | null
|
||||||
);
|
);
|
||||||
|
} else if (productionStandardForAdd?.status === 'success') {
|
||||||
|
setProductionStandards(
|
||||||
|
productionStandardForAdd.data as ProductionStandard | null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, [productionStandard]);
|
}, [productionStandard, productionStandardForAdd]);
|
||||||
|
|
||||||
const projectFlockKandangDetailUrl = useMemo(() => {
|
const projectFlockKandangDetailUrl = useMemo(() => {
|
||||||
if (
|
if (
|
||||||
@@ -1378,6 +1406,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
setSelectedLocation(location);
|
setSelectedLocation(location);
|
||||||
setSelectedProjectFlock(null);
|
setSelectedProjectFlock(null);
|
||||||
setSelectedKandang(null);
|
setSelectedKandang(null);
|
||||||
|
setProductionStandards(null);
|
||||||
|
setNextDayRecording(null);
|
||||||
if (duplicateErrorShown) {
|
if (duplicateErrorShown) {
|
||||||
toast.dismiss();
|
toast.dismiss();
|
||||||
setDuplicateErrorShown(false);
|
setDuplicateErrorShown(false);
|
||||||
@@ -1402,6 +1432,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
|
|
||||||
setSelectedProjectFlock(projectFlock);
|
setSelectedProjectFlock(projectFlock);
|
||||||
setSelectedKandang(null);
|
setSelectedKandang(null);
|
||||||
|
setProductionStandards(null);
|
||||||
|
setNextDayRecording(null);
|
||||||
if (duplicateErrorShown) {
|
if (duplicateErrorShown) {
|
||||||
toast.dismiss();
|
toast.dismiss();
|
||||||
setDuplicateErrorShown(false);
|
setDuplicateErrorShown(false);
|
||||||
@@ -1422,6 +1454,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
formik.setFieldValue('kandang_id', kandangId);
|
formik.setFieldValue('kandang_id', kandangId);
|
||||||
|
|
||||||
setSelectedKandang(kandang);
|
setSelectedKandang(kandang);
|
||||||
|
setProductionStandards(null);
|
||||||
|
setNextDayRecording(null);
|
||||||
if (duplicateErrorShown) {
|
if (duplicateErrorShown) {
|
||||||
toast.dismiss();
|
toast.dismiss();
|
||||||
setDuplicateErrorShown(false);
|
setDuplicateErrorShown(false);
|
||||||
@@ -1958,10 +1992,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
<p className='font-semibold'>
|
<p className='font-semibold'>
|
||||||
{type === 'add'
|
{type === 'add'
|
||||||
? nextDayRecording
|
? nextDayRecording
|
||||||
? `Hari ke-${nextDayRecording.next_day} (Minggu ke-${Math.ceil(nextDayRecording.next_day / 7)})`
|
? `Hari ke-${nextDayRecording.next_day} (Minggu ke-${calculateWeek(nextDayRecording.next_day)})`
|
||||||
: '-'
|
: '-'
|
||||||
: initialValues?.day
|
: initialValues?.day
|
||||||
? `Hari ke-${initialValues.day} (Minggu ke-${Math.ceil(initialValues.day / 7)})`
|
? `Hari ke-${initialValues.day} (Minggu ke-${calculateWeek(initialValues.day)})`
|
||||||
: '-'}
|
: '-'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user