mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-114,136): update flock references to use ProjectFlock and adjust RecordingForm for new API
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
|||||||
UpdateRecordingFormSchema,
|
UpdateRecordingFormSchema,
|
||||||
} from './RecordingForm.schema';
|
} from './RecordingForm.schema';
|
||||||
import { useRecordingFormHandlers } from './useRecordingFormHandlers';
|
import { useRecordingFormHandlers } from './useRecordingFormHandlers';
|
||||||
import { FlockApi } from '@/services/api/flock';
|
import { ProjectFlockApi } from '@/services/api/production';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { RECORDING_FLAG_OPTIONS } from '@/config/constant';
|
import { RECORDING_FLAG_OPTIONS } from '@/config/constant';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
@@ -29,15 +29,10 @@ interface RecordingFormProps {
|
|||||||
initialValues?: Recording;
|
initialValues?: Recording;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DUMMY_FLOCKS = [
|
|
||||||
{ value: 1, label: 'Flock A' },
|
|
||||||
{ value: 2, label: 'Flock B' },
|
|
||||||
{ value: 3, label: 'Flock C' },
|
|
||||||
{ value: 4, label: 'Flock D' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||||
const [flockSelectInputValue, setFlockSelectInputValue] = useState('');
|
const [flockSelectInputValue, setFlockSelectInputValue] = useState('');
|
||||||
|
const [locationSelectInputValue, setLocationSelectInputValue] = useState('');
|
||||||
|
const [coopSelectInputValue, setCoopSelectInputValue] = useState('');
|
||||||
const [selectedFeed, setSelectedFeed] = useState<number[]>([]);
|
const [selectedFeed, setSelectedFeed] = useState<number[]>([]);
|
||||||
const [selectedWeight, setSelectedWeight] = useState<number[]>([]);
|
const [selectedWeight, setSelectedWeight] = useState<number[]>([]);
|
||||||
const [selectedVaccine, setSelectedVaccine] = useState<number[]>([]);
|
const [selectedVaccine, setSelectedVaccine] = useState<number[]>([]);
|
||||||
@@ -107,20 +102,20 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// // Flock selection
|
// Flock selection
|
||||||
// const flocksUrl = `${FlockApi.basePath}?${new URLSearchParams({ search: flockSelectInputValue }).toString()}`;
|
const projectFlocksUrl = `${ProjectFlockApi.basePath}?${new URLSearchParams({ search: flockSelectInputValue }).toString()}`;
|
||||||
// const { data: flocks, isLoading: isLoadingFlocks } = useSWR(
|
const { data: projectFlocks, isLoading: isLoadingFlocks } = useSWR(
|
||||||
// flocksUrl,
|
projectFlocksUrl,
|
||||||
// FlockApi.getAllFetcher
|
ProjectFlockApi.getAllFetcher
|
||||||
// );
|
);
|
||||||
// const flockOptions = isResponseSuccess(flocks)
|
const flockOptions = isResponseSuccess(projectFlocks)
|
||||||
// ? flocks?.data.map((f) => ({ value: f.id, label: f.name }))
|
? projectFlocks?.data.map((flock) => ({
|
||||||
// : [];
|
value: flock.id,
|
||||||
|
label: flock.flock.name,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
|
||||||
const flockOptions = DUMMY_FLOCKS;
|
// Pakan selection
|
||||||
|
|
||||||
const [locationSelectInputValue, setLocationSelectInputValue] = useState('');
|
|
||||||
const [coopSelectInputValue, setCoopSelectInputValue] = useState('');
|
|
||||||
|
|
||||||
const locationsUrl = `${LocationApi.basePath}?${new URLSearchParams({ search: locationSelectInputValue ?? '' }).toString()}`;
|
const locationsUrl = `${LocationApi.basePath}?${new URLSearchParams({ search: locationSelectInputValue ?? '' }).toString()}`;
|
||||||
const { data: locations, isLoading: isLoadingLocations } = useSWR(
|
const { data: locations, isLoading: isLoadingLocations } = useSWR(
|
||||||
@@ -366,7 +361,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
onChange={flockChangeHandler}
|
onChange={flockChangeHandler}
|
||||||
options={flockOptions}
|
options={flockOptions}
|
||||||
onInputChange={setFlockSelectInputValue}
|
onInputChange={setFlockSelectInputValue}
|
||||||
isLoading={false}
|
isLoading={isLoadingFlocks}
|
||||||
isError={
|
isError={
|
||||||
formik.touched.flock_id && Boolean(formik.errors.flock_id)
|
formik.touched.flock_id && Boolean(formik.errors.flock_id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
CreateFlockPayload,
|
CreateFlockPayload,
|
||||||
Flock,
|
Flock,
|
||||||
UpdateFlockPayload,
|
UpdateFlockPayload,
|
||||||
} from '@/types/api/flock/flock';
|
} from '@/types/api/master-data/flock';
|
||||||
import {
|
import {
|
||||||
CreateRecordingPayload,
|
CreateRecordingPayload,
|
||||||
Recording,
|
Recording,
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { BaseApiService } from './base';
|
||||||
|
import {
|
||||||
|
CreateProjectFlockPayload,
|
||||||
|
ProjectFlock,
|
||||||
|
UpdateProjectFlockPayload,
|
||||||
|
} from '@/types/api/production/project-flock';
|
||||||
|
|
||||||
|
export const ProjectFlockApi = new BaseApiService<
|
||||||
|
ProjectFlock,
|
||||||
|
CreateProjectFlockPayload,
|
||||||
|
UpdateProjectFlockPayload
|
||||||
|
>('/production/project_flocks');
|
||||||
Vendored
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
import { BaseMetadata } from '@/types/api/api-general';
|
import { BaseMetadata } from '@/types/api/api-general';
|
||||||
import { Flock } from '@/types/api/flock/flock';
|
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||||
import { Location } from '@/types/api/master-data/location';
|
import { Location } from '@/types/api/master-data/location';
|
||||||
import { Kandang } from '@/types/api/master-data/kandang';
|
import { Kandang } from '@/types/api/master-data/kandang';
|
||||||
|
|
||||||
export type BaseRecording = {
|
export type BaseRecording = {
|
||||||
id: number;
|
id: number;
|
||||||
flock: Flock;
|
flock: ProjectFlock;
|
||||||
recording_date: string;
|
recording_date: string;
|
||||||
location: Location;
|
location: Location;
|
||||||
coop: Kandang;
|
coop: Kandang;
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
import { Flock } from '@/types/api/master-data/flock';
|
||||||
|
import { Area } from '@/types/api/master-data/area';
|
||||||
|
import { ProductCategory } from '@/types/api/master-data/product-category';
|
||||||
|
import { Fcr } from '@/types/api/master-data/fcr';
|
||||||
|
import { Kandang } from '@/types/api/master-data/kandang';
|
||||||
|
import { BaseMetadata } from '@/types/api/api-general';
|
||||||
|
|
||||||
|
export type BaseProjectFlock = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
flock: Flock;
|
||||||
|
flock_id: number;
|
||||||
|
area: Area;
|
||||||
|
area_id: number;
|
||||||
|
product_category: ProductCategory;
|
||||||
|
product_category_id: number;
|
||||||
|
fcr: Fcr;
|
||||||
|
fcr_id: number;
|
||||||
|
location: Location;
|
||||||
|
location_id: number;
|
||||||
|
period: number;
|
||||||
|
kandang_ids: number[];
|
||||||
|
kandangs: Kandang[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ProjectFlock = BaseMetadata & BaseProjectFlock;
|
||||||
|
|
||||||
|
export type CreateProjectFlockPayload = {
|
||||||
|
name: string;
|
||||||
|
flock_id: number;
|
||||||
|
area_id: number;
|
||||||
|
product_category_id: number;
|
||||||
|
fcr_id: number;
|
||||||
|
location_id: number;
|
||||||
|
period: number;
|
||||||
|
kandang_ids: number[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UpdateProjectFlockPayload = CreateProjectFlockPayload;
|
||||||
Reference in New Issue
Block a user