mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
fix(FE-86): fixing approve button and delete button
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { min } from 'moment';
|
||||
import * as Yup from 'yup';
|
||||
|
||||
export const ProjectFlockFormSchema = Yup.object({
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
FlockApi,
|
||||
KandangApi,
|
||||
LocationApi,
|
||||
ProductCategoryApi,
|
||||
} from '@/services/api/master-data';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { useFormik } from 'formik';
|
||||
@@ -106,14 +105,6 @@ const ProjectFlockForm = ({
|
||||
FcrApi.getAllFetcher
|
||||
);
|
||||
|
||||
const productCategoryUrl = `${
|
||||
ProductCategoryApi.basePath
|
||||
}?${new URLSearchParams({
|
||||
search: '',
|
||||
}).toString()}`;
|
||||
const { data: productCategories, isLoading: isLoadingProductCategories } =
|
||||
useSWR(productCategoryUrl, ProductCategoryApi.getAllFetcher);
|
||||
|
||||
const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
|
||||
search: '',
|
||||
location_id: selectedLocation == '' ? '0' : selectedLocation,
|
||||
@@ -153,12 +144,6 @@ const ProjectFlockForm = ({
|
||||
label: flock.name,
|
||||
}))
|
||||
: [];
|
||||
const optionsProductCategory = isResponseSuccess(productCategories)
|
||||
? productCategories?.data.map((productCategory) => ({
|
||||
value: productCategory.id,
|
||||
label: productCategory.name,
|
||||
}))
|
||||
: [];
|
||||
|
||||
useEffect(() => {
|
||||
if (isResponseSuccess(locations)) {
|
||||
@@ -168,7 +153,7 @@ const ProjectFlockForm = ({
|
||||
}));
|
||||
setOptionsLocation(options);
|
||||
}
|
||||
}, [locations]);
|
||||
}, [locations, setSelectedLocation]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isResponseSuccess(kandang)) {
|
||||
@@ -327,11 +312,16 @@ const ProjectFlockForm = ({
|
||||
: null,
|
||||
flock_id: initialValues?.flock?.id ?? 0,
|
||||
area_id: initialValues?.area?.id ?? 0,
|
||||
category: initialValues?.category as (NonNullable<"GROWING" | "LAYING" | undefined>),
|
||||
category: initialValues?.category as NonNullable<
|
||||
'GROWING' | 'LAYING' | undefined
|
||||
>,
|
||||
fcr_id: initialValues?.fcr?.id ?? 0,
|
||||
location_id: initialValues?.location?.id ?? 0,
|
||||
period: initialValues?.period ?? 0,
|
||||
kandang_ids: initialValues?.kandangs?.map((k: Kandang) => k.id) as (number | undefined)[],
|
||||
kandang_ids: initialValues?.kandangs?.map((k: Kandang) => k.id) as (
|
||||
| number
|
||||
| undefined
|
||||
)[],
|
||||
};
|
||||
}, [initialValues]);
|
||||
|
||||
@@ -378,16 +368,18 @@ const ProjectFlockForm = ({
|
||||
label: initialValues?.area.name,
|
||||
});
|
||||
formik.setFieldValue('area_id', initialValues?.area_id);
|
||||
if(initialValues?.area_id){
|
||||
if (initialValues?.area_id) {
|
||||
setSelectedArea(initialValues?.area_id.toString() as string);
|
||||
}
|
||||
|
||||
formik.setFieldValue('period', initialValues?.period);
|
||||
}
|
||||
}, [initialValues, setSelectedArea, formType]);
|
||||
|
||||
useEffect(() => {
|
||||
formikSetValues(formikInitialValues);
|
||||
}, [formikSetValues, formikInitialValues, formik]);
|
||||
}, [formikSetValues, formikInitialValues]);
|
||||
|
||||
// Aktifkan lokasi jika formType = 'detail'
|
||||
useEffect(() => {
|
||||
if (formType === 'detail') {
|
||||
@@ -408,9 +400,9 @@ const ProjectFlockForm = ({
|
||||
}, [formik.values]);
|
||||
|
||||
useEffect(() => {
|
||||
isResponseSuccess(periodFlocks)
|
||||
? formik.setFieldValue('period', periodFlocks.data.next_period)
|
||||
: formik.setFieldValue('period', '');
|
||||
if(isResponseSuccess(periodFlocks)){
|
||||
formik.setFieldValue('period', periodFlocks.data.next_period);
|
||||
}
|
||||
}, [periodFlocks]);
|
||||
|
||||
// Actions handler
|
||||
@@ -488,22 +480,24 @@ const ProjectFlockForm = ({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className='w-full py-4'>
|
||||
<Button
|
||||
variant='outline'
|
||||
color='success'
|
||||
onClick={() => {
|
||||
if (initialValues?.id) {
|
||||
confirmModal.openModal();
|
||||
}
|
||||
}}
|
||||
disabled={!initialValues?.id}
|
||||
className='w-full sm:w-fit'
|
||||
>
|
||||
<Icon icon='material-symbols:check' width={24} height={24} />
|
||||
Approve
|
||||
</Button>
|
||||
</div>
|
||||
{formType == 'detail' && (
|
||||
<div className='w-full py-4'>
|
||||
<Button
|
||||
variant='outline'
|
||||
color='success'
|
||||
onClick={() => {
|
||||
if (initialValues?.id) {
|
||||
confirmModal.openModal();
|
||||
}
|
||||
}}
|
||||
disabled={!initialValues?.id}
|
||||
className='w-full sm:w-fit'
|
||||
>
|
||||
<Icon icon='material-symbols:check' width={24} height={24} />
|
||||
Approve
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<form
|
||||
className='w-auto h-auto'
|
||||
onSubmit={formik.handleSubmit}
|
||||
@@ -511,7 +505,9 @@ const ProjectFlockForm = ({
|
||||
>
|
||||
<div className='card bg-base-100 shadow w-full mb-6'>
|
||||
<div className='card-body'>
|
||||
<div className='card-title mb-4'>Informasi Umum {formik.values.kandang_ids && formik.values.kandang_ids.join(', ')}</div>
|
||||
<div className='card-title mb-4'>
|
||||
Informasi Umum
|
||||
</div>
|
||||
|
||||
<div className='grid sm:grid-cols-2 gap-4'>
|
||||
<SelectInput
|
||||
@@ -603,6 +599,7 @@ const ProjectFlockForm = ({
|
||||
errorMessage={formik.errors.period as string}
|
||||
readOnly={formType === 'detail'}
|
||||
disabled={true}
|
||||
isLoading={isLoadingPeriodFlocks}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -633,6 +630,9 @@ const ProjectFlockForm = ({
|
||||
open={openSelectKandangs}
|
||||
>
|
||||
<div className='overflow-x-auto'>
|
||||
{isLoadingKandang && (
|
||||
<span className="loading loading-dots loading-xl"></span>
|
||||
)}
|
||||
<table className='table'>
|
||||
{/* head */}
|
||||
<thead>
|
||||
@@ -756,24 +756,26 @@ const ProjectFlockForm = ({
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
<div className='w-full'>
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (initialValues?.id) {
|
||||
deleteModal.openModal();
|
||||
}
|
||||
}}
|
||||
color='error'
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:delete-outline-rounded'
|
||||
width={16}
|
||||
height={16}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
{formType != 'add' && (
|
||||
<div className='w-full'>
|
||||
<Button
|
||||
onClick={() => {
|
||||
if (initialValues?.id) {
|
||||
deleteModal.openModal();
|
||||
}
|
||||
}}
|
||||
color='error'
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:delete-outline-rounded'
|
||||
width={16}
|
||||
height={16}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<ConfirmationModal
|
||||
|
||||
Reference in New Issue
Block a user