mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
feat(84-85-86-87-88-89-102): create feature project flocks and adjust master data flock feature
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
@plugin "daisyui";
|
@plugin "daisyui";
|
||||||
|
|
||||||
@plugin "daisyui/theme" {
|
@plugin "daisyui/theme" {
|
||||||
name: "corporate";
|
name: "lti";
|
||||||
default: false;
|
default: false;
|
||||||
prefersdark: false;
|
prefersdark: false;
|
||||||
color-scheme: "light";
|
color-scheme: "light";
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
import FlockForm from "@/components/pages/master-data/flock/form/FlockForm";
|
import FlockForm from "@/components/pages/master-data/flock/form/FlockForm";
|
||||||
import { isResponseError, isResponseSuccess } from "@/lib/api-helper";
|
import { isResponseError, isResponseSuccess } from "@/lib/api-helper";
|
||||||
import { FlockApi } from "@/services/api/master-data";
|
import { FlockApi } from "@/services/api/master-data";
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
import FlockForm from "@/components/pages/master-data/flock/form/FlockForm";
|
import FlockForm from "@/components/pages/master-data/flock/form/FlockForm";
|
||||||
import { isResponseError, isResponseSuccess } from "@/lib/api-helper";
|
import { isResponseError, isResponseSuccess } from "@/lib/api-helper";
|
||||||
import { FlockApi } from "@/services/api/master-data";
|
import { FlockApi } from "@/services/api/master-data";
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import ProjectFlockForm from "@/components/pages/production/project-flock/form/ProjectFlockForm";
|
||||||
|
|
||||||
|
const AddProjectFlock = () => {
|
||||||
|
return (
|
||||||
|
<section className="w-full p-4 flex flex-row justify-center">
|
||||||
|
<ProjectFlockForm formType="add"/>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AddProjectFlock;
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
|
||||||
|
import ProjectFlockForm from "@/components/pages/production/project-flock/form/ProjectFlockForm";
|
||||||
|
import { isResponseError, isResponseSuccess } from "@/lib/api-helper";
|
||||||
|
import { ProjectFlockApi } from "@/services/api/production";
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
|
import useSWR from "swr";
|
||||||
|
|
||||||
|
const ProjectFlockDetail = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const projectFlockId = searchParams.get("projectFlockId");
|
||||||
|
|
||||||
|
const { data: projectFlock, isLoading: isLoadingCostumer } = useSWR(
|
||||||
|
projectFlockId,
|
||||||
|
(id: number) => ProjectFlockApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!projectFlockId){
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full flex flex-row justify-center items-center p-4">
|
||||||
|
<span className="loading loading-spinner loading-xl" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isLoadingCostumer && (!projectFlock || isResponseError(projectFlock))){
|
||||||
|
router.replace("/404");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full p-4 flex flex-row justify-center">
|
||||||
|
{isLoadingCostumer && <span className="loading loading-spinner loading-xl" />}
|
||||||
|
{!isLoadingCostumer && isResponseSuccess(projectFlock) && (
|
||||||
|
<ProjectFlockForm formType="detail" initialValues={projectFlock.data} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProjectFlockDetail;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import ProjectFlockForm from "@/components/pages/production/project-flock/form/ProjectFlockForm"
|
||||||
|
import ProjectFlockTable from "@/components/pages/production/project-flock/ProjectFlockTable";
|
||||||
|
|
||||||
|
const ProjectFlock = () => {
|
||||||
|
return (
|
||||||
|
<section className="w-full p-4">
|
||||||
|
<ProjectFlockTable/>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProjectFlock;
|
||||||
@@ -41,7 +41,7 @@ const RowsOptions = ({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
href={`/master-data/flock/edit/?flockId=${props.row.original.id}`}
|
href={`/master-data/flock/detail/edit/?flockId=${props.row.original.id}`}
|
||||||
variant='ghost'
|
variant='ghost'
|
||||||
color='warning'
|
color='warning'
|
||||||
className='justify-start text-sm'
|
className='justify-start text-sm'
|
||||||
@@ -53,6 +53,20 @@ const RowsOptions = ({
|
|||||||
className='justify-start text-sm'
|
className='justify-start text-sm'
|
||||||
/>
|
/>
|
||||||
Edit
|
Edit
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
href={`/master-data/flock/detail/?flockId=${props.row.original.id}`}
|
||||||
|
variant='ghost'
|
||||||
|
color='primary'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='mdi:eye-outline'
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
className='justify-start text-sm'
|
||||||
|
/>
|
||||||
|
Detail
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={deleteClickHandler}
|
onClick={deleteClickHandler}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ export const FlockFormSchema = Yup.object({
|
|||||||
name: Yup.string()
|
name: Yup.string()
|
||||||
.required('Nama wajib diisi!')
|
.required('Nama wajib diisi!')
|
||||||
.matches(
|
.matches(
|
||||||
/^[a-zA-Z0-9]+$/,
|
/^[\p{L}\p{N}\s]+$/u,
|
||||||
'Nama hanya boleh berisi huruf dan angka (tanpa spasi atau simbol)'
|
'Nama tidak boleh mengandung simbol'
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ const FlockForm = ({ formType = 'add', initialValues }: FlockCustomProps) => {
|
|||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
color='warning'
|
color='warning'
|
||||||
href={`/master-data/flock/edit/?flockId=${initialValues?.id}`}
|
href={`/master-data/flock/detail/edit/?flockId=${initialValues?.id}`}
|
||||||
className='px-4'
|
className='px-4'
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
|
|||||||
@@ -0,0 +1,312 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||||
|
import { useModal } from '@/components/Modal';
|
||||||
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
|
import Table from '@/components/Table';
|
||||||
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
|
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||||
|
import { ROWS_OPTIONS } from '@/config/constant';
|
||||||
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import { cn } from '@/lib/helper';
|
||||||
|
import { ProjectFlockApi } from '@/services/api/production';
|
||||||
|
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||||
|
import { Kandang } from '@/types/api/master-data/kandang';
|
||||||
|
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import {
|
||||||
|
CellContext,
|
||||||
|
ColumnDef,
|
||||||
|
ColumnSort,
|
||||||
|
SortingState,
|
||||||
|
} from '@tanstack/react-table';
|
||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
const RowOptionsMenu = ({
|
||||||
|
type = 'dropdown',
|
||||||
|
props,
|
||||||
|
deleteClickHandler,
|
||||||
|
}: {
|
||||||
|
type: 'dropdown' | 'collapse';
|
||||||
|
props: CellContext<ProjectFlock, unknown>;
|
||||||
|
deleteClickHandler: () => void;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
tabIndex={type == 'dropdown' ? 0 : undefined}
|
||||||
|
className={cn(
|
||||||
|
{
|
||||||
|
'dropdown-content': type === 'dropdown',
|
||||||
|
'mt-2': type === 'collapse',
|
||||||
|
},
|
||||||
|
'p-2.5 mr-2 flex flex-col gap-1 bg-base-100 rounded-box z-10 border border-black/10 shadow'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
href={`/production/project-flock/detail?projectFlockId=${props.row.original.id}`}
|
||||||
|
variant='ghost'
|
||||||
|
color='primary'
|
||||||
|
className='justify-start text-sm'
|
||||||
|
>
|
||||||
|
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||||
|
Detail
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={deleteClickHandler}
|
||||||
|
variant='ghost'
|
||||||
|
color='error'
|
||||||
|
className='text-error hover:text-inherit'
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:delete-outline-rounded'
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
className='justify-start text-sm'
|
||||||
|
/>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ProjectFlockTable = () => {
|
||||||
|
const {
|
||||||
|
state: tableFilterState,
|
||||||
|
updateFilter,
|
||||||
|
setPage,
|
||||||
|
setPageSize,
|
||||||
|
toQueryString: getTableFilterQueryString,
|
||||||
|
} = useTableFilter({
|
||||||
|
initial: {
|
||||||
|
search: '',
|
||||||
|
},
|
||||||
|
paramMap: {
|
||||||
|
page: 'page',
|
||||||
|
pageSize: 'limit',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch Data
|
||||||
|
const {
|
||||||
|
data: projectFlocks,
|
||||||
|
isLoading,
|
||||||
|
mutate: refreshProjectFlocks,
|
||||||
|
} = useSWR(
|
||||||
|
`${ProjectFlockApi.basePath}${getTableFilterQueryString()}`,
|
||||||
|
ProjectFlockApi.getAllFetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
// State
|
||||||
|
const [sorting, setSorting] = useState<SortingState>([]);
|
||||||
|
const [selectedProjectFlock, setSelectedProjectFlock] =
|
||||||
|
useState<ProjectFlock>();
|
||||||
|
const deleteModal = useModal();
|
||||||
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
|
|
||||||
|
// Columns
|
||||||
|
const projectFlocksColumns: ColumnDef<ProjectFlock>[] = [
|
||||||
|
{
|
||||||
|
header: '#',
|
||||||
|
cell: (props) =>
|
||||||
|
tableFilterState.pageSize * (tableFilterState.page - 1) +
|
||||||
|
props.row.index +
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'flock.name',
|
||||||
|
header: 'Flock',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'area.name',
|
||||||
|
header: 'Area',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'location.name',
|
||||||
|
header: 'Lokasi',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'fcr.name',
|
||||||
|
header: 'FCR',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'product_category.name',
|
||||||
|
header: 'Kategori Produk',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Kandang',
|
||||||
|
cell: (props) => {
|
||||||
|
const kandang = props.row.original.kandangs;
|
||||||
|
const kandangNames = kandang.map((k: Kandang) => k.name);
|
||||||
|
console.log('kandang');
|
||||||
|
console.log(kandang);
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{kandangNames.length > 0 ? kandangNames.join(', ') : 'Tidak ada'}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'period',
|
||||||
|
header: 'Periode',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'created_at',
|
||||||
|
header: 'Dibuat pada',
|
||||||
|
cell: (props) =>
|
||||||
|
new Date(props.row.original.created_at).toLocaleDateString(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Aksi',
|
||||||
|
cell: (props) => {
|
||||||
|
const currentPageSize = props.table.getPaginationRowModel().rows.length;
|
||||||
|
const currentPageRows = props.table.getPaginationRowModel().flatRows;
|
||||||
|
const currentRowRelativeIndex =
|
||||||
|
currentPageRows.findIndex((r) => r.id === props.row.id) + 1;
|
||||||
|
|
||||||
|
const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2;
|
||||||
|
|
||||||
|
const deleteClickHandler = () => {
|
||||||
|
setSelectedProjectFlock(props.row.original);
|
||||||
|
deleteModal.openModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{currentPageSize > 2 && (
|
||||||
|
<RowDropdownOptions isLast2Rows={isLast2Rows}>
|
||||||
|
<RowOptionsMenu
|
||||||
|
type='dropdown'
|
||||||
|
props={props}
|
||||||
|
deleteClickHandler={deleteClickHandler}
|
||||||
|
/>
|
||||||
|
</RowDropdownOptions>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{currentPageSize <= 2 && (
|
||||||
|
<RowCollapseOptions>
|
||||||
|
<RowOptionsMenu
|
||||||
|
type='dropdown'
|
||||||
|
props={props}
|
||||||
|
deleteClickHandler={deleteClickHandler}
|
||||||
|
/>
|
||||||
|
</RowCollapseOptions>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// Handler
|
||||||
|
const pageSizeChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
|
const newVal = val as OptionType;
|
||||||
|
setPageSize(newVal.value as number);
|
||||||
|
};
|
||||||
|
const confirmationModalDeleteClickHandler = async () => {
|
||||||
|
setIsDeleteLoading(true);
|
||||||
|
|
||||||
|
await ProjectFlockApi.delete(selectedProjectFlock?.id as number);
|
||||||
|
refreshProjectFlocks();
|
||||||
|
|
||||||
|
deleteModal.closeModal();
|
||||||
|
toast.success('Successfully delete Project Flock!');
|
||||||
|
setIsDeleteLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
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]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className='w-full p-0 sm:p-4'>
|
||||||
|
<div className='flex flex-col gap-2 mb-4'>
|
||||||
|
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-2'>
|
||||||
|
<div className='flex flex-row'>
|
||||||
|
<Button href='/production/project-flock/add' color='primary'>
|
||||||
|
<Icon icon='ic:round-plus' width={24} height={24} />
|
||||||
|
Tambah
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-row justify-end'>
|
||||||
|
<SelectInput
|
||||||
|
label='Baris'
|
||||||
|
options={ROWS_OPTIONS}
|
||||||
|
value={{
|
||||||
|
label: String(tableFilterState.pageSize),
|
||||||
|
value: tableFilterState.pageSize,
|
||||||
|
}}
|
||||||
|
onChange={pageSizeChangeHandler}
|
||||||
|
className={{ wrapper: 'max-w-28' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Table<ProjectFlock>
|
||||||
|
data={isResponseSuccess(projectFlocks) ? projectFlocks?.data : []}
|
||||||
|
columns={projectFlocksColumns}
|
||||||
|
pageSize={tableFilterState.pageSize}
|
||||||
|
page={
|
||||||
|
isResponseSuccess(projectFlocks) ? projectFlocks?.meta?.page : 0
|
||||||
|
}
|
||||||
|
totalItems={
|
||||||
|
isResponseSuccess(projectFlocks)
|
||||||
|
? projectFlocks?.meta?.total_results
|
||||||
|
: 0
|
||||||
|
}
|
||||||
|
onPageChange={setPage}
|
||||||
|
isLoading={isLoading}
|
||||||
|
sorting={sorting}
|
||||||
|
setSorting={setSorting}
|
||||||
|
className={{
|
||||||
|
containerClassName: cn({
|
||||||
|
'mb-20':
|
||||||
|
isResponseSuccess(projectFlocks) &&
|
||||||
|
projectFlocks?.data?.length === 0,
|
||||||
|
}),
|
||||||
|
tableWrapperClassName: 'overflow-x-auto min-h-full!',
|
||||||
|
tableClassName: 'font-inter w-full table-auto min-h-full!',
|
||||||
|
headerRowClassName: 'border-b border-b-gray-200',
|
||||||
|
headerColumnClassName:
|
||||||
|
'px-6 py-3 text-xs font-semibold text-gray-500 last:flex last:flex-row last:justify-end',
|
||||||
|
bodyRowClassName: 'border-b border-b-gray-200',
|
||||||
|
bodyColumnClassName:
|
||||||
|
'px-6 py-3 last:flex last:flex-row last:justify-end',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ConfirmationModal
|
||||||
|
ref={deleteModal.ref}
|
||||||
|
type='error'
|
||||||
|
text={`Apakah anda yakin ingin menghapus data Project Flock ini (${selectedProjectFlock?.flock?.name})?`}
|
||||||
|
secondaryButton={{
|
||||||
|
text: 'Tidak',
|
||||||
|
}}
|
||||||
|
primaryButton={{
|
||||||
|
text: 'Ya',
|
||||||
|
color: 'error',
|
||||||
|
isLoading: isDeleteLoading,
|
||||||
|
onClick: confirmationModalDeleteClickHandler,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProjectFlockTable;
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
|
export const ProjectFlockFormSchema = Yup.object({
|
||||||
|
name: Yup.string().required('Nama Proyek wajib diisi!'),
|
||||||
|
|
||||||
|
// Flock
|
||||||
|
flock: Yup.object({
|
||||||
|
value: Yup.number().required('ID Flock wajib diisi!'),
|
||||||
|
label: Yup.string().required('Nama Flock wajib diisi!'),
|
||||||
|
}).nullable(),
|
||||||
|
flock_id: Yup.number().required('Flock wajib diisi!'),
|
||||||
|
|
||||||
|
// Area
|
||||||
|
area: Yup.object({
|
||||||
|
value: Yup.number().required('ID Area wajib diisi!'),
|
||||||
|
label: Yup.string().required('Nama Area wajib diisi!'),
|
||||||
|
}).nullable(),
|
||||||
|
area_id: Yup.number().required('Area wajib diisi!'),
|
||||||
|
|
||||||
|
//Product Category
|
||||||
|
product_category: Yup.object({
|
||||||
|
value: Yup.number().required('ID Kategori Produk wajib diisi!'),
|
||||||
|
label: Yup.string().required('Nama Kategori Produk wajib diisi!'),
|
||||||
|
}).nullable(),
|
||||||
|
product_category_id: Yup.number().required('Kategori Produk wajib diisi!'),
|
||||||
|
|
||||||
|
// FCR
|
||||||
|
fcr: Yup.object({
|
||||||
|
value: Yup.number().required('ID FCR wajib diisi!'),
|
||||||
|
label: Yup.string().required('Nama FCR wajib diisi!'),
|
||||||
|
}).nullable(),
|
||||||
|
fcr_id: Yup.number().required('FCR wajib diisi!'),
|
||||||
|
|
||||||
|
// Location
|
||||||
|
location: Yup.object({
|
||||||
|
value: Yup.number().required('ID Lokasi wajib diisi!'),
|
||||||
|
label: Yup.string().required('Nama Lokasi wajib diisi!'),
|
||||||
|
}).nullable(),
|
||||||
|
location_id: Yup.number().required('Lokasi wajib diisi!'),
|
||||||
|
|
||||||
|
period: Yup.number()
|
||||||
|
.required('Periode wajib diisi!')
|
||||||
|
.typeError('Periode harus berupa angka')
|
||||||
|
.min(1, 'Minimal periode adalah 1'),
|
||||||
|
|
||||||
|
kandang_ids: Yup.array()
|
||||||
|
.of(Yup.number().typeError('Kandang tidak valid!'))
|
||||||
|
.min(1, 'Minimal harus ada 1 kandang!')
|
||||||
|
.required('Kandang wajib diisi!'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ProjectFlockFormValues = Yup.InferType<
|
||||||
|
typeof ProjectFlockFormSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
export const UpdateProjectFlockFormSchema = ProjectFlockFormSchema;
|
||||||
|
|
||||||
@@ -0,0 +1,646 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Button from '@/components/Button';
|
||||||
|
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
import {
|
||||||
|
AreaApi,
|
||||||
|
FcrApi,
|
||||||
|
FlockApi,
|
||||||
|
KandangApi,
|
||||||
|
LocationApi,
|
||||||
|
ProductCategoryApi,
|
||||||
|
} from '@/services/api/master-data';
|
||||||
|
import { Icon } from '@iconify/react';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
import {
|
||||||
|
ProjectFlockFormSchema,
|
||||||
|
ProjectFlockFormValues,
|
||||||
|
UpdateProjectFlockFormSchema,
|
||||||
|
} from './ProjectFlockForm.schema';
|
||||||
|
import {
|
||||||
|
CreateProjectFlockPayload,
|
||||||
|
ProjectFlock,
|
||||||
|
} from '@/types/api/production/project-flock';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import TextInput from '@/components/input/TextInput';
|
||||||
|
import Table from '@/components/Table';
|
||||||
|
import { Kandang } from '@/types/api/master-data/kandang';
|
||||||
|
import Collapse from '@/components/Collapse';
|
||||||
|
import { ProjectFlockApi } from '@/services/api/production';
|
||||||
|
|
||||||
|
interface ProjectFlockFormProps {
|
||||||
|
formType?: 'add' | 'edit' | 'detail';
|
||||||
|
initialValues?: ProjectFlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProjectFlockForm = ({
|
||||||
|
formType = 'add',
|
||||||
|
initialValues,
|
||||||
|
}: ProjectFlockFormProps) => {
|
||||||
|
// State
|
||||||
|
const router = useRouter();
|
||||||
|
const [projectFlockFormErrorMessage, setProjectFlockFormErrorMessage] =
|
||||||
|
useState('');
|
||||||
|
const [selectedArea, setSelectedArea] = useState('');
|
||||||
|
|
||||||
|
const [selectedLocation, setSelectedLocation] = useState('');
|
||||||
|
const [disabledLocation, setDisabledLocation] = useState(true);
|
||||||
|
const [optionsLocation, setOptionsLocation] = useState<OptionType[]>([]);
|
||||||
|
|
||||||
|
const [openSelectKandangs, setOpenSelectKandangs] = useState(
|
||||||
|
initialValues?.kandangs?.length > 0
|
||||||
|
);
|
||||||
|
const [optionsKandang, setOptionsKandang] = useState<Kandang[]>(
|
||||||
|
initialValues?.kandangs ?? []
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fetch Data
|
||||||
|
const flockUrl = `${FlockApi.basePath}?${new URLSearchParams({
|
||||||
|
search: '',
|
||||||
|
}).toString()}`;
|
||||||
|
const { data: flocks, isLoading: isLoadingFlocks } = useSWR(
|
||||||
|
flockUrl,
|
||||||
|
FlockApi.getAllFetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
const areaUrl = `${AreaApi.basePath}?${new URLSearchParams({
|
||||||
|
search: '',
|
||||||
|
}).toString()}`;
|
||||||
|
const { data: areas, isLoading: isLoadingAreas } = useSWR(
|
||||||
|
areaUrl,
|
||||||
|
AreaApi.getAllFetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
const locationUrl = `${LocationApi.basePath}?${new URLSearchParams({
|
||||||
|
search: '',
|
||||||
|
area_id: selectedArea,
|
||||||
|
}).toString()}`;
|
||||||
|
const { data: locations, isLoading: isLoadingLocations } = useSWR(
|
||||||
|
locationUrl,
|
||||||
|
LocationApi.getAllFetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
const fcrUrl = `${FcrApi.basePath}?${new URLSearchParams({
|
||||||
|
search: '',
|
||||||
|
}).toString()}`;
|
||||||
|
const { data: fcrs, isLoading: isLoadingFcrs } = useSWR(
|
||||||
|
fcrUrl,
|
||||||
|
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,
|
||||||
|
}).toString()}`;
|
||||||
|
const { data: kandang, isLoading: isLoadingKandang } = useSWR(
|
||||||
|
kandangUrl,
|
||||||
|
KandangApi.getAllFetcher
|
||||||
|
);
|
||||||
|
|
||||||
|
// Map Data to Options
|
||||||
|
const optionsArea = isResponseSuccess(areas)
|
||||||
|
? areas?.data.map((area) => ({
|
||||||
|
value: area.id,
|
||||||
|
label: area.name,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
const optionsFcr = isResponseSuccess(fcrs)
|
||||||
|
? fcrs?.data.map((fcr) => ({
|
||||||
|
value: fcr.id,
|
||||||
|
label: fcr.name,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
const optionsFlock = isResponseSuccess(flocks)
|
||||||
|
? flocks?.data.map((flock) => ({
|
||||||
|
value: flock.id,
|
||||||
|
label: flock.name,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
const optionsProductCategory = isResponseSuccess(productCategories)
|
||||||
|
? productCategories?.data.map((productCategory) => ({
|
||||||
|
value: productCategory.id,
|
||||||
|
label: productCategory.name,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isResponseSuccess(locations)) {
|
||||||
|
const options = locations.data.map((location) => ({
|
||||||
|
value: location.id,
|
||||||
|
label: location.name,
|
||||||
|
}));
|
||||||
|
setOptionsLocation(options);
|
||||||
|
}
|
||||||
|
}, [locations]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isResponseSuccess(kandang)) {
|
||||||
|
if (kandang.data.length > 0 && selectedLocation != '') {
|
||||||
|
setOptionsKandang(kandang.data);
|
||||||
|
setOpenSelectKandangs(true);
|
||||||
|
} else {
|
||||||
|
setOptionsKandang([]);
|
||||||
|
setOpenSelectKandangs(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [kandang]);
|
||||||
|
|
||||||
|
// Options Handler
|
||||||
|
const areaChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
|
formik.setFieldTouched('area_id', true);
|
||||||
|
formik.setFieldValue('area_id', (val as OptionType)?.value);
|
||||||
|
|
||||||
|
formik.setFieldValue('area', val);
|
||||||
|
|
||||||
|
setSelectedArea((val as OptionType)?.value as string);
|
||||||
|
const disabled = (val as OptionType)?.value == null;
|
||||||
|
setDisabledLocation(disabled);
|
||||||
|
|
||||||
|
formik.setFieldValue('location', null);
|
||||||
|
formik.setFieldValue('location_id', 0);
|
||||||
|
formik.setFieldTouched('location', false);
|
||||||
|
formik.setFieldTouched('location_id', false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const locationChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||||
|
setSelectedLocation((val as OptionType)?.value as string);
|
||||||
|
optionChangeHandler(val, 'location');
|
||||||
|
formik.setFieldValue('kandang_ids', []);
|
||||||
|
};
|
||||||
|
|
||||||
|
const optionChangeHandler = (
|
||||||
|
val: OptionType | OptionType[] | null,
|
||||||
|
inputName: string
|
||||||
|
) => {
|
||||||
|
formik.setFieldValue(inputName, val);
|
||||||
|
|
||||||
|
formik.setFieldValue(
|
||||||
|
`${inputName}_id`,
|
||||||
|
val ? (val as OptionType)?.value : 0
|
||||||
|
);
|
||||||
|
formik.setFieldTouched(`${inputName}_id`, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const kandangChangeHandler = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const { value, checked } = event.target;
|
||||||
|
if (checked) {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'kandang_ids',
|
||||||
|
formik.values.kandang_ids.concat(parseInt(value))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'kandang_ids',
|
||||||
|
formik.values.kandang_ids.filter((id) => id !== parseInt(value))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const kandangCheckAll = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const { checked } = event.target;
|
||||||
|
if (checked) {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'kandang_ids',
|
||||||
|
optionsKandang.map((kandang) => kandang.id)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
formik.setFieldValue('kandang_ids', []);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Submit Handler
|
||||||
|
const createProjectFlockHandler = async (
|
||||||
|
payload: CreateProjectFlockPayload
|
||||||
|
) => {
|
||||||
|
const createProjectFlockRes = await ProjectFlockApi.create(payload);
|
||||||
|
|
||||||
|
if (isResponseSuccess(createProjectFlockRes)) {
|
||||||
|
toast.success(createProjectFlockRes?.message as string);
|
||||||
|
router.push('/production/project-flock');
|
||||||
|
}
|
||||||
|
if (isResponseError(createProjectFlockRes)) {
|
||||||
|
setProjectFlockFormErrorMessage(createProjectFlockRes?.message as string);
|
||||||
|
// toast.ersror(createProjectFlockRes?.message as string);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Formik InitialValue
|
||||||
|
const formikInitialValues = useMemo<ProjectFlockFormValues>(() => {
|
||||||
|
return {
|
||||||
|
name: initialValues?.name ?? '',
|
||||||
|
flock: initialValues?.flock
|
||||||
|
? {
|
||||||
|
value: initialValues.flock.id,
|
||||||
|
label: initialValues.flock.name,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
area: initialValues?.area
|
||||||
|
? {
|
||||||
|
value: initialValues.area.id,
|
||||||
|
label: initialValues.area.name,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
product_category: initialValues?.product_category
|
||||||
|
? {
|
||||||
|
value: initialValues.product_category.id,
|
||||||
|
label: initialValues.product_category.name,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
fcr: initialValues?.fcr
|
||||||
|
? {
|
||||||
|
value: initialValues.fcr.id,
|
||||||
|
label: initialValues.fcr.name,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
location: initialValues?.location
|
||||||
|
? {
|
||||||
|
value: initialValues.location.id,
|
||||||
|
label: initialValues.location.name,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
flock_id: initialValues?.flock_id ?? 0,
|
||||||
|
area_id: 0,
|
||||||
|
product_category_id: 0,
|
||||||
|
fcr_id: 0,
|
||||||
|
location_id: 0,
|
||||||
|
period: initialValues?.period ?? 0,
|
||||||
|
kandang_ids: [],
|
||||||
|
};
|
||||||
|
}, [initialValues]);
|
||||||
|
|
||||||
|
// Formik
|
||||||
|
const formik = useFormik<ProjectFlockFormValues>({
|
||||||
|
initialValues: formikInitialValues,
|
||||||
|
validationSchema:
|
||||||
|
formType == 'add' ? ProjectFlockFormSchema : UpdateProjectFlockFormSchema,
|
||||||
|
validateOnBlur: true,
|
||||||
|
validateOnChange: true,
|
||||||
|
validateOnMount: true,
|
||||||
|
onSubmit: async (values) => {
|
||||||
|
setProjectFlockFormErrorMessage('');
|
||||||
|
const payload: CreateProjectFlockPayload = {
|
||||||
|
name: values.name as string,
|
||||||
|
flock_id: values.flock_id as number,
|
||||||
|
area_id: values.area_id as number,
|
||||||
|
product_category_id: values.product_category_id as number,
|
||||||
|
fcr_id: values.fcr_id as number,
|
||||||
|
location_id: values.location_id as number,
|
||||||
|
period: values.period as number,
|
||||||
|
kandang_ids: values.kandang_ids as number[],
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (formType) {
|
||||||
|
case 'add':
|
||||||
|
await createProjectFlockHandler(payload);
|
||||||
|
break;
|
||||||
|
case 'detail':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { setValues: formikSetValues } = formik;
|
||||||
|
// Effect Initial
|
||||||
|
useEffect(() => {
|
||||||
|
console.log('Initial Value');
|
||||||
|
console.log(initialValues);
|
||||||
|
if(formType == 'detail'){
|
||||||
|
formik.setFieldValue('area', {
|
||||||
|
value: initialValues.area.id,
|
||||||
|
label: initialValues.area.name,
|
||||||
|
});
|
||||||
|
formik.setFieldValue('area_id', initialValues.area_id);
|
||||||
|
setSelectedArea(initialValues.area?.id);
|
||||||
|
|
||||||
|
formik.setFieldValue('period', initialValues.period);
|
||||||
|
}
|
||||||
|
}, [initialValues, setSelectedArea, formType]);
|
||||||
|
useEffect(() => {
|
||||||
|
formikSetValues(formikInitialValues);
|
||||||
|
}, [formikSetValues, formikInitialValues]);
|
||||||
|
// Aktifkan lokasi jika formType = 'detail'
|
||||||
|
useEffect(() => {
|
||||||
|
if (formType === 'detail') {
|
||||||
|
setDisabledLocation(false);
|
||||||
|
}
|
||||||
|
}, [formType]);
|
||||||
|
|
||||||
|
// Set lokasi otomatis berdasarkan initialValues saat formType = 'detail'
|
||||||
|
useEffect(() => {
|
||||||
|
if (formType === 'detail' && initialValues?.location?.id) {
|
||||||
|
setSelectedLocation(initialValues.location?.id.toString());
|
||||||
|
setDisabledLocation(false); // biar dropdown lokasi aktif juga
|
||||||
|
}
|
||||||
|
}, [formType, initialValues]);
|
||||||
|
|
||||||
|
// Setelah data kandang difetch, centang otomatis kandang yang ada di initialValues
|
||||||
|
useEffect(() => {
|
||||||
|
if (formType === 'detail' && isResponseSuccess(kandang)) {
|
||||||
|
setOptionsKandang(kandang.data);
|
||||||
|
setOpenSelectKandangs(true);
|
||||||
|
|
||||||
|
// Ambil ID dari initialValues.kandangs
|
||||||
|
const kandangIds =
|
||||||
|
initialValues?.kandangs?.map((k: Kandang) => k.id) ?? [];
|
||||||
|
|
||||||
|
// Set nilai ke formik
|
||||||
|
formik.setFieldValue('kandang_ids', kandangIds);
|
||||||
|
}
|
||||||
|
}, [formType, kandang, initialValues]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className='w-full'>
|
||||||
|
<header className='flex flex-col gap-4'>
|
||||||
|
<Button
|
||||||
|
href='/production/project-flock'
|
||||||
|
variant='link'
|
||||||
|
className='w-fit p-0 text-primary'
|
||||||
|
>
|
||||||
|
<Icon icon='uil:arrow-left' width={24} height={24} />
|
||||||
|
Kembali
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<h1 className='text-2xl font-bold text-center'>
|
||||||
|
{formType === 'add' && 'Tambah Project Flock'}
|
||||||
|
{formType === 'detail' && 'Detail Project Flock'}
|
||||||
|
</h1>
|
||||||
|
</header>
|
||||||
|
{projectFlockFormErrorMessage && (
|
||||||
|
<div className='my-4'>
|
||||||
|
<div role='alert' className='alert alert-error'>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:error-outline'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
<span>{projectFlockFormErrorMessage}</span>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setProjectFlockFormErrorMessage('');
|
||||||
|
}}
|
||||||
|
variant='link'
|
||||||
|
>
|
||||||
|
<Icon icon='material-symbols:close' width={24} height={24} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<form
|
||||||
|
className='w-auto h-auto'
|
||||||
|
onSubmit={formik.handleSubmit}
|
||||||
|
onReset={formik.handleReset}
|
||||||
|
>
|
||||||
|
<div className='card bg-base-100 shadow w-full mb-6'>
|
||||||
|
<div className='card-body'>
|
||||||
|
<div className='card-title mb-4'>Informasi Umum</div>
|
||||||
|
|
||||||
|
<div className='grid grid-cols-2 gap-4'>
|
||||||
|
{formType != 'detail' && (
|
||||||
|
<div className='col-span-2'>
|
||||||
|
<TextInput
|
||||||
|
required
|
||||||
|
name='name'
|
||||||
|
label='Nama Project Flock'
|
||||||
|
placeholder='Masukan nama project flock'
|
||||||
|
value={formik.values.name}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
onBlur={formik.handleBlur}
|
||||||
|
isError={
|
||||||
|
formik.touched.name && Boolean(formik.errors.name)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.name}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<SelectInput
|
||||||
|
required
|
||||||
|
label='Area'
|
||||||
|
value={formik.values.area as OptionType}
|
||||||
|
onChange={areaChangeHandler}
|
||||||
|
options={optionsArea}
|
||||||
|
isLoading={isLoadingAreas}
|
||||||
|
isError={formik.touched.area && Boolean(formik.errors.area)}
|
||||||
|
errorMessage={formik.errors.area as string}
|
||||||
|
isClearable
|
||||||
|
isDisabled={formType === 'detail'}
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
required
|
||||||
|
label='Flock'
|
||||||
|
value={formik.values.flock as OptionType}
|
||||||
|
onChange={(val) => {
|
||||||
|
optionChangeHandler(val, 'flock');
|
||||||
|
}}
|
||||||
|
options={optionsFlock}
|
||||||
|
isLoading={isLoadingFlocks}
|
||||||
|
isError={formik.touched.flock && Boolean(formik.errors.flock)}
|
||||||
|
errorMessage={formik.errors.flock as string}
|
||||||
|
isClearable
|
||||||
|
isDisabled={formType === 'detail'}
|
||||||
|
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
required
|
||||||
|
label='Lokasi'
|
||||||
|
value={formik.values.location as OptionType}
|
||||||
|
onChange={locationChangeHandler}
|
||||||
|
options={optionsLocation}
|
||||||
|
isLoading={isLoadingLocations}
|
||||||
|
isError={
|
||||||
|
formik.touched.location && Boolean(formik.errors.location)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.location as string}
|
||||||
|
isClearable
|
||||||
|
isDisabled={formType === 'detail' || disabledLocation}
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
required
|
||||||
|
label='FCR'
|
||||||
|
value={formik.values.fcr as OptionType}
|
||||||
|
onChange={(val) => {
|
||||||
|
optionChangeHandler(val, 'fcr');
|
||||||
|
}}
|
||||||
|
options={optionsFcr}
|
||||||
|
isLoading={isLoadingFcrs}
|
||||||
|
isError={formik.touched.fcr && Boolean(formik.errors.fcr)}
|
||||||
|
errorMessage={formik.errors.fcr as string}
|
||||||
|
isClearable
|
||||||
|
isDisabled={formType === 'detail'}
|
||||||
|
/>
|
||||||
|
<SelectInput
|
||||||
|
required
|
||||||
|
label='Kategori Produk'
|
||||||
|
value={formik.values.product_category as OptionType}
|
||||||
|
onChange={(val) => {
|
||||||
|
optionChangeHandler(val, 'product_category');
|
||||||
|
}}
|
||||||
|
options={optionsProductCategory}
|
||||||
|
isLoading={isLoadingProductCategories}
|
||||||
|
isError={
|
||||||
|
formik.touched.product_category &&
|
||||||
|
Boolean(formik.errors.product_category)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.product_category as string}
|
||||||
|
isClearable
|
||||||
|
isDisabled={formType === 'detail'}
|
||||||
|
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
required
|
||||||
|
type='number'
|
||||||
|
name='period'
|
||||||
|
label='Periode'
|
||||||
|
value={formik.values.period as number}
|
||||||
|
onChange={formik.handleChange}
|
||||||
|
isError={
|
||||||
|
formik.touched.period && Boolean(formik.errors.period)
|
||||||
|
}
|
||||||
|
errorMessage={formik.errors.period as string}
|
||||||
|
readOnly={formType === 'detail'}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='card bg-base-100 shadow w-full'>
|
||||||
|
<div className='card-body'>
|
||||||
|
<Collapse
|
||||||
|
title={
|
||||||
|
<div className='card-actions justify-between w-full'>
|
||||||
|
<div className='card-title'>Pilih Kandang</div>
|
||||||
|
<Button
|
||||||
|
variant='link'
|
||||||
|
className='text-primary rotate-0 transition-transform hover:text-inherit'
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
icon='material-symbols:keyboard-arrow-down'
|
||||||
|
width={24}
|
||||||
|
height={24}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
className='w-full size-full'
|
||||||
|
titleClassName='w-full p-0!'
|
||||||
|
onOpenChange={setOpenSelectKandangs}
|
||||||
|
open={openSelectKandangs}
|
||||||
|
>
|
||||||
|
<div className='overflow-x-auto'>
|
||||||
|
<table className='table'>
|
||||||
|
{/* head */}
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type='checkbox'
|
||||||
|
checked={
|
||||||
|
formik.values.kandang_ids.length ===
|
||||||
|
optionsKandang.length
|
||||||
|
}
|
||||||
|
className='checkbox'
|
||||||
|
onChange={
|
||||||
|
formType === 'detail'
|
||||||
|
? () => {}
|
||||||
|
: kandangCheckAll
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</th>
|
||||||
|
<th>Kandang</th>
|
||||||
|
<th>Penanggung Jawab</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{/* rows */}
|
||||||
|
{selectedLocation != '' &&
|
||||||
|
optionsKandang.map((kandang) => (
|
||||||
|
<tr key={kandang.id}>
|
||||||
|
<th>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
value={kandang.id}
|
||||||
|
type='checkbox'
|
||||||
|
className='checkbox'
|
||||||
|
checked={formik.values.kandang_ids.includes(
|
||||||
|
kandang.id
|
||||||
|
)}
|
||||||
|
onChange={
|
||||||
|
formType === 'detail'
|
||||||
|
? () => {}
|
||||||
|
: kandangChangeHandler
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</th>
|
||||||
|
<td>{kandang.name}</td>
|
||||||
|
<td>{kandang.pic?.name}</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{selectedLocation == '' && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={3} className='text-center text-muted'>
|
||||||
|
Data tidak tersedia
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
{/* foot */}
|
||||||
|
{selectedLocation != '' && (
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Kandang</th>
|
||||||
|
<th>Penanggung Jawab</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
)}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</Collapse>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex flex-row justify-center gap-2 flex-wrap my-6'>
|
||||||
|
{formType !== 'detail' && (
|
||||||
|
<div className='flex flex-row justify-end gap-2'>
|
||||||
|
<Button
|
||||||
|
type='button'
|
||||||
|
color='warning'
|
||||||
|
className='px-4'
|
||||||
|
onClick={formik.handleReset}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type='submit'
|
||||||
|
color='primary'
|
||||||
|
isLoading={formik.isSubmitting}
|
||||||
|
disabled={!formik.isValid || formik.isSubmitting}
|
||||||
|
className='px-4'
|
||||||
|
>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProjectFlockForm;
|
||||||
+48
-13
@@ -12,6 +12,52 @@ export const MAIN_DRAWER_LINKS: MAIN_DRAWER_MENU[] = [
|
|||||||
icon: 'gg:chart',
|
icon: 'gg:chart',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: 'Flock',
|
||||||
|
link: '/production',
|
||||||
|
icon: 'material-symbols:raven-outline-rounded',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
title: 'List Flock',
|
||||||
|
link: '/production/project-flock',
|
||||||
|
icon: 'material-symbols:list-alt-add-outline-rounded',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Chick In',
|
||||||
|
link: '/production/chick-in',
|
||||||
|
icon: 'mdi:home-import-outline',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Recording',
|
||||||
|
link: '/production/recording',
|
||||||
|
icon: 'mdi:clipboard-text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
title: 'Persediaan',
|
||||||
|
link: '/inventory',
|
||||||
|
icon: 'mdi:warehouse',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
title: 'Product',
|
||||||
|
link: '/inventory/product',
|
||||||
|
icon: 'mdi:package-variant-closed',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Penyesuaian Stok',
|
||||||
|
link: '/inventory/adjustment',
|
||||||
|
icon: 'mdi:database-edit',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Transfer Stok',
|
||||||
|
link: '/inventory/movement',
|
||||||
|
icon: 'mdi:swap-horizontal',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
title: 'Master Data',
|
title: 'Master Data',
|
||||||
link: '/master-data',
|
link: '/master-data',
|
||||||
@@ -80,24 +126,13 @@ export const MAIN_DRAWER_LINKS: MAIN_DRAWER_MENU[] = [
|
|||||||
{
|
{
|
||||||
title: 'Flock',
|
title: 'Flock',
|
||||||
link: '/master-data/flock',
|
link: '/master-data/flock',
|
||||||
icon: 'material-symbols:raven-outline-rounded',
|
icon: 'material-symbols:raven-outline-rounded'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: 'Persediaan',
|
|
||||||
link: '/inventory',
|
|
||||||
icon: 'material-symbols:box-outline-rounded',
|
|
||||||
submenu: [
|
|
||||||
{
|
|
||||||
title: 'Penyesuaian Persediaan',
|
|
||||||
link: '/inventory/adjustment',
|
|
||||||
icon: 'material-symbols:box-edit-outline-rounded',
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
|
||||||
export const ROWS_OPTIONS = [
|
export const ROWS_OPTIONS = [
|
||||||
{
|
{
|
||||||
label: '10',
|
label: '10',
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import {
|
||||||
|
ProjectFlock,
|
||||||
|
CreateProjectFlockPayload,
|
||||||
|
} from '@/types/api/production/project-flock';
|
||||||
|
import { BaseApiService } from './base';
|
||||||
|
|
||||||
|
export const ProjectFlockApi = new BaseApiService<
|
||||||
|
ProjectFlock,
|
||||||
|
CreateProjectFlockPayload,
|
||||||
|
unknown
|
||||||
|
>('/production/project_flocks');
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
import { Area } from "../master-data/area";
|
||||||
|
import { Fcr } from "../master-data/fcr";
|
||||||
|
import { Flock } from "../master-data/flock";
|
||||||
|
import { Kandang } from "../master-data/kandang";
|
||||||
|
import { Location } from "../master-data/location";
|
||||||
|
import { ProductCategory } from "../master-data/product-category";
|
||||||
|
|
||||||
|
export type BaseProjectFlock = {
|
||||||
|
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