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:
@@ -6,7 +6,7 @@ import { cn } from '@/lib/helper';
|
|||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||||
import { use, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
import { FlockApi } from '@/services/api/master-data';
|
import { FlockApi } from '@/services/api/master-data';
|
||||||
import { useModal } from '@/components/Modal';
|
import { useModal } from '@/components/Modal';
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
||||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||||
import TextInput from '@/components/input/TextInput';
|
|
||||||
import { useModal } from '@/components/Modal';
|
import { useModal } from '@/components/Modal';
|
||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
import Table from '@/components/Table';
|
import Table from '@/components/Table';
|
||||||
@@ -22,10 +21,9 @@ import { Icon } from '@iconify/react';
|
|||||||
import {
|
import {
|
||||||
CellContext,
|
CellContext,
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
ColumnSort,
|
|
||||||
SortingState,
|
SortingState,
|
||||||
} from '@tanstack/react-table';
|
} from '@tanstack/react-table';
|
||||||
import { ChangeEventHandler, useCallback, useEffect, useState } from 'react';
|
import { ChangeEventHandler, useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
@@ -140,7 +138,6 @@ const ProjectFlockTable = () => {
|
|||||||
const {
|
const {
|
||||||
data: areas,
|
data: areas,
|
||||||
isLoading: isLoadingAreas,
|
isLoading: isLoadingAreas,
|
||||||
mutate: refreshAreas,
|
|
||||||
} = useSWR(areaUrl, AreaApi.getAllFetcher);
|
} = useSWR(areaUrl, AreaApi.getAllFetcher);
|
||||||
|
|
||||||
const locationUrl = `${LocationApi.basePath}?${new URLSearchParams({
|
const locationUrl = `${LocationApi.basePath}?${new URLSearchParams({
|
||||||
@@ -151,7 +148,6 @@ const ProjectFlockTable = () => {
|
|||||||
const {
|
const {
|
||||||
data: locations,
|
data: locations,
|
||||||
isLoading: isLoadingLocations,
|
isLoading: isLoadingLocations,
|
||||||
mutate: refreshLocations,
|
|
||||||
} = useSWR(locationUrl, LocationApi.getAllFetcher);
|
} = useSWR(locationUrl, LocationApi.getAllFetcher);
|
||||||
|
|
||||||
const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
|
const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
|
||||||
@@ -163,7 +159,6 @@ const ProjectFlockTable = () => {
|
|||||||
const {
|
const {
|
||||||
data: kandangs,
|
data: kandangs,
|
||||||
isLoading: isLoadingKandang,
|
isLoading: isLoadingKandang,
|
||||||
mutate: refreshKandang,
|
|
||||||
} = useSWR(kandangUrl, KandangApi.getAllFetcher);
|
} = useSWR(kandangUrl, KandangApi.getAllFetcher);
|
||||||
|
|
||||||
// Data to Options Mapping
|
// Data to Options Mapping
|
||||||
@@ -337,19 +332,6 @@ const ProjectFlockTable = () => {
|
|||||||
const searchChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
|
const searchChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
updateFilter('search', e.target.value);
|
updateFilter('search', e.target.value);
|
||||||
};
|
};
|
||||||
const updateSortingFilter = useCallback(
|
|
||||||
(
|
|
||||||
sortName: Exclude<keyof typeof tableFilterState, 'page' | 'pageSize'>,
|
|
||||||
sortFilter: ColumnSort | undefined
|
|
||||||
) => {
|
|
||||||
if (!sortFilter) {
|
|
||||||
updateFilter(sortName, '');
|
|
||||||
} else {
|
|
||||||
updateFilter(sortName, sortFilter.desc ? 'desc' : 'asc');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[updateFilter]
|
|
||||||
);
|
|
||||||
const handleSelectAll = (checked: boolean) => {
|
const handleSelectAll = (checked: boolean) => {
|
||||||
if (checked && isResponseSuccess(projectFlocks)) {
|
if (checked && isResponseSuccess(projectFlocks)) {
|
||||||
const allIds = projectFlocks.data.map((item) => item.id);
|
const allIds = projectFlocks.data.map((item) => item.id);
|
||||||
@@ -458,6 +440,7 @@ const ProjectFlockTable = () => {
|
|||||||
(val as OptionType)?.value.toString()
|
(val as OptionType)?.value.toString()
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
onInputChange={setAreaSelectInputValue}
|
||||||
isClearable
|
isClearable
|
||||||
/>
|
/>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
@@ -472,6 +455,7 @@ const ProjectFlockTable = () => {
|
|||||||
(val as OptionType)?.value.toString()
|
(val as OptionType)?.value.toString()
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
onInputChange={setLocationSelectInputValue}
|
||||||
isClearable
|
isClearable
|
||||||
/>
|
/>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
@@ -486,6 +470,7 @@ const ProjectFlockTable = () => {
|
|||||||
(val as OptionType)?.value.toString()
|
(val as OptionType)?.value.toString()
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
onInputChange={setKandangSelectInputValue}
|
||||||
isClearable
|
isClearable
|
||||||
/>
|
/>
|
||||||
<DebouncedTextInput
|
<DebouncedTextInput
|
||||||
@@ -569,7 +554,7 @@ const ProjectFlockTable = () => {
|
|||||||
selectedFlocks.length > 0
|
selectedFlocks.length > 0
|
||||||
? `Apakah anda yakin ingin approve Project Flock berikut? (${selectedFlocks
|
? `Apakah anda yakin ingin approve Project Flock berikut? (${selectedFlocks
|
||||||
.map(
|
.map(
|
||||||
(flock, index) =>
|
(flock) =>
|
||||||
`${flock.flock?.name ?? '(Tanpa nama)'} - ${
|
`${flock.flock?.name ?? '(Tanpa nama)'} - ${
|
||||||
flock.area?.name ?? '-'
|
flock.area?.name ?? '-'
|
||||||
}`
|
}`
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { min } from 'moment';
|
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
export const ProjectFlockFormSchema = Yup.object({
|
export const ProjectFlockFormSchema = Yup.object({
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
FlockApi,
|
FlockApi,
|
||||||
KandangApi,
|
KandangApi,
|
||||||
LocationApi,
|
LocationApi,
|
||||||
ProductCategoryApi,
|
|
||||||
} from '@/services/api/master-data';
|
} from '@/services/api/master-data';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
@@ -106,14 +105,6 @@ const ProjectFlockForm = ({
|
|||||||
FcrApi.getAllFetcher
|
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({
|
const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
|
||||||
search: '',
|
search: '',
|
||||||
location_id: selectedLocation == '' ? '0' : selectedLocation,
|
location_id: selectedLocation == '' ? '0' : selectedLocation,
|
||||||
@@ -153,12 +144,6 @@ const ProjectFlockForm = ({
|
|||||||
label: flock.name,
|
label: flock.name,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
const optionsProductCategory = isResponseSuccess(productCategories)
|
|
||||||
? productCategories?.data.map((productCategory) => ({
|
|
||||||
value: productCategory.id,
|
|
||||||
label: productCategory.name,
|
|
||||||
}))
|
|
||||||
: [];
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isResponseSuccess(locations)) {
|
if (isResponseSuccess(locations)) {
|
||||||
@@ -168,7 +153,7 @@ const ProjectFlockForm = ({
|
|||||||
}));
|
}));
|
||||||
setOptionsLocation(options);
|
setOptionsLocation(options);
|
||||||
}
|
}
|
||||||
}, [locations]);
|
}, [locations, setSelectedLocation]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isResponseSuccess(kandang)) {
|
if (isResponseSuccess(kandang)) {
|
||||||
@@ -327,11 +312,16 @@ const ProjectFlockForm = ({
|
|||||||
: null,
|
: null,
|
||||||
flock_id: initialValues?.flock?.id ?? 0,
|
flock_id: initialValues?.flock?.id ?? 0,
|
||||||
area_id: initialValues?.area?.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,
|
fcr_id: initialValues?.fcr?.id ?? 0,
|
||||||
location_id: initialValues?.location?.id ?? 0,
|
location_id: initialValues?.location?.id ?? 0,
|
||||||
period: initialValues?.period ?? 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]);
|
}, [initialValues]);
|
||||||
|
|
||||||
@@ -378,16 +368,18 @@ const ProjectFlockForm = ({
|
|||||||
label: initialValues?.area.name,
|
label: initialValues?.area.name,
|
||||||
});
|
});
|
||||||
formik.setFieldValue('area_id', initialValues?.area_id);
|
formik.setFieldValue('area_id', initialValues?.area_id);
|
||||||
if(initialValues?.area_id){
|
if (initialValues?.area_id) {
|
||||||
setSelectedArea(initialValues?.area_id.toString() as string);
|
setSelectedArea(initialValues?.area_id.toString() as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
formik.setFieldValue('period', initialValues?.period);
|
formik.setFieldValue('period', initialValues?.period);
|
||||||
}
|
}
|
||||||
}, [initialValues, setSelectedArea, formType]);
|
}, [initialValues, setSelectedArea, formType]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
formikSetValues(formikInitialValues);
|
formikSetValues(formikInitialValues);
|
||||||
}, [formikSetValues, formikInitialValues, formik]);
|
}, [formikSetValues, formikInitialValues]);
|
||||||
|
|
||||||
// Aktifkan lokasi jika formType = 'detail'
|
// Aktifkan lokasi jika formType = 'detail'
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (formType === 'detail') {
|
if (formType === 'detail') {
|
||||||
@@ -408,9 +400,9 @@ const ProjectFlockForm = ({
|
|||||||
}, [formik.values]);
|
}, [formik.values]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isResponseSuccess(periodFlocks)
|
if(isResponseSuccess(periodFlocks)){
|
||||||
? formik.setFieldValue('period', periodFlocks.data.next_period)
|
formik.setFieldValue('period', periodFlocks.data.next_period);
|
||||||
: formik.setFieldValue('period', '');
|
}
|
||||||
}, [periodFlocks]);
|
}, [periodFlocks]);
|
||||||
|
|
||||||
// Actions handler
|
// Actions handler
|
||||||
@@ -488,6 +480,7 @@ const ProjectFlockForm = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{formType == 'detail' && (
|
||||||
<div className='w-full py-4'>
|
<div className='w-full py-4'>
|
||||||
<Button
|
<Button
|
||||||
variant='outline'
|
variant='outline'
|
||||||
@@ -504,6 +497,7 @@ const ProjectFlockForm = ({
|
|||||||
Approve
|
Approve
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
<form
|
<form
|
||||||
className='w-auto h-auto'
|
className='w-auto h-auto'
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
@@ -511,7 +505,9 @@ const ProjectFlockForm = ({
|
|||||||
>
|
>
|
||||||
<div className='card bg-base-100 shadow w-full mb-6'>
|
<div className='card bg-base-100 shadow w-full mb-6'>
|
||||||
<div className='card-body'>
|
<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'>
|
<div className='grid sm:grid-cols-2 gap-4'>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
@@ -603,6 +599,7 @@ const ProjectFlockForm = ({
|
|||||||
errorMessage={formik.errors.period as string}
|
errorMessage={formik.errors.period as string}
|
||||||
readOnly={formType === 'detail'}
|
readOnly={formType === 'detail'}
|
||||||
disabled={true}
|
disabled={true}
|
||||||
|
isLoading={isLoadingPeriodFlocks}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -633,6 +630,9 @@ const ProjectFlockForm = ({
|
|||||||
open={openSelectKandangs}
|
open={openSelectKandangs}
|
||||||
>
|
>
|
||||||
<div className='overflow-x-auto'>
|
<div className='overflow-x-auto'>
|
||||||
|
{isLoadingKandang && (
|
||||||
|
<span className="loading loading-dots loading-xl"></span>
|
||||||
|
)}
|
||||||
<table className='table'>
|
<table className='table'>
|
||||||
{/* head */}
|
{/* head */}
|
||||||
<thead>
|
<thead>
|
||||||
@@ -756,6 +756,7 @@ const ProjectFlockForm = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{formType != 'add' && (
|
||||||
<div className='w-full'>
|
<div className='w-full'>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -774,6 +775,7 @@ const ProjectFlockForm = ({
|
|||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<ConfirmationModal
|
<ConfirmationModal
|
||||||
|
|||||||
Reference in New Issue
Block a user