mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Merge branch 'dev/randy' into 'feat/FE/US-75/chick-in-doc'
[FEAT/FE][US#75/TASK#92-93-106] Slicing UI list, create, and edit Chickin DOC See merge request mbugroup/lti-web-client!24
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "VERCEL_GIT_COMMIT_REF: $VERCEL_GIT_COMMIT_REF"
|
||||
|
||||
if [[ "$VERCEL_GIT_COMMIT_REF" == "master" || "$VERCEL_GIT_COMMIT_REF" == "development" ]]; then
|
||||
echo "✅ - Build can proceed"
|
||||
exit 1
|
||||
else
|
||||
echo "🛑 - Build cancelled"
|
||||
exit 0
|
||||
fi
|
||||
@@ -1,5 +1,43 @@
|
||||
@import 'tailwindcss';
|
||||
@plugin "daisyui";
|
||||
@import '../styles/daisyui.css';
|
||||
|
||||
@plugin "daisyui/theme" {
|
||||
name: "lti";
|
||||
default: false;
|
||||
prefersdark: false;
|
||||
color-scheme: "light";
|
||||
--color-base-100: oklch(98% 0.001 106.423);
|
||||
--color-base-200: oklch(97% 0.001 106.424);
|
||||
--color-base-300: oklch(92% 0.003 48.717);
|
||||
--color-base-content: oklch(22.389% 0.031 278.072);
|
||||
--color-primary: oklch(60% 0.126 221.723);
|
||||
--color-primary-content: oklch(100% 0 0);
|
||||
--color-secondary: oklch(52% 0.105 223.128);
|
||||
--color-secondary-content: oklch(100% 0 0);
|
||||
--color-accent: oklch(45% 0.085 224.283);
|
||||
--color-accent-content: oklch(100% 0 0);
|
||||
--color-neutral: oklch(39% 0.07 227.392);
|
||||
--color-neutral-content: oklch(100% 0 0);
|
||||
--color-info: oklch(58% 0.158 241.966);
|
||||
--color-info-content: oklch(100% 0 0);
|
||||
--color-success: oklch(62% 0.194 149.214);
|
||||
--color-success-content: oklch(100% 0 0);
|
||||
--color-warning: oklch(85% 0.199 91.936);
|
||||
--color-warning-content: oklch(0% 0 0);
|
||||
--color-error: oklch(57% 0.245 27.325);
|
||||
--color-error-content: oklch(100% 0 0);
|
||||
--radius-selector: 0rem;
|
||||
--radius-field: 0.25rem;
|
||||
--radius-box: 0.25rem;
|
||||
--size-selector: 0.21875rem;
|
||||
--size-field: 0.1875rem;
|
||||
--border: 1px;
|
||||
--depth: 0;
|
||||
--noise: 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
:root {
|
||||
--color-primary: #1f74bf;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from "@/components/helper/SuspenseHelper"
|
||||
|
||||
const Layout = ({
|
||||
children
|
||||
}: Readonly<{
|
||||
children: React.ReactNode
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>
|
||||
}
|
||||
|
||||
export default Layout;
|
||||
@@ -0,0 +1,11 @@
|
||||
import MovementForm from '@/components/pages/inventory/movement/form/MovementForm';
|
||||
|
||||
const AddMovement = () => {
|
||||
return (
|
||||
<div className='w-full p-4 flex flex-row justify-center'>
|
||||
<MovementForm />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AddMovement;
|
||||
@@ -0,0 +1,48 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import MovementForm from '@/components/pages/inventory/movement/form/MovementForm';
|
||||
import { MovementApi } from '@/services/api/inventory';
|
||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||
|
||||
const MovementEdit = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const movementId = searchParams.get('movementId');
|
||||
|
||||
const { data: movement, isLoading: isLoadingMovement } = useSWR(
|
||||
movementId,
|
||||
(id: number) => MovementApi.getSingle(id)
|
||||
);
|
||||
|
||||
if (!movementId) {
|
||||
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 (!isLoadingMovement && (!movement || isResponseError(movement))) {
|
||||
router.replace('/404');
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='w-full p-4 flex flex-row justify-center'>
|
||||
{isLoadingMovement && (
|
||||
<span className='loading loading-spinner loading-xl' />
|
||||
)}
|
||||
{!isLoadingMovement && isResponseSuccess(movement) && (
|
||||
<MovementForm type='edit' initialValues={movement.data} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MovementEdit;
|
||||
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
||||
|
||||
const Layout = ({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
||||
};
|
||||
|
||||
export default Layout;
|
||||
@@ -0,0 +1,48 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import MovementForm from '@/components/pages/inventory/movement/form/MovementForm';
|
||||
import { MovementApi } from '@/services/api/inventory';
|
||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||
|
||||
const MovementDetail = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const movementId = searchParams.get('movementId');
|
||||
|
||||
const { data: movement, isLoading: isLoadingMovement } = useSWR(
|
||||
movementId,
|
||||
(id: number) => MovementApi.getSingle(id)
|
||||
);
|
||||
|
||||
if (!movementId) {
|
||||
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 (!isLoadingMovement && (!movement || isResponseError(movement))) {
|
||||
router.replace('/404');
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='w-full p-4 flex flex-row justify-center'>
|
||||
{isLoadingMovement && (
|
||||
<span className='loading loading-spinner loading-xl' />
|
||||
)}
|
||||
{!isLoadingMovement && isResponseSuccess(movement) && (
|
||||
<MovementForm type='detail' initialValues={movement.data} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MovementDetail;
|
||||
@@ -0,0 +1,11 @@
|
||||
import MovementTable from '@/components/pages/inventory/movement/MovementTable';
|
||||
|
||||
const Movement = () => {
|
||||
return (
|
||||
<section className='w-full p-4'>
|
||||
<MovementTable />
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default Movement;
|
||||
+1
-1
@@ -28,7 +28,7 @@ export default function RootLayout({
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang='en'>
|
||||
<html lang='en' data-theme='lti'>
|
||||
<body className={`${inter.variable} antialiased font-inter`}>
|
||||
<RequireAuth>
|
||||
<MainDrawer>{children}</MainDrawer>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
||||
|
||||
const Layout = ({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
||||
};
|
||||
|
||||
export default Layout;
|
||||
@@ -0,0 +1,11 @@
|
||||
import FlockForm from "@/components/pages/master-data/flock/form/FlockForm";
|
||||
|
||||
const AddFlock = () => {
|
||||
return (
|
||||
<section className="w-full p-4 flex flex-row justify-center">
|
||||
<FlockForm />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default AddFlock;
|
||||
@@ -0,0 +1,49 @@
|
||||
'use client'
|
||||
|
||||
import FlockForm from "@/components/pages/master-data/flock/form/FlockForm";
|
||||
import { isResponseError, isResponseSuccess } from "@/lib/api-helper";
|
||||
import { FlockApi } from "@/services/api/master-data";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import useSWR from "swr";
|
||||
|
||||
const FlockEdit = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
// Get Query Params
|
||||
const flockId = searchParams.get('flockId');
|
||||
|
||||
// Fetch Data
|
||||
const { data: flock, isLoading: isLoadingFlock } = useSWR(
|
||||
flockId,
|
||||
(id: number) => FlockApi.getSingle(id)
|
||||
);
|
||||
|
||||
if (!flockId) {
|
||||
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 (!isLoadingFlock && (!flock || isResponseError(flock))) {
|
||||
router.replace('/404');
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='w-full p-4 flex flex-row justify-center'>
|
||||
{isLoadingFlock && (
|
||||
<span className='loading loading-spinner loading-xl' />
|
||||
)}
|
||||
{!isLoadingFlock && isResponseSuccess(flock) && (
|
||||
<FlockForm formType='edit' initialValues={flock.data} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FlockEdit;
|
||||
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from "@/components/helper/SuspenseHelper"
|
||||
|
||||
const Layout = ({
|
||||
children
|
||||
}: Readonly<{
|
||||
children: React.ReactNode
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>
|
||||
}
|
||||
|
||||
export default Layout;
|
||||
@@ -0,0 +1,46 @@
|
||||
'use client'
|
||||
|
||||
import FlockForm from "@/components/pages/master-data/flock/form/FlockForm";
|
||||
import { isResponseError, isResponseSuccess } from "@/lib/api-helper";
|
||||
import { FlockApi } from "@/services/api/master-data";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import useSWR from "swr";
|
||||
|
||||
const FlockDetail = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
// Get Query Params
|
||||
const flockId = searchParams.get('flockId');
|
||||
|
||||
// Fetch Data
|
||||
const { data: flock, isLoading: isLoadingFlock } = useSWR(flockId, (id: number) => FlockApi.getSingle(id));
|
||||
|
||||
if(!flockId){
|
||||
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(!isLoadingFlock && (!flock || isResponseError(flock))){
|
||||
router.replace('/404');
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full p-4 flex flex-row justify-center">
|
||||
{isLoadingFlock && (
|
||||
<span className="loading loading-spinner loading-xl" />
|
||||
)}
|
||||
{!isLoadingFlock && isResponseSuccess(flock) && (
|
||||
<FlockForm formType="detail" initialValues={flock.data} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default FlockDetail;
|
||||
@@ -0,0 +1,11 @@
|
||||
import FlockTable from "@/components/pages/master-data/flock/FlocksTable";
|
||||
|
||||
const Flock = () => {
|
||||
return (
|
||||
<section className="w-full p-4">
|
||||
<FlockTable/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default Flock;
|
||||
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
||||
|
||||
const Layout = ({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
||||
};
|
||||
|
||||
export default Layout;
|
||||
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from "@/components/helper/SuspenseHelper"
|
||||
|
||||
const Layout = ({
|
||||
children
|
||||
}: Readonly<{
|
||||
children: React.ReactNode
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>
|
||||
}
|
||||
|
||||
export default Layout;
|
||||
@@ -0,0 +1,249 @@
|
||||
'use client';
|
||||
|
||||
import Button from '@/components/Button';
|
||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||
import Modal, { useModal } from '@/components/Modal';
|
||||
import ChickinForm from '@/components/pages/production/chickin/form/ChickinForm';
|
||||
import Table from '@/components/Table';
|
||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||
import { cn } from '@/lib/helper';
|
||||
import { ProjectFlockApi } from '@/services/api/production';
|
||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import { Kandang } from '@/types/api/master-data/kandang';
|
||||
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import useSWR from 'swr';
|
||||
|
||||
const AddChickin = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const projectFlockId = searchParams.get('projectFlockId');
|
||||
|
||||
// Tables Props
|
||||
const { state: tableFilterState } = useTableFilter({
|
||||
initial: { search: '' },
|
||||
paramMap: { page: 'page', pageSize: 'limit' },
|
||||
});
|
||||
|
||||
// States
|
||||
const [selectedKandang, setSelectedKandang] = useState<Kandang | undefined>(
|
||||
undefined
|
||||
);
|
||||
const [searchProjectFlock, setSearchProjectFlock] = useState('');
|
||||
|
||||
// Fetch Data
|
||||
const { data: projectFlock, isLoading: isLoadingProjectFlock } = useSWR(
|
||||
projectFlockId,
|
||||
(id: number) => ProjectFlockApi.getSingle(id)
|
||||
);
|
||||
const { data: listProjectFlock, isLoading: isLoadingListProjectFlock } =
|
||||
useSWR(`${ProjectFlockApi.basePath}?${new URLSearchParams({
|
||||
search: searchProjectFlock,
|
||||
}).toString()}`, ProjectFlockApi.getAllFetcher);
|
||||
|
||||
const getProjectFlockKandangUrl = `/kandangs/lookup`;
|
||||
const {
|
||||
data: projectFlockKandang,
|
||||
isLoading: isLoadingProjectFlockKandang,
|
||||
mutate: refreshProjectFlockKandang,
|
||||
} = useSWR(getProjectFlockKandangUrl, () =>
|
||||
ProjectFlockApi.customRequest<BaseApiResponse<ProjectFlockKandang>, 'GET'>(
|
||||
getProjectFlockKandangUrl,
|
||||
{
|
||||
method: 'GET',
|
||||
params: {
|
||||
project_flock_id: projectFlockId ?? 0,
|
||||
kandang_id: selectedKandang?.id,
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// Mapping Options
|
||||
const options = isResponseSuccess(listProjectFlock)
|
||||
? listProjectFlock?.data.map((projectFlock) => {
|
||||
return {
|
||||
value: projectFlock.id,
|
||||
label: `${projectFlock?.flock.name} - ${projectFlock?.category} - Periode ${projectFlock.period}` ,
|
||||
};
|
||||
})
|
||||
: [];
|
||||
|
||||
const chickinModal = useModal();
|
||||
|
||||
// Use Effect
|
||||
useEffect(() => {
|
||||
refreshProjectFlockKandang();
|
||||
}, [selectedKandang, refreshProjectFlockKandang]);
|
||||
|
||||
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 (
|
||||
!isLoadingProjectFlock &&
|
||||
(!projectFlock || isResponseError(projectFlock))
|
||||
) {
|
||||
router.replace('/404');
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle Function
|
||||
const handleChickinClick = (kandang: Kandang) => {
|
||||
setSelectedKandang(kandang);
|
||||
refreshProjectFlockKandang();
|
||||
chickinModal.openModal();
|
||||
};
|
||||
const handleAfterSubmit = () => {
|
||||
refreshProjectFlockKandang();
|
||||
chickinModal.closeModal();
|
||||
router.push('/production/chickin');
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{isResponseSuccess(projectFlock) && (
|
||||
<>
|
||||
<section className='w-full p-4'>
|
||||
<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>
|
||||
|
||||
<div className='flex flex-col gap-4 w-full my-4'>
|
||||
<div className='max-w-1/4'>
|
||||
<SelectInput
|
||||
required
|
||||
isSearchable
|
||||
label='Project Flock'
|
||||
options={options}
|
||||
isLoading={isLoadingListProjectFlock}
|
||||
value={{
|
||||
label: `${projectFlock.data.flock.name} - ${projectFlock.data.category} - Periode ${projectFlock.data.period}`,
|
||||
value: projectFlock.data.id,
|
||||
}}
|
||||
onChange={(val) =>
|
||||
router.push(
|
||||
`/production/chickin/add?projectFlockId=${
|
||||
(val as OptionType | null)?.value
|
||||
}`
|
||||
)
|
||||
}
|
||||
onInputChange={(val) => {
|
||||
setSearchProjectFlock(val);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<Table<Kandang>
|
||||
data={projectFlock.data.kandangs}
|
||||
columns={[
|
||||
{
|
||||
header: '#',
|
||||
cell: (props) =>
|
||||
tableFilterState.pageSize * (tableFilterState.page - 1) +
|
||||
props.row.index +
|
||||
1,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: 'Nama Kandang',
|
||||
},
|
||||
{
|
||||
header: 'Aksi',
|
||||
cell: (props) => {
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
color='success'
|
||||
variant='outline'
|
||||
isLoading={isLoadingProjectFlockKandang}
|
||||
onClick={() => {
|
||||
handleChickinClick(props.row.original);
|
||||
}}
|
||||
>
|
||||
<Icon
|
||||
icon='mdi:home-import-outline'
|
||||
width={24}
|
||||
height={24}
|
||||
/>
|
||||
Chickin
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
},
|
||||
},
|
||||
]}
|
||||
page={undefined}
|
||||
className={{
|
||||
containerClassName: cn({
|
||||
'mb-20':
|
||||
isResponseSuccess(projectFlock) &&
|
||||
projectFlock.data.kandangs?.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',
|
||||
paginationClassName: 'hidden',
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
<Modal ref={chickinModal.ref}>
|
||||
<div className='flex flex-row justify-between items-center'>
|
||||
<h1 className='text-xl font-semibold text-center mb-6'>
|
||||
Chickin Kandang - {selectedKandang?.name}
|
||||
</h1>
|
||||
<Button
|
||||
color='error'
|
||||
variant='link'
|
||||
onClick={chickinModal.closeModal}
|
||||
>
|
||||
<Icon
|
||||
className='text-black'
|
||||
icon='uil:times'
|
||||
width={24}
|
||||
height={24}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
{isResponseSuccess(projectFlockKandang) &&
|
||||
!isLoadingProjectFlockKandang && (
|
||||
<ChickinForm
|
||||
initialValues={{
|
||||
project_flock_kandang: projectFlockKandang.data,
|
||||
created_user: projectFlock.data.created_user,
|
||||
created_at: projectFlock.data.created_at,
|
||||
updated_at: projectFlock.data.updated_at,
|
||||
}}
|
||||
afterSubmit={handleAfterSubmit}
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AddChickin;
|
||||
@@ -0,0 +1,10 @@
|
||||
import ChickinTable from "@/components/pages/production/chickin/ChickinTable";
|
||||
|
||||
const Chickin = () => {
|
||||
return (
|
||||
<section className="w-full p-4">
|
||||
<ChickinTable/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
export default Chickin;
|
||||
@@ -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 ProjectFlockEdit = () => {
|
||||
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="edit" initialValues={projectFlock.data} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectFlockEdit;
|
||||
@@ -0,0 +1,11 @@
|
||||
import SuspenseHelper from "@/components/helper/SuspenseHelper"
|
||||
|
||||
const Layout = ({
|
||||
children
|
||||
}: Readonly<{
|
||||
children: React.ReactNode
|
||||
}>) => {
|
||||
return <SuspenseHelper>{children}</SuspenseHelper>
|
||||
}
|
||||
|
||||
export default Layout;
|
||||
@@ -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;
|
||||
@@ -1,7 +1,5 @@
|
||||
import react from 'react';
|
||||
|
||||
import Link from 'next/link';
|
||||
|
||||
import { cn } from '@/lib/helper';
|
||||
import { Color } from '@/types/theme';
|
||||
|
||||
@@ -10,6 +8,8 @@ interface ButtonProps extends react.ComponentProps<'button'> {
|
||||
color?: Color;
|
||||
href?: string;
|
||||
isLoading?: boolean;
|
||||
target?: string;
|
||||
rel?: string;
|
||||
}
|
||||
|
||||
const Button = ({
|
||||
@@ -22,6 +22,8 @@ const Button = ({
|
||||
className,
|
||||
disabled,
|
||||
onClick,
|
||||
target,
|
||||
rel,
|
||||
...props
|
||||
}: ButtonProps) => {
|
||||
const btnBaseClassName = cn(
|
||||
@@ -43,7 +45,7 @@ const Button = ({
|
||||
'btn-warning': color === 'warning',
|
||||
'btn-error': color === 'error',
|
||||
},
|
||||
'h-fit justify-center items-center gap-2 rounded-xl p-2 text-base transition-all'
|
||||
'h-fit justify-center items-center gap-2 rounded p-2 text-base transition-all'
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -68,6 +70,8 @@ const Button = ({
|
||||
{href && (
|
||||
<Link
|
||||
href={disabled ? '#' : href}
|
||||
target={target}
|
||||
rel={rel}
|
||||
aria-disabled={disabled}
|
||||
className={cn(
|
||||
btnBaseClassName,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
import { cn } from '@/lib/helper';
|
||||
import { Color } from '@/types/theme';
|
||||
|
||||
interface TooltipProps {
|
||||
children?: ReactNode;
|
||||
content?: ReactNode;
|
||||
className?: {
|
||||
wrapper?: string;
|
||||
content?: string;
|
||||
};
|
||||
open?: boolean;
|
||||
color?: Color;
|
||||
position?: 'top' | 'bottom' | 'left' | 'right';
|
||||
}
|
||||
|
||||
const Tooltip = ({
|
||||
children,
|
||||
content,
|
||||
className,
|
||||
open,
|
||||
color,
|
||||
position,
|
||||
}: TooltipProps) => {
|
||||
const tooltipBaseClassName = cn('tooltip', {
|
||||
'tooltip-open': typeof open === 'boolean' && open,
|
||||
|
||||
'tooltip-top': position === 'top',
|
||||
'tooltip-bottom': position === 'bottom',
|
||||
'tooltip-left': position === 'left',
|
||||
'tooltip-right': position === 'right',
|
||||
|
||||
'tooltip-primary': color === 'primary',
|
||||
'tooltip-secondary': color === 'secondary',
|
||||
'tooltip-accent': color === 'accent',
|
||||
'tooltip-neutral': color === 'neutral',
|
||||
'tooltip-info': color === 'info',
|
||||
'tooltip-success': color === 'success',
|
||||
'tooltip-warning': color === 'warning',
|
||||
'tooltip-error': color === 'error',
|
||||
});
|
||||
return (
|
||||
<div className={cn(tooltipBaseClassName, className?.wrapper)}>
|
||||
<div
|
||||
className={cn(
|
||||
'tooltip-content',
|
||||
'max-w-60 sm:max-w-xs',
|
||||
className?.content
|
||||
)}
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Tooltip;
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Icon } from '@iconify/react';
|
||||
import { FormikContextType } from 'formik';
|
||||
import Button from '@/components/Button';
|
||||
import { cn } from '@/lib/helper';
|
||||
|
||||
interface FormActionsProps<T> {
|
||||
type: 'add' | 'edit' | 'detail';
|
||||
formik: FormikContextType<T>;
|
||||
editUrl?: string;
|
||||
onDelete?: () => void;
|
||||
disableSubmit?: boolean;
|
||||
}
|
||||
|
||||
export const FormActions = <T,>({
|
||||
type,
|
||||
formik,
|
||||
editUrl,
|
||||
onDelete,
|
||||
disableSubmit = false,
|
||||
}: FormActionsProps<T>) => {
|
||||
return (
|
||||
<div className='flex flex-row justify-between gap-2 flex-wrap'>
|
||||
{type !== 'add' && onDelete && (
|
||||
<div className='flex flex-row justify-start gap-2'>
|
||||
<Button
|
||||
type='button'
|
||||
color='error'
|
||||
onClick={onDelete}
|
||||
className='px-4'
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:delete-outline-rounded'
|
||||
width={24}
|
||||
height={24}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
Delete
|
||||
</Button>
|
||||
{type !== 'edit' && editUrl && (
|
||||
<Button
|
||||
type='button'
|
||||
color='warning'
|
||||
href={editUrl}
|
||||
className='px-4'
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:edit-outline'
|
||||
width={24}
|
||||
height={24}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{type !== 'detail' && (
|
||||
<div
|
||||
className={cn('flex flex-row justify-end gap-2', {
|
||||
'w-full': type === 'add',
|
||||
})}
|
||||
>
|
||||
<Button
|
||||
type='reset'
|
||||
color='warning'
|
||||
className='px-4'
|
||||
onClick={() => {
|
||||
formik.handleReset();
|
||||
formik.validateForm();
|
||||
}}
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
<Button
|
||||
type='submit'
|
||||
color='primary'
|
||||
className='px-4'
|
||||
isLoading={formik.isSubmitting}
|
||||
disabled={disableSubmit || !formik.isValid || formik.isSubmitting}
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
import Button from '@/components/Button';
|
||||
import { Icon } from '@iconify/react';
|
||||
|
||||
interface FormHeaderProps {
|
||||
type: 'add' | 'edit' | 'detail';
|
||||
title: string;
|
||||
backUrl: string;
|
||||
}
|
||||
|
||||
export const FormHeader = ({ type, title, backUrl }: FormHeaderProps) => {
|
||||
return (
|
||||
<header className='flex flex-col gap-4'>
|
||||
<Button href={backUrl} 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'>
|
||||
{type === 'add' && `Tambah ${title}`}
|
||||
{type === 'edit' && `Edit ${title}`}
|
||||
{type === 'detail' && `Detail ${title}`}
|
||||
</h1>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
'use client';
|
||||
|
||||
import {
|
||||
ChangeEventHandler,
|
||||
FocusEventHandler,
|
||||
ReactNode,
|
||||
} from 'react';
|
||||
|
||||
import { cn } from '@/lib/helper';
|
||||
|
||||
export interface DateInputProps {
|
||||
label?: string;
|
||||
bottomLabel?: string;
|
||||
name: string;
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
min?: string;
|
||||
max?: string;
|
||||
className?: {
|
||||
wrapper?: string;
|
||||
label?: string;
|
||||
inputWrapper?: string;
|
||||
input?: string;
|
||||
};
|
||||
isError?: boolean;
|
||||
isValid?: boolean;
|
||||
disabled?: boolean;
|
||||
readOnly?: boolean;
|
||||
required?: boolean;
|
||||
isLoading?: boolean;
|
||||
errorMessage?: string;
|
||||
startAdornment?: ReactNode;
|
||||
endAdornment?: ReactNode;
|
||||
onChange?: ChangeEventHandler<HTMLInputElement>;
|
||||
onBlur?: FocusEventHandler<HTMLInputElement>;
|
||||
}
|
||||
|
||||
const DateInput = ({
|
||||
label,
|
||||
bottomLabel,
|
||||
name,
|
||||
value,
|
||||
placeholder,
|
||||
min,
|
||||
max,
|
||||
className,
|
||||
isError,
|
||||
isValid,
|
||||
errorMessage,
|
||||
startAdornment,
|
||||
endAdornment,
|
||||
disabled = false,
|
||||
required = false,
|
||||
onChange,
|
||||
onBlur,
|
||||
readOnly = false,
|
||||
isLoading = false,
|
||||
}: DateInputProps) => {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'w-full flex flex-col gap-2 text-start',
|
||||
className?.wrapper
|
||||
)}
|
||||
>
|
||||
{label && (
|
||||
<label
|
||||
htmlFor={name}
|
||||
className={cn(
|
||||
'w-full text-sm font-normal leading-5',
|
||||
{
|
||||
'text-error': isError,
|
||||
},
|
||||
className?.label
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
{required && (
|
||||
<>
|
||||
{' '}
|
||||
<span className='tooltip tooltip-error' data-tip='required'>
|
||||
<span className='text-error'>*</span>
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</label>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
'input h-12 px-4 py-2 text-base font-normal leading-6 w-full rounded-lg! outline-none! transition-all duration-200 flex items-center',
|
||||
{
|
||||
'border-error': isError,
|
||||
'border-success!': isValid,
|
||||
},
|
||||
className?.inputWrapper
|
||||
)}
|
||||
>
|
||||
{startAdornment && startAdornment}
|
||||
|
||||
<input
|
||||
type='date'
|
||||
id={name}
|
||||
name={name}
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
onBlur={onBlur}
|
||||
min={min}
|
||||
max={max}
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'grow bg-transparent cursor-pointer',
|
||||
className?.input
|
||||
)}
|
||||
readOnly={readOnly}
|
||||
/>
|
||||
|
||||
{(isLoading || endAdornment) && (
|
||||
<div className='flex flex-row gap-2'>
|
||||
{isLoading && <span className='loading loading-spinner' />}
|
||||
{endAdornment && endAdornment}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!isError && bottomLabel && (
|
||||
<p className='w-full text-sm opacity-60'>{bottomLabel}</p>
|
||||
)}
|
||||
{isError && errorMessage && (
|
||||
<p className='w-full text-sm text-error'>{errorMessage}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DateInput;
|
||||
@@ -1,12 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import {
|
||||
ComponentType,
|
||||
ReactNode,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { ComponentType, ReactNode, useEffect, useMemo, useState } from 'react';
|
||||
import Select, {
|
||||
OptionProps,
|
||||
GroupBase,
|
||||
@@ -98,10 +92,7 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
||||
return { ...base, IndicatorSeparator: () => null };
|
||||
}, [isAnimated]);
|
||||
|
||||
const internalInputChangeHandler = (
|
||||
val: string,
|
||||
meta: InputActionMeta
|
||||
) => {
|
||||
const internalInputChangeHandler = (val: string, meta: InputActionMeta) => {
|
||||
if (meta.action === 'input-change') setInternalInputValue(val);
|
||||
if (meta.action === 'menu-close') setInternalInputValue('');
|
||||
};
|
||||
@@ -113,9 +104,7 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
||||
const SelectComponent = createables ? CreatableSelect : Select;
|
||||
|
||||
/** 🎯 handleChange tanpa any */
|
||||
const handleChange = (
|
||||
val: MultiValue<T> | SingleValue<T>
|
||||
): void => {
|
||||
const handleChange = (val: MultiValue<T> | SingleValue<T> | null): void => {
|
||||
if (!val) {
|
||||
onChange?.(null);
|
||||
return;
|
||||
@@ -145,15 +134,15 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
||||
>
|
||||
{label}
|
||||
{required && (
|
||||
<span className="tooltip tooltip-error" data-tip="required">
|
||||
<span className="text-error"> *</span>
|
||||
<span className='tooltip tooltip-error' data-tip='required'>
|
||||
<span className='text-error'> *</span>
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<SelectComponent<T, boolean, GroupBase<T>>
|
||||
instanceId="select"
|
||||
instanceId='select'
|
||||
value={value ?? (isMulti ? [] : null)}
|
||||
onChange={handleChange}
|
||||
options={options}
|
||||
@@ -225,9 +214,9 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
||||
}}
|
||||
/>
|
||||
|
||||
{isError && <p className="w-full text-sm text-error">{errorMessage}</p>}
|
||||
{isError && <p className='w-full text-sm text-error'>{errorMessage}</p>}
|
||||
{!isError && bottomLabel && (
|
||||
<p className="w-full text-sm opacity-60">{bottomLabel}</p>
|
||||
<p className='w-full text-sm opacity-60'>{bottomLabel}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { Icon } from '@iconify/react';
|
||||
import Steps from '@/components/steps/Steps';
|
||||
import StepItem from '@/components/steps/StepItem';
|
||||
import Tooltip from '@/components/Tooltip';
|
||||
|
||||
import { formatDate } from '@/lib/helper';
|
||||
import { ApprovalsLine } from '@/types/api/api-general';
|
||||
|
||||
interface ApprovalStepsProps {
|
||||
approvals: ApprovalsLine;
|
||||
}
|
||||
|
||||
const ApprovalSteps = ({ approvals }: ApprovalStepsProps) => {
|
||||
return (
|
||||
<Steps direction='vertical' className='w-full md:steps-horizontal'>
|
||||
{approvals.map((approval, idx) => {
|
||||
const stepItemColor =
|
||||
approval.status === 'approved'
|
||||
? 'success'
|
||||
: approval.status === 'rejected'
|
||||
? 'error'
|
||||
: undefined;
|
||||
|
||||
const stepItemIcon =
|
||||
approval.status === 'approved'
|
||||
? 'material-symbols:check-rounded'
|
||||
: approval.status === 'rejected'
|
||||
? 'material-symbols:close-rounded'
|
||||
: 'bxs:hourglass';
|
||||
|
||||
return (
|
||||
<StepItem
|
||||
key={idx}
|
||||
color={stepItemColor}
|
||||
icon={
|
||||
approval.status !== 'waiting' && (
|
||||
<Tooltip
|
||||
color={stepItemColor}
|
||||
position='right'
|
||||
className={{
|
||||
wrapper: 'md:tooltip-bottom',
|
||||
}}
|
||||
content={
|
||||
<div className='flex flex-col text-base'>
|
||||
<span>{formatDate(approval.date, 'YYYY-MM-DD')}</span>
|
||||
<span>Oleh: {approval.action_by}</span>
|
||||
<span>Catatan: {approval.notes}</span>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Icon icon={stepItemIcon} width={24} height={24} />
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
>
|
||||
{approval.role}
|
||||
</StepItem>
|
||||
);
|
||||
})}
|
||||
</Steps>
|
||||
);
|
||||
};
|
||||
|
||||
export default ApprovalSteps;
|
||||
@@ -13,7 +13,7 @@ import toast from 'react-hot-toast';
|
||||
import {
|
||||
InventoryAdjustmentFormSchema,
|
||||
InventoryAdjustmentFormValues,
|
||||
} from './InventoryAdjustmentForm.schema';
|
||||
} from '@/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.schema';
|
||||
import useSWR from 'swr';
|
||||
import {
|
||||
ProductApi,
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { SortingState } from '@tanstack/react-table';
|
||||
|
||||
import Table from '@/components/Table';
|
||||
import { useModal } from '@/components/Modal';
|
||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||
import { Movement } from '@/types/api/inventory/movement';
|
||||
import { MovementApi } from '@/services/api/inventory';
|
||||
import { cn } from '@/lib/helper';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||
import { ROWS_OPTIONS } from '@/config/constant';
|
||||
import { TableToolbar } from '@/components/table/TableToolbar';
|
||||
import { TableRowSizeSelector } from '@/components/table/TableRowSizeSelector';
|
||||
import { OptionType } from '@/components/input/SelectInput';
|
||||
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||
import { TableRowOptions } from '@/components/table/TableRowOptions';
|
||||
|
||||
const MovementTable = () => {
|
||||
const {
|
||||
state: tableFilterState,
|
||||
updateFilter,
|
||||
setPage,
|
||||
setPageSize,
|
||||
toQueryString: getTableFilterQueryString,
|
||||
} = useTableFilter({
|
||||
initial: { search: '' },
|
||||
paramMap: { page: 'page', pageSize: 'limit' },
|
||||
});
|
||||
|
||||
const [sorting, setSorting] = useState<SortingState>([]);
|
||||
const [selectedMovement, setSelectedMovement] = useState<
|
||||
Movement | undefined
|
||||
>(undefined);
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
|
||||
const deleteModal = useModal();
|
||||
|
||||
const {
|
||||
data: movements,
|
||||
isLoading,
|
||||
mutate: refreshMovements,
|
||||
} = useSWR(
|
||||
`${MovementApi.basePath}${getTableFilterQueryString()}`,
|
||||
MovementApi.getAllFetcher
|
||||
);
|
||||
|
||||
const searchChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateFilter('search', e.target.value);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const pageSizeChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
const newVal = val as OptionType;
|
||||
setPageSize(newVal.value as number);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const confirmationModalDeleteClickHandler = async () => {
|
||||
setIsDeleteLoading(true);
|
||||
try {
|
||||
await MovementApi.delete(selectedMovement?.id as number);
|
||||
refreshMovements();
|
||||
deleteModal.closeModal();
|
||||
} finally {
|
||||
setIsDeleteLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-4'>
|
||||
<div className='flex flex-col gap-2 mb-4'>
|
||||
<TableToolbar
|
||||
addButton={{
|
||||
href: '/inventory/movement/add',
|
||||
label: 'Tambah Movement',
|
||||
}}
|
||||
search={{
|
||||
value: tableFilterState.search,
|
||||
onChange: searchChangeHandler,
|
||||
placeholder: 'Cari Movement',
|
||||
}}
|
||||
/>
|
||||
<TableRowSizeSelector
|
||||
value={tableFilterState.pageSize}
|
||||
onChange={pageSizeChangeHandler}
|
||||
options={ROWS_OPTIONS}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Table<Movement>
|
||||
data={isResponseSuccess(movements) ? movements?.data : []}
|
||||
columns={[
|
||||
{
|
||||
header: '#',
|
||||
cell: (props) =>
|
||||
tableFilterState.pageSize * (tableFilterState.page - 1) +
|
||||
props.row.index +
|
||||
1,
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.source_warehouse?.name,
|
||||
header: 'Gudang Asal',
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.destination_warehouse?.name,
|
||||
header: 'Gudang Tujuan',
|
||||
},
|
||||
{
|
||||
accessorKey: 'transfer_reason',
|
||||
header: 'Catatan',
|
||||
},
|
||||
{
|
||||
accessorKey: 'transfer_date',
|
||||
header: 'Tanggal',
|
||||
cell: (props) =>
|
||||
new Date(props.row.original.transfer_date).toLocaleDateString(
|
||||
'id-ID'
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => {
|
||||
const totalCost = row.deliveries?.reduce(
|
||||
(sum, d) => sum + (d.shipping_cost_total || 0),
|
||||
0
|
||||
);
|
||||
return totalCost?.toLocaleString('id-ID');
|
||||
},
|
||||
header: 'Biaya Pengiriman',
|
||||
},
|
||||
{
|
||||
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 = () => {
|
||||
setSelectedMovement(props.row.original);
|
||||
deleteModal.openModal();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{currentPageSize > 2 && (
|
||||
<RowDropdownOptions isLast2Rows={isLast2Rows}>
|
||||
<TableRowOptions
|
||||
type='dropdown'
|
||||
recordId={props.row.original.id}
|
||||
basePath='/inventory/movement'
|
||||
queryParam='movementId'
|
||||
showEdit={false}
|
||||
showDelete={false}
|
||||
/>
|
||||
</RowDropdownOptions>
|
||||
)}
|
||||
|
||||
{currentPageSize <= 2 && (
|
||||
<RowCollapseOptions>
|
||||
<TableRowOptions
|
||||
type='collapse'
|
||||
recordId={props.row.original.id}
|
||||
basePath='/inventory/movement'
|
||||
queryParam='movementId'
|
||||
showEdit={false}
|
||||
showDelete={false}
|
||||
/>
|
||||
</RowCollapseOptions>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
},
|
||||
]}
|
||||
pageSize={tableFilterState.pageSize}
|
||||
page={isResponseSuccess(movements) ? movements?.meta?.page : 0}
|
||||
totalItems={
|
||||
isResponseSuccess(movements) ? movements?.meta?.total_results : 0
|
||||
}
|
||||
onPageChange={setPage}
|
||||
isLoading={isLoading}
|
||||
sorting={sorting}
|
||||
setSorting={setSorting}
|
||||
className={{
|
||||
containerClassName: cn({
|
||||
'mb-20':
|
||||
isResponseSuccess(movements) && movements?.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',
|
||||
}}
|
||||
/>
|
||||
|
||||
<ConfirmationModal
|
||||
ref={deleteModal.ref}
|
||||
type='error'
|
||||
text={`Apakah anda yakin ingin menghapus data Movement ini?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'error',
|
||||
isLoading: isDeleteLoading,
|
||||
onClick: confirmationModalDeleteClickHandler,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MovementTable;
|
||||
@@ -0,0 +1,218 @@
|
||||
import * as Yup from 'yup';
|
||||
import { Movement } from '@/types/api/inventory/movement';
|
||||
|
||||
export type ProductSchema = {
|
||||
product: {
|
||||
value: number;
|
||||
label: string;
|
||||
} | null;
|
||||
product_id: number;
|
||||
product_qty: number;
|
||||
};
|
||||
|
||||
export type DeliverySchema = {
|
||||
delivery_cost?: number | undefined;
|
||||
delivery_cost_per_item?: number | undefined;
|
||||
document?: File | string | null;
|
||||
document_path?: string | null;
|
||||
driver_name: string;
|
||||
vehicle_plate: string;
|
||||
supplier: {
|
||||
value: number;
|
||||
label: string;
|
||||
} | null;
|
||||
supplier_id: number;
|
||||
products: {
|
||||
product: {
|
||||
value: number;
|
||||
label: string;
|
||||
} | null;
|
||||
product_id: number;
|
||||
product_qty: number;
|
||||
}[];
|
||||
};
|
||||
|
||||
const ProductObjectSchema: Yup.ObjectSchema<ProductSchema> = Yup.object({
|
||||
product: Yup.object({
|
||||
value: Yup.number().min(1).required(),
|
||||
label: Yup.string().required(),
|
||||
}).nullable(),
|
||||
product_id: Yup.number().required('Produk wajib diisi!'),
|
||||
product_qty: Yup.number()
|
||||
.required('Qty wajib diisi!')
|
||||
.min(1, 'Qty minimal 1!')
|
||||
.typeError('Qty harus berupa angka!'),
|
||||
});
|
||||
|
||||
const DeliveryProductObjectSchema = Yup.object({
|
||||
product: Yup.object({
|
||||
value: Yup.number().min(1).required(),
|
||||
label: Yup.string().required(),
|
||||
}).nullable(),
|
||||
product_id: Yup.number().required('Produk wajib diisi!'),
|
||||
product_qty: Yup.number()
|
||||
.required('Qty wajib diisi!')
|
||||
.min(1, 'Qty minimal 1!')
|
||||
.typeError('Qty harus berupa angka!'),
|
||||
});
|
||||
|
||||
const DeliveryObjectSchema: Yup.ObjectSchema<DeliverySchema> = Yup.object({
|
||||
delivery_cost: Yup.number()
|
||||
.transform((value) => (isNaN(value) || value === 0 ? undefined : value))
|
||||
.min(1, 'Biaya minimal 1!')
|
||||
.typeError('Biaya harus berupa angka!')
|
||||
.test(
|
||||
'one-of-cost-fields',
|
||||
'Biaya pengiriman atau biaya per item wajib diisi!',
|
||||
function (value) {
|
||||
const { delivery_cost_per_item } = this.parent;
|
||||
return (
|
||||
(value !== undefined && value > 0) ||
|
||||
(delivery_cost_per_item !== undefined && delivery_cost_per_item > 0)
|
||||
);
|
||||
}
|
||||
),
|
||||
delivery_cost_per_item: Yup.number()
|
||||
.transform((value) => (isNaN(value) || value === 0 ? undefined : value))
|
||||
.min(1, 'Biaya per item minimal 1!')
|
||||
.typeError('Biaya per item harus berupa angka!')
|
||||
.test(
|
||||
'one-of-cost-fields',
|
||||
'Biaya pengiriman atau biaya per item wajib diisi!',
|
||||
function (value) {
|
||||
const { delivery_cost } = this.parent;
|
||||
return (
|
||||
(value !== undefined && value > 0) ||
|
||||
(delivery_cost !== undefined && delivery_cost > 0)
|
||||
);
|
||||
}
|
||||
),
|
||||
document_path: Yup.string().optional(),
|
||||
document_index: Yup.number().optional(),
|
||||
document: Yup.mixed<File | string>()
|
||||
.nullable()
|
||||
.test('fileSize', 'Ukuran dokumen maksimal 2 MB', (value) => {
|
||||
if (!value) return true;
|
||||
if (typeof value === 'string') return true;
|
||||
if (value instanceof File) return value.size <= 2 * 1024 * 1024;
|
||||
return false;
|
||||
}),
|
||||
driver_name: Yup.string().required('Nama sopir wajib diisi!'),
|
||||
vehicle_plate: Yup.string().required('Plat nomor wajib diisi!'),
|
||||
supplier: Yup.object({
|
||||
value: Yup.number().min(1).required(),
|
||||
label: Yup.string().required(),
|
||||
}).nullable(),
|
||||
supplier_id: Yup.number().required('Supplier wajib diisi!'),
|
||||
products: Yup.array()
|
||||
.of(DeliveryProductObjectSchema)
|
||||
.min(1, 'Minimal harus ada 1 produk!')
|
||||
.required('Produk wajib diisi!'),
|
||||
});
|
||||
|
||||
export const MovementFormSchema = Yup.object({
|
||||
transfer_reason: Yup.string().required('Alasan transfer wajib diisi!'),
|
||||
transfer_date: Yup.string().required('Tanggal transfer wajib diisi!'),
|
||||
source_warehouse: Yup.object({
|
||||
value: Yup.number().min(1).required(),
|
||||
label: Yup.string().required(),
|
||||
area: Yup.string().optional(),
|
||||
location: Yup.string().optional(),
|
||||
}).nullable(),
|
||||
source_warehouse_id: Yup.number()
|
||||
.required('Gudang asal wajib diisi!')
|
||||
.typeError('Gudang asal wajib diisi!'),
|
||||
destination_warehouse: Yup.object({
|
||||
value: Yup.number().min(1).required(),
|
||||
label: Yup.string().required(),
|
||||
area: Yup.string().optional(),
|
||||
location: Yup.string().optional(),
|
||||
}).nullable(),
|
||||
destination_warehouse_id: Yup.number()
|
||||
.required('Gudang tujuan wajib diisi!')
|
||||
.typeError('Gudang tujuan wajib diisi!'),
|
||||
products: Yup.array()
|
||||
.of(ProductObjectSchema)
|
||||
.min(1, 'Minimal harus ada 1 produk!')
|
||||
.required('Produk wajib diisi!'),
|
||||
deliveries: Yup.array()
|
||||
.of(DeliveryObjectSchema)
|
||||
.min(1, 'Minimal harus ada 1 pengiriman!')
|
||||
.required('Pengiriman wajib diisi!'),
|
||||
});
|
||||
|
||||
export const UpdateMovementFormSchema = MovementFormSchema;
|
||||
|
||||
export type MovementFormValues = Yup.InferType<typeof MovementFormSchema>;
|
||||
|
||||
export const getMovementFormInitialValues = (
|
||||
initialValues?: Movement
|
||||
): MovementFormValues => {
|
||||
const detailIdToProductId = new Map<number, { id: number; name: string }>();
|
||||
initialValues?.details?.forEach((detail) => {
|
||||
detailIdToProductId.set(detail.id, {
|
||||
id: detail.product.id,
|
||||
name: detail.product.name,
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
transfer_reason: initialValues?.transfer_reason ?? '',
|
||||
transfer_date: initialValues?.transfer_date ?? '',
|
||||
source_warehouse: initialValues?.source_warehouse
|
||||
? {
|
||||
value: initialValues.source_warehouse.id,
|
||||
label: initialValues.source_warehouse.name,
|
||||
area: initialValues.source_warehouse.area?.name ?? undefined,
|
||||
location: initialValues.source_warehouse.location?.name ?? undefined,
|
||||
}
|
||||
: null,
|
||||
source_warehouse_id: initialValues?.source_warehouse?.id ?? 0,
|
||||
destination_warehouse: initialValues?.destination_warehouse
|
||||
? {
|
||||
value: initialValues.destination_warehouse.id,
|
||||
label: initialValues.destination_warehouse.name,
|
||||
area: initialValues.destination_warehouse.area?.name ?? undefined,
|
||||
location:
|
||||
initialValues.destination_warehouse.location?.name ?? undefined,
|
||||
}
|
||||
: null,
|
||||
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
||||
products:
|
||||
initialValues?.details?.map((detail) => ({
|
||||
product: {
|
||||
value: detail.product.id,
|
||||
label: detail.product.name,
|
||||
},
|
||||
product_id: detail.product.id,
|
||||
product_qty: detail.quantity,
|
||||
})) ?? [],
|
||||
deliveries:
|
||||
initialValues?.deliveries?.map((d) => ({
|
||||
delivery_cost: d.shipping_cost_total ?? undefined,
|
||||
delivery_cost_per_item: d.shipping_cost_item ?? undefined,
|
||||
document_number: d.document_number ?? '',
|
||||
document: d.document_path ?? null,
|
||||
document_path: d.document_path ?? null,
|
||||
driver_name: d.driver_name ?? '',
|
||||
vehicle_plate: d.vehicle_plate ?? '',
|
||||
supplier: d.supplier
|
||||
? { value: d.supplier.id, label: d.supplier.name }
|
||||
: null,
|
||||
supplier_id: d.supplier?.id ?? 0,
|
||||
products:
|
||||
d.items?.map((item) => {
|
||||
const productData = detailIdToProductId.get(
|
||||
item.stock_transfer_detail_id
|
||||
);
|
||||
return {
|
||||
product: productData
|
||||
? { value: productData.id, label: productData.name }
|
||||
: null,
|
||||
product_id: productData?.id ?? 0,
|
||||
product_qty: item.quantity,
|
||||
};
|
||||
}) ?? [],
|
||||
})) ?? [],
|
||||
};
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,95 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import { useModal } from '@/components/Modal';
|
||||
import { MovementApi } from '@/services/api/inventory';
|
||||
import {
|
||||
CreateMovementPayload,
|
||||
UpdateMovementPayload,
|
||||
} from '@/types/api/inventory/movement';
|
||||
import { isResponseError } from '@/lib/api-helper';
|
||||
|
||||
export const useMovementFormHandlers = (initialValuesId?: number) => {
|
||||
const router = useRouter();
|
||||
const deleteModal = useModal();
|
||||
const [movementFormErrorMessage, setMovementFormErrorMessage] = useState('');
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
|
||||
const createMovementHandler = useCallback(
|
||||
async (payload: CreateMovementPayload, documents: File[] = []) => {
|
||||
const formData = new FormData();
|
||||
formData.append('data', JSON.stringify(payload));
|
||||
documents.forEach((file, index) => {
|
||||
formData.append(`documents[${index}]`, file);
|
||||
});
|
||||
|
||||
const res = await MovementApi.create(
|
||||
formData as unknown as CreateMovementPayload
|
||||
);
|
||||
if (isResponseError(res)) {
|
||||
setMovementFormErrorMessage(res.message);
|
||||
return;
|
||||
}
|
||||
toast.success(res?.message as string);
|
||||
router.push('/inventory/movement');
|
||||
},
|
||||
[router]
|
||||
);
|
||||
|
||||
const updateMovementHandler = useCallback(
|
||||
async (
|
||||
movementId: number,
|
||||
payload: UpdateMovementPayload,
|
||||
documents: File[] = []
|
||||
) => {
|
||||
let finalPayload: UpdateMovementPayload | FormData;
|
||||
|
||||
if (documents.length > 0) {
|
||||
const formData = new FormData();
|
||||
formData.append('data', JSON.stringify(payload));
|
||||
documents.forEach((file, index) => {
|
||||
formData.append(`documents[${index}]`, file);
|
||||
});
|
||||
|
||||
finalPayload = formData as unknown as UpdateMovementPayload;
|
||||
} else {
|
||||
finalPayload = payload;
|
||||
}
|
||||
|
||||
const res = await MovementApi.update(movementId, finalPayload);
|
||||
if (res?.status === 'error') {
|
||||
setMovementFormErrorMessage(res.message);
|
||||
return;
|
||||
}
|
||||
toast.success(res?.message as string);
|
||||
router.refresh();
|
||||
router.push('/inventory/movement');
|
||||
},
|
||||
[router]
|
||||
);
|
||||
|
||||
const deleteMovementClickHandler = useCallback(() => {
|
||||
deleteModal.openModal();
|
||||
}, [deleteModal]);
|
||||
|
||||
const confirmationModalDeleteClickHandler = useCallback(async () => {
|
||||
if (!initialValuesId) return;
|
||||
|
||||
setIsDeleteLoading(true);
|
||||
await MovementApi.delete(initialValuesId);
|
||||
deleteModal.closeModal();
|
||||
toast.success('Successfully delete Movement!');
|
||||
setIsDeleteLoading(false);
|
||||
router.push('/inventory/movement');
|
||||
}, [deleteModal, initialValuesId, router]);
|
||||
|
||||
return {
|
||||
deleteModal,
|
||||
movementFormErrorMessage,
|
||||
isDeleteLoading,
|
||||
createMovementHandler,
|
||||
updateMovementHandler,
|
||||
deleteMovementClickHandler,
|
||||
confirmationModalDeleteClickHandler,
|
||||
};
|
||||
};
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { CustomerFormSchema, CustomerFormValues, UpdateCustomerFormSchema } from './CustomerForm.schema';
|
||||
import { CustomerFormSchema, CustomerFormValues, UpdateCustomerFormSchema } from '@/components/pages/master-data/customer/form/CustomerForm.schema';
|
||||
import { useFormik } from 'formik';
|
||||
import Button from '@/components/Button';
|
||||
import { Icon } from '@iconify/react';
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
'use client';
|
||||
|
||||
import { CellContext, ColumnDef } from '@tanstack/react-table';
|
||||
import { Flock } from '@/types/api/master-data/flock';
|
||||
import { cn } from '@/lib/helper';
|
||||
import Button from '@/components/Button';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||
import { useState } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { FlockApi } from '@/services/api/master-data';
|
||||
import { useModal } from '@/components/Modal';
|
||||
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||
import toast from 'react-hot-toast';
|
||||
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||
import { ROWS_OPTIONS } from '@/config/constant';
|
||||
import Table from '@/components/Table';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||
|
||||
const RowsOptions = ({
|
||||
type = 'dropdown',
|
||||
props,
|
||||
deleteClickHandler,
|
||||
}: {
|
||||
type: 'dropdown' | 'collapse';
|
||||
props: CellContext<Flock, 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={`/master-data/flock/detail/edit/?flockId=${props.row.original.id}`}
|
||||
variant='ghost'
|
||||
color='warning'
|
||||
className='justify-start text-sm'
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:edit-outline'
|
||||
width={16}
|
||||
height={16}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
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
|
||||
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 FlockTable = () => {
|
||||
const {
|
||||
state: tableFilterState,
|
||||
updateFilter,
|
||||
setPage,
|
||||
setPageSize,
|
||||
toQueryString: getTableFilterQueryString,
|
||||
} = useTableFilter({
|
||||
initial: { search: '', nameSort: '' },
|
||||
paramMap: {
|
||||
page: 'page',
|
||||
pageSize: 'limit',
|
||||
nameSort: 'sort_name',
|
||||
},
|
||||
});
|
||||
|
||||
// Fetch Data
|
||||
const {
|
||||
data: flocks,
|
||||
isLoading,
|
||||
mutate: refreshFlocks,
|
||||
} = useSWR(
|
||||
`${FlockApi.basePath}${getTableFilterQueryString()}`,
|
||||
FlockApi.getAllFetcher
|
||||
);
|
||||
|
||||
// State
|
||||
const deleteModal = useModal();
|
||||
const [selectedFlock, setSelectedFlock] = useState<Flock | undefined>(
|
||||
undefined
|
||||
);
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
|
||||
// Columns Definition
|
||||
const flocksColumns: ColumnDef<Flock>[] = [
|
||||
{
|
||||
header: '#',
|
||||
cell: (props) =>
|
||||
tableFilterState.pageSize * (tableFilterState.page - 1) +
|
||||
props.row.index +
|
||||
1,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: 'Nama',
|
||||
},
|
||||
{
|
||||
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 = () => {
|
||||
setSelectedFlock(props.row.original);
|
||||
deleteModal.openModal();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{currentPageSize > 2 && (
|
||||
<RowDropdownOptions isLast2Rows={isLast2Rows}>
|
||||
<RowsOptions
|
||||
type='dropdown'
|
||||
props={props}
|
||||
deleteClickHandler={deleteClickHandler}
|
||||
/>
|
||||
</RowDropdownOptions>
|
||||
)}
|
||||
{currentPageSize <= 2 && (
|
||||
<RowCollapseOptions>
|
||||
<RowsOptions
|
||||
type='collapse'
|
||||
props={props}
|
||||
deleteClickHandler={deleteClickHandler}
|
||||
/>
|
||||
</RowCollapseOptions>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Handler
|
||||
const confirmationModalDeleteClickHandler = async () => {
|
||||
setIsDeleteLoading(true);
|
||||
|
||||
await FlockApi.delete(selectedFlock?.id as number);
|
||||
refreshFlocks();
|
||||
|
||||
deleteModal.closeModal();
|
||||
toast.success('Successfully delete Flock!');
|
||||
setIsDeleteLoading(false);
|
||||
};
|
||||
const searchChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateFilter('search', e.target.value);
|
||||
};
|
||||
const pageSizeChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
const newVal = val as OptionType;
|
||||
setPageSize(newVal.value as number);
|
||||
};
|
||||
|
||||
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='/master-data/flock/add' color='primary'>
|
||||
Tambah Flock
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<DebouncedTextInput
|
||||
name='search'
|
||||
placeholder='Cari Flock'
|
||||
value={tableFilterState.search}
|
||||
onChange={searchChangeHandler}
|
||||
className={{ wrapper: 'sm:max-w-3xs' }}
|
||||
/>
|
||||
</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<Flock>
|
||||
data={isResponseSuccess(flocks) ? flocks?.data : []}
|
||||
columns={flocksColumns}
|
||||
pageSize={tableFilterState.pageSize}
|
||||
page={isResponseSuccess(flocks) ? flocks?.meta?.page : 0}
|
||||
totalItems={
|
||||
isResponseSuccess(flocks) ? flocks?.meta?.total_results : 0
|
||||
}
|
||||
onPageChange={setPage}
|
||||
isLoading={isLoading}
|
||||
className={{
|
||||
containerClassName: cn({
|
||||
'mb-20': isResponseSuccess(flocks) && flocks?.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>
|
||||
<ConfirmationModal
|
||||
ref={deleteModal.ref}
|
||||
type='error'
|
||||
text={`Apakah anda yakin ingin menghapus data Supplier ini (${selectedFlock?.name})?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'error',
|
||||
isLoading: isDeleteLoading,
|
||||
onClick: confirmationModalDeleteClickHandler,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default FlockTable;
|
||||
@@ -0,0 +1,14 @@
|
||||
import * as Yup from 'yup';
|
||||
|
||||
export const FlockFormSchema = Yup.object({
|
||||
name: Yup.string()
|
||||
.required('Nama wajib diisi!')
|
||||
.matches(
|
||||
/^[\p{L}\p{N}\s]+$/u,
|
||||
'Nama tidak boleh mengandung simbol'
|
||||
),
|
||||
});
|
||||
|
||||
export const UpdateFlockFormSchema = FlockFormSchema;
|
||||
|
||||
export type FlockFormValues = Yup.InferType<typeof FlockFormSchema>;
|
||||
@@ -0,0 +1,217 @@
|
||||
'use client'
|
||||
|
||||
import { useModal } from '@/components/Modal';
|
||||
import { FlockApi } from '@/services/api/master-data';
|
||||
import { Flock } from '@/types/api/master-data/flock';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { FlockFormSchema, FlockFormValues, UpdateFlockFormSchema } from '@/components/pages/master-data/flock/form/FlockForm.schema';
|
||||
import { useFormik } from 'formik';
|
||||
import Button from '@/components/Button';
|
||||
import { Icon } from '@iconify/react';
|
||||
import TextInput from '@/components/input/TextInput';
|
||||
import { cn } from '@/lib/helper';
|
||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||
|
||||
interface FlockCustomProps {
|
||||
formType?: 'add' | 'edit' | 'detail';
|
||||
initialValues?: Flock;
|
||||
}
|
||||
|
||||
const FlockForm = ({ formType = 'add', initialValues }: FlockCustomProps) => {
|
||||
const router = useRouter();
|
||||
const deleteModal = useModal();
|
||||
|
||||
// State
|
||||
const [flockFormErrorMessage, setFlockFormErrorMessage] = useState('');
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
|
||||
// Handler
|
||||
const confirmationModalDeleteClickHandler = async () => {
|
||||
setIsDeleteLoading(true);
|
||||
|
||||
await FlockApi.delete(initialValues?.id as number);
|
||||
|
||||
deleteModal.closeModal();
|
||||
setIsDeleteLoading(false);
|
||||
router.push('/master-data/flock');
|
||||
};
|
||||
|
||||
// Initital Value
|
||||
const formikInitialValue = useMemo<FlockFormValues>(() => {
|
||||
return {
|
||||
name: initialValues?.name ?? '',
|
||||
};
|
||||
}, [initialValues]);
|
||||
|
||||
// Formik
|
||||
const formik = useFormik<FlockFormValues>({
|
||||
initialValues: formikInitialValue,
|
||||
enableReinitialize: true,
|
||||
validationSchema: formType === 'edit' ? UpdateFlockFormSchema : FlockFormSchema,
|
||||
onSubmit: async (values) => {
|
||||
// reset error message
|
||||
setFlockFormErrorMessage('');
|
||||
|
||||
// create payload
|
||||
const payload = {
|
||||
name: values.name,
|
||||
};
|
||||
|
||||
// cek type form yang disubmit
|
||||
switch (formType) {
|
||||
case 'add':
|
||||
await FlockApi.create(payload);
|
||||
break;
|
||||
case 'edit':
|
||||
await FlockApi.update(initialValues?.id as number, payload);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
router.push('/master-data/flock');
|
||||
},
|
||||
});
|
||||
|
||||
// Initialize Formik
|
||||
const { setValues: formikSetValues } = formik;
|
||||
useEffect(() => {
|
||||
formikSetValues(formikInitialValue);
|
||||
}, [formikSetValues, formikInitialValue]);
|
||||
|
||||
// Render
|
||||
return (
|
||||
<>
|
||||
<section className='w-full max-w-xl'>
|
||||
<header className='flex flex-col gap-4'>
|
||||
<Button
|
||||
href='/master-data/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 Flock'}
|
||||
{formType === 'edit' && 'Ubah Flock'}
|
||||
{formType === 'detail' && 'Detail Flock'}
|
||||
</h1>
|
||||
</header>
|
||||
<form
|
||||
onSubmit={formik.handleSubmit}
|
||||
onReset={formik.handleReset}
|
||||
className='w-full mt-8 flex flex-col gap-6'
|
||||
>
|
||||
{/* Fields Form */}
|
||||
<div className='flex flex-col gap-4'>
|
||||
<TextInput
|
||||
required
|
||||
label='Nama Flock'
|
||||
name='name'
|
||||
placeholder='Masukkan nama flock'
|
||||
value={formik.values.name}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
isError={formik.touched.name && Boolean(formik.errors.name)}
|
||||
errorMessage={formik.errors.name}
|
||||
readOnly={formType === 'detail'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Button */}
|
||||
<div className='flex flex-row justify-between gap-2 flex-wrap'>
|
||||
{formType !== 'add' && (
|
||||
<div className='flex flex-row justify-start gap-2'>
|
||||
<Button
|
||||
type='button'
|
||||
color='error'
|
||||
onClick={() => deleteModal.openModal()}
|
||||
className='px-4'
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:delete-outline-rounded'
|
||||
width={24}
|
||||
height={24}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
Delete
|
||||
</Button>
|
||||
{formType !== 'edit' && (
|
||||
<Button
|
||||
type='button'
|
||||
color='warning'
|
||||
href={`/master-data/flock/detail/edit/?flockId=${initialValues?.id}`}
|
||||
className='px-4'
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:edit-outline'
|
||||
width={24}
|
||||
height={24}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{formType !== 'detail' && (
|
||||
<div
|
||||
className={cn('flex flex-row justify-end gap-2', {
|
||||
'w-full': formType === 'add',
|
||||
})}
|
||||
>
|
||||
<Button type='reset' color='warning' className='px-4'>
|
||||
Reset
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type='submit'
|
||||
color='primary'
|
||||
isLoading={formik.isSubmitting}
|
||||
disabled={!formik.isValid || formik.isSubmitting}
|
||||
className='px-4'
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{flockFormErrorMessage && (
|
||||
<div role='alert' className='alert alert-error'>
|
||||
<Icon
|
||||
icon='material-symbols:error-outline'
|
||||
width={24}
|
||||
height={24}
|
||||
/>
|
||||
<span>{flockFormErrorMessage}</span>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{formType !== 'add' && (
|
||||
<ConfirmationModal
|
||||
ref={deleteModal.ref}
|
||||
type='error'
|
||||
text={`Apakah anda yakin ingin menghapus data Flock ini (${initialValues?.name})?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'error',
|
||||
onClick: confirmationModalDeleteClickHandler,
|
||||
isLoading: isDeleteLoading,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default FlockForm;
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
SupplierFormSchema,
|
||||
SupplierFormValues,
|
||||
UpdateSupplierFormSchema,
|
||||
} from './SupplierForm.schema';
|
||||
} from '@/components/pages/master-data/supplier/form/SupplierForm.schema';
|
||||
import { useFormik } from 'formik';
|
||||
import SelectInput, { OptionType } from '@/components/input/SelectInput';
|
||||
import { Icon } from '@iconify/react';
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
'use client';
|
||||
|
||||
import Button from '@/components/Button';
|
||||
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
||||
import { OptionType } from '@/components/input/SelectInput';
|
||||
import Modal, { 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 { TableRowSizeSelector } from '@/components/table/TableRowSizeSelector';
|
||||
import { ROWS_OPTIONS } from '@/config/constant';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import { cn } from '@/lib/helper';
|
||||
import { ChickinApi, ProjectFlockApi } from '@/services/api/production';
|
||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||
import { Chickin } from '@/types/api/production/chickin';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { CellContext, SortingState } from '@tanstack/react-table';
|
||||
import { useState } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import ChickinForm from './form/ChickinForm';
|
||||
|
||||
const ChickinTable = () => {
|
||||
const {
|
||||
state: tableFilterState,
|
||||
updateFilter,
|
||||
setPage,
|
||||
setPageSize,
|
||||
toQueryString: getTableFilterQueryString,
|
||||
} = useTableFilter({
|
||||
initial: {
|
||||
search: '',
|
||||
},
|
||||
paramMap: {
|
||||
page: 'page',
|
||||
pageSize: 'limit',
|
||||
search: 'search',
|
||||
},
|
||||
});
|
||||
|
||||
const [sorting, setSorting] = useState<SortingState>([]);
|
||||
const [selectedChickin, setSelectedChickin] = useState<Chickin | undefined>(
|
||||
undefined
|
||||
);
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
|
||||
const deleteModal = useModal();
|
||||
const chickinModal = useModal();
|
||||
|
||||
// Data Fetching
|
||||
const {
|
||||
data: chickins,
|
||||
isLoading,
|
||||
mutate: refreshChickins,
|
||||
} = useSWR(
|
||||
`${ChickinApi.basePath}${getTableFilterQueryString()}`,
|
||||
ChickinApi.getAllFetcher
|
||||
);
|
||||
const {
|
||||
data: projectFlocks,
|
||||
isLoading: isLoadingProjectFlocks,
|
||||
} = useSWR(
|
||||
`${ProjectFlockApi.basePath}${getTableFilterQueryString()}`,
|
||||
ProjectFlockApi.getAllFetcher
|
||||
);
|
||||
|
||||
const searchChangeHandler = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateFilter('search', event.target.value);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const pageSizeChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
const newVal = val as OptionType;
|
||||
setPageSize(newVal.value as number);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const confirmationModalDeleteClickHandler = async () => {
|
||||
setIsDeleteLoading(true);
|
||||
try {
|
||||
await ChickinApi.delete(selectedChickin?.id as number);
|
||||
refreshChickins();
|
||||
deleteModal.closeModal();
|
||||
} finally {
|
||||
setIsDeleteLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='flex flex-col gap-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'>
|
||||
<Button
|
||||
href='/production/chickin/add?projectFlockId=1'
|
||||
color='primary'
|
||||
>
|
||||
<Icon icon='uil:plus' width={24} height={24} />
|
||||
Tambah
|
||||
</Button>
|
||||
<DebouncedTextInput
|
||||
name='search'
|
||||
placeholder='Cari Chickin'
|
||||
value={tableFilterState.search}
|
||||
onChange={searchChangeHandler}
|
||||
className={{ wrapper: 'sm:max-w-3xs' }}
|
||||
/>
|
||||
</div>
|
||||
<TableRowSizeSelector
|
||||
value={tableFilterState.pageSize}
|
||||
onChange={pageSizeChangeHandler}
|
||||
options={ROWS_OPTIONS}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Table<Chickin>
|
||||
data={isResponseSuccess(chickins) ? chickins?.data : []}
|
||||
columns={[
|
||||
{
|
||||
header: '#',
|
||||
cell: (props) =>
|
||||
tableFilterState.pageSize * (tableFilterState.page - 1) +
|
||||
props.row.index +
|
||||
1,
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.project_flock_kandang?.kandang.name,
|
||||
header: 'Kandang',
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.quantity,
|
||||
header: 'Jumlah Chickin',
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.chick_in_date,
|
||||
header: 'Tanggal Chickin',
|
||||
cell: (props) => {
|
||||
if (props.row.original.chick_in_date) {
|
||||
return new Date(props.row.original.chick_in_date).toLocaleDateString(
|
||||
'id-ID'
|
||||
);
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.note,
|
||||
header: 'Catatan',
|
||||
},
|
||||
{
|
||||
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 = () => {
|
||||
setSelectedChickin(props.row.original);
|
||||
deleteModal.openModal();
|
||||
};
|
||||
|
||||
const editClickHandler = () => {
|
||||
setSelectedChickin(props.row.original);
|
||||
chickinModal.openModal();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{currentPageSize > 2 && (
|
||||
<RowDropdownOptions isLast2Rows={isLast2Rows}>
|
||||
<RowOptionsMenu
|
||||
type='dropdown'
|
||||
props={props}
|
||||
deleteClickHandler={deleteClickHandler}
|
||||
editClickHandler={editClickHandler}
|
||||
/>
|
||||
</RowDropdownOptions>
|
||||
)}
|
||||
|
||||
{currentPageSize <= 2 && (
|
||||
<RowCollapseOptions>
|
||||
<RowOptionsMenu
|
||||
type='collapse'
|
||||
props={props}
|
||||
deleteClickHandler={deleteClickHandler}
|
||||
editClickHandler={editClickHandler}
|
||||
/>
|
||||
</RowCollapseOptions>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
},
|
||||
]}
|
||||
pageSize={tableFilterState.pageSize}
|
||||
page={isResponseSuccess(chickins) ? chickins?.meta?.page : 0}
|
||||
totalItems={
|
||||
isResponseSuccess(chickins) ? chickins?.meta?.total_results : 0
|
||||
}
|
||||
onPageChange={setPage}
|
||||
isLoading={isLoading}
|
||||
sorting={sorting}
|
||||
setSorting={setSorting}
|
||||
className={{
|
||||
containerClassName: cn({
|
||||
'mb-20':
|
||||
isResponseSuccess(chickins) && chickins?.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',
|
||||
}}
|
||||
/>
|
||||
<ConfirmationModal
|
||||
ref={deleteModal.ref}
|
||||
type='error'
|
||||
text={`Apakah anda yakin ingin menghapus data Chickin ini?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
onClick: confirmationModalDeleteClickHandler,
|
||||
isLoading: isDeleteLoading,
|
||||
color: 'error',
|
||||
}}
|
||||
/>
|
||||
<Modal ref={chickinModal.ref}>
|
||||
<div className='flex flex-row justify-between items-center'>
|
||||
<h1 className='text-xl font-semibold text-center mb-6'>
|
||||
Chickin Kandang - { selectedChickin?.project_flock_kandang && selectedChickin?.project_flock_kandang.kandang?.name}
|
||||
</h1>
|
||||
<Button
|
||||
color='error'
|
||||
variant='link'
|
||||
onClick={chickinModal.closeModal}
|
||||
>
|
||||
<Icon
|
||||
className='text-black'
|
||||
icon='uil:times'
|
||||
width={24}
|
||||
height={24}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
<ChickinForm initialValues={selectedChickin} formType='edit' afterSubmit={() => {
|
||||
refreshChickins()
|
||||
chickinModal.closeModal()
|
||||
}}/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const RowOptionsMenu = ({
|
||||
type = 'dropdown',
|
||||
props,
|
||||
editClickHandler,
|
||||
deleteClickHandler,
|
||||
}: {
|
||||
type: 'dropdown' | 'collapse';
|
||||
props: CellContext<Chickin, unknown>;
|
||||
editClickHandler: () => void;
|
||||
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/chickin/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
|
||||
variant='ghost'
|
||||
color='warning'
|
||||
className='justify-start text-sm'
|
||||
onClick={editClickHandler}
|
||||
>
|
||||
<Icon icon='mdi:pencil-outline' width={16} height={16} />
|
||||
Edit
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChickinTable;
|
||||
@@ -0,0 +1,11 @@
|
||||
import * as Yup from 'yup';
|
||||
|
||||
export const ChickinFormSchema = Yup.object({
|
||||
chick_in_date: Yup.string().required('Tanggal masuk wajib diisi!'),
|
||||
note: Yup.string().required('Catatan wajib diisi!'),
|
||||
quantity: Yup.number().min(1, 'Jumlah wajib diisi!').required('Jumlah wajib diisi!'),
|
||||
})
|
||||
|
||||
export type ChickinFormValues = Yup.InferType<typeof ChickinFormSchema>;
|
||||
|
||||
export const UpdateChickinFormSchema = ChickinFormSchema;
|
||||
@@ -0,0 +1,206 @@
|
||||
'use client';
|
||||
|
||||
import Button from '@/components/Button';
|
||||
import {
|
||||
Chickin,
|
||||
CreateChickinPayload,
|
||||
UpdateChickinPayload,
|
||||
} from '@/types/api/production/chickin';
|
||||
import {
|
||||
ChickinFormSchema,
|
||||
ChickinFormValues,
|
||||
UpdateChickinFormSchema,
|
||||
} from '@/components/pages/production/chickin/form/ChickinForm.schema';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useFormik } from 'formik';
|
||||
import { ChickinApi } from '@/services/api/production';
|
||||
import DateInput from '@/components/input/DateInput';
|
||||
import { isResponseError } from '@/lib/api-helper';
|
||||
import toast from 'react-hot-toast';
|
||||
import { Icon } from '@iconify/react';
|
||||
import TextArea from '@/components/input/TextArea';
|
||||
import TextInput from '@/components/input/TextInput';
|
||||
|
||||
interface ChickinFormProps {
|
||||
formType?: 'add' | 'detail' | 'edit';
|
||||
initialValues?: Chickin;
|
||||
afterSubmit?: () => void;
|
||||
}
|
||||
|
||||
const ChickinForm = ({
|
||||
formType = 'add',
|
||||
initialValues,
|
||||
afterSubmit,
|
||||
}: ChickinFormProps) => {
|
||||
// Helper Function
|
||||
const formatDateForInput = (dateString?: string): string => {
|
||||
if (!dateString) return '';
|
||||
return new Date(dateString).toISOString().split('T')[0];
|
||||
};
|
||||
|
||||
// State
|
||||
const [chickinFormErrorMessage, setChickinFormErrorMessage] = useState('');
|
||||
|
||||
// Initial Value
|
||||
const formikInitialValue = useMemo<ChickinFormValues>(() => {
|
||||
return {
|
||||
chick_in_date: formatDateForInput(initialValues?.chick_in_date) ?? '',
|
||||
note: initialValues?.note ?? `Catatan Chickin ${initialValues?.project_flock_kandang?.project_flock.flock.name}`,
|
||||
quantity: initialValues?.quantity ?? 1,
|
||||
};
|
||||
}, [initialValues]);
|
||||
|
||||
// Handle Submit Function
|
||||
const handleCreate = useCallback(
|
||||
async (
|
||||
payload: CreateChickinPayload,
|
||||
afterSubmit: (() => void) | undefined
|
||||
) => {
|
||||
const res = await ChickinApi.create(payload);
|
||||
if (isResponseError(res)) {
|
||||
setChickinFormErrorMessage(res.message);
|
||||
return;
|
||||
}
|
||||
toast.success(res?.message as string);
|
||||
afterSubmit?.();
|
||||
},
|
||||
[]
|
||||
);
|
||||
const handleUpdate = useCallback(
|
||||
async (
|
||||
payload: UpdateChickinPayload,
|
||||
afterSubmit: (() => void) | undefined
|
||||
) => {
|
||||
const res = await ChickinApi.update(
|
||||
payload.project_flock_kandang_id as number,
|
||||
payload
|
||||
);
|
||||
if (isResponseError(res)) {
|
||||
setChickinFormErrorMessage(res.message);
|
||||
return;
|
||||
}
|
||||
toast.success(res?.message as string);
|
||||
afterSubmit?.();
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
// Formik
|
||||
const formik = useFormik<ChickinFormValues>({
|
||||
initialValues: formikInitialValue,
|
||||
enableReinitialize: true,
|
||||
validationSchema:
|
||||
formType === 'edit' ? UpdateChickinFormSchema : ChickinFormSchema,
|
||||
onSubmit: async (values) => {
|
||||
// reset error message
|
||||
setChickinFormErrorMessage('');
|
||||
|
||||
if (initialValues?.project_flock_kandang?.id == undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// create payload
|
||||
const payload = {
|
||||
chick_in_date: values.chick_in_date,
|
||||
project_flock_kandang_id: initialValues?.project_flock_kandang?.id,
|
||||
};
|
||||
|
||||
// cek type form yang disubmit
|
||||
switch (formType) {
|
||||
case 'add':
|
||||
handleCreate(payload, afterSubmit);
|
||||
break;
|
||||
case 'edit':
|
||||
handleUpdate(payload, afterSubmit);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Initialize Formik
|
||||
const { setValues: formikSetValues } = formik;
|
||||
useEffect(() => {
|
||||
formikSetValues(formikInitialValue);
|
||||
}, [formikSetValues, formikInitialValue]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<form
|
||||
className='min-h-48 flex flex-col gap-4'
|
||||
onSubmit={formik.handleSubmit}
|
||||
onReset={formik.handleReset}
|
||||
>
|
||||
<DateInput
|
||||
value={formik.values.chick_in_date}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
name='chick_in_date'
|
||||
label='Tanggal Chickin'
|
||||
required
|
||||
isError={
|
||||
formik.touched.chick_in_date && Boolean(formik.errors.chick_in_date)
|
||||
}
|
||||
errorMessage={formik.errors.chick_in_date}
|
||||
/>
|
||||
<TextInput
|
||||
value={formik.values.quantity}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
name='quantity'
|
||||
label='Jumlah Chickin'
|
||||
required
|
||||
isError={formik.touched.quantity && Boolean(formik.errors.quantity)}
|
||||
errorMessage={formik.errors.quantity}
|
||||
type='number'
|
||||
disabled
|
||||
/>
|
||||
<TextArea
|
||||
required
|
||||
label='Catatan'
|
||||
name='note'
|
||||
value={formik.values.note}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
isError={formik.touched.note && Boolean(formik.errors.note)}
|
||||
errorMessage={formik.errors.note}
|
||||
|
||||
/>
|
||||
{initialValues?.project_flock_kandang?.id == undefined && (
|
||||
<p className='text-error'>Project Flock Kandang tidak ditemukan.</p>
|
||||
)}
|
||||
{chickinFormErrorMessage && (
|
||||
<div
|
||||
role='alert'
|
||||
className='alert alert-error'
|
||||
onClick={() => {
|
||||
setChickinFormErrorMessage('');
|
||||
}}
|
||||
>
|
||||
<Icon icon='mdi:times' />
|
||||
<span>{chickinFormErrorMessage}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className='flex justify-center mt-auto gap-2'>
|
||||
<Button color='warning' type='reset'>
|
||||
Reset
|
||||
</Button>
|
||||
<Button
|
||||
type='submit'
|
||||
isLoading={formik.isSubmitting}
|
||||
disabled={
|
||||
!formik.isValid ||
|
||||
formik.isSubmitting ||
|
||||
!initialValues?.project_flock_kandang?.id
|
||||
}
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChickinForm;
|
||||
@@ -0,0 +1,588 @@
|
||||
'use client';
|
||||
|
||||
import Button from '@/components/Button';
|
||||
import DebouncedTextInput from '@/components/input/DebouncedTextInput';
|
||||
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 { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||
import { cn } from '@/lib/helper';
|
||||
import { AreaApi, KandangApi, LocationApi } from '@/services/api/master-data';
|
||||
import { ProjectFlockApi } from '@/services/api/production';
|
||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import { Kandang } from '@/types/api/master-data/kandang';
|
||||
import { ProjectFlock } from '@/types/api/production/project-flock';
|
||||
import { Icon } from '@iconify/react';
|
||||
import {
|
||||
CellContext,
|
||||
ColumnDef,
|
||||
SortingState,
|
||||
} from '@tanstack/react-table';
|
||||
import { ChangeEventHandler, 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
|
||||
href={`/production/chickin/add?projectFlockId=${props.row.original.id}`}
|
||||
variant='ghost'
|
||||
color='success'
|
||||
className='justify-start text-sm'
|
||||
>
|
||||
<Icon icon='mdi:home-import-outline' width={16} height={16} />
|
||||
Chickin
|
||||
</Button>
|
||||
{/* <Button
|
||||
href={`/production/project-flock/detail/edit?projectFlockId=${props.row.original.id}`}
|
||||
variant='ghost'
|
||||
color='warning'
|
||||
className='justify-start text-sm'
|
||||
>
|
||||
<Icon icon='mdi:pencil-outline' width={16} height={16} />
|
||||
Edit
|
||||
</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: '',
|
||||
areaFilter: '',
|
||||
locationFilter: '',
|
||||
kandangFilter: '',
|
||||
periodFilter: '',
|
||||
},
|
||||
paramMap: {
|
||||
page: 'page',
|
||||
pageSize: 'limit',
|
||||
search: 'search',
|
||||
areaFilter: 'area_id',
|
||||
locationFilter: 'location_id',
|
||||
kandangFilter: 'kandang_id',
|
||||
periodFilter: 'period',
|
||||
},
|
||||
});
|
||||
const [locationSelectInputValue, setLocationSelectInputValue] = useState('');
|
||||
const [areaSelectInputValue, setAreaSelectInputValue] = useState('');
|
||||
const [kandangSelectInputValue, setKandangSelectInputValue] = useState('');
|
||||
|
||||
const [selectedArea, setSelectedArea] = useState<OptionType | null>(null);
|
||||
const [selectedLocation, setSelectedLocation] = useState<OptionType | null>(
|
||||
null
|
||||
);
|
||||
const [selectedKandang, setSelectedKandang] = useState<OptionType | null>(
|
||||
null
|
||||
);
|
||||
const [periodInputValue, setPeriodInputValue] = useState<number | null>(null);
|
||||
|
||||
// Fetch Data
|
||||
const {
|
||||
data: projectFlocks,
|
||||
isLoading,
|
||||
mutate: refreshProjectFlocks,
|
||||
} = useSWR(
|
||||
`${ProjectFlockApi.basePath}${getTableFilterQueryString()}`,
|
||||
ProjectFlockApi.getAllFetcher
|
||||
);
|
||||
|
||||
const areaUrl = `${AreaApi.basePath}?${new URLSearchParams({
|
||||
search: areaSelectInputValue,
|
||||
limit: '100',
|
||||
}).toString()}`;
|
||||
const {
|
||||
data: areas,
|
||||
isLoading: isLoadingAreas,
|
||||
} = useSWR(areaUrl, AreaApi.getAllFetcher);
|
||||
|
||||
const locationUrl = `${LocationApi.basePath}?${new URLSearchParams({
|
||||
search: locationSelectInputValue,
|
||||
area_id: selectedArea != null ? selectedArea.value.toString() : '',
|
||||
limit: '100',
|
||||
}).toString()}`;
|
||||
const {
|
||||
data: locations,
|
||||
isLoading: isLoadingLocations,
|
||||
} = useSWR(locationUrl, LocationApi.getAllFetcher);
|
||||
|
||||
const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
|
||||
search: kandangSelectInputValue,
|
||||
location_id:
|
||||
selectedLocation != null ? selectedLocation.value.toString() : '',
|
||||
limit: '100',
|
||||
}).toString()}`;
|
||||
const {
|
||||
data: kandangs,
|
||||
isLoading: isLoadingKandang,
|
||||
} = useSWR(kandangUrl, KandangApi.getAllFetcher);
|
||||
|
||||
// Data to Options Mapping
|
||||
const optionsArea = isResponseSuccess(areas)
|
||||
? areas?.data.map((area) => ({
|
||||
value: area.id,
|
||||
label: area.name,
|
||||
}))
|
||||
: [];
|
||||
const optionsKandang = isResponseSuccess(kandangs)
|
||||
? kandangs?.data.map((kandang) => ({
|
||||
value: kandang.id,
|
||||
label: kandang.name,
|
||||
}))
|
||||
: [];
|
||||
const optionsLocation = isResponseSuccess(locations)
|
||||
? locations?.data.map((location) => ({
|
||||
value: location.id,
|
||||
label: location.name,
|
||||
}))
|
||||
: [];
|
||||
|
||||
// State
|
||||
const [sorting, setSorting] = useState<SortingState>([]);
|
||||
const [selectedProjectFlock, setSelectedProjectFlock] =
|
||||
useState<ProjectFlock>();
|
||||
const deleteModal = useModal();
|
||||
const confirmModal = useModal();
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
||||
const [selectedFlocks, setSelectedFlocks] = useState<ProjectFlock[]>([]);
|
||||
const [isApproveLoading, setIsApproveLoading] = useState(false);
|
||||
|
||||
// Columns
|
||||
const projectFlocksColumns: ColumnDef<ProjectFlock>[] = [
|
||||
{
|
||||
id: 'select',
|
||||
header: () => {
|
||||
const allSelected =
|
||||
isResponseSuccess(projectFlocks) &&
|
||||
projectFlocks.data.length > 0 &&
|
||||
selectedIds.length === projectFlocks.data.length;
|
||||
|
||||
return (
|
||||
<input
|
||||
type='checkbox'
|
||||
className='checkbox checkbox-sm'
|
||||
checked={allSelected}
|
||||
onChange={(e) => handleSelectAll(e.target.checked)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
cell: (props) => {
|
||||
const id = props.row.original.id;
|
||||
const isChecked = selectedIds.includes(id);
|
||||
|
||||
return (
|
||||
<input
|
||||
type='checkbox'
|
||||
className='checkbox checkbox-sm'
|
||||
checked={isChecked}
|
||||
onChange={(e) => handleSelectRow(id, e.target.checked)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
accessorKey: 'flock.name',
|
||||
header: 'Flock',
|
||||
},
|
||||
{
|
||||
accessorKey: 'area.name',
|
||||
header: 'Area',
|
||||
},
|
||||
{
|
||||
accessorKey: 'location.name',
|
||||
header: 'Lokasi',
|
||||
},
|
||||
{
|
||||
accessorKey: 'fcr.name',
|
||||
header: 'FCR',
|
||||
},
|
||||
{
|
||||
accessorKey: 'category',
|
||||
header: 'Kategori',
|
||||
},
|
||||
{
|
||||
header: 'Kandang',
|
||||
cell: (props) => {
|
||||
const kandang = props.row.original.kandangs;
|
||||
if (kandang) {
|
||||
const kandangNames = kandang.map((k: Kandang) => k.name);
|
||||
return (
|
||||
<div>
|
||||
{kandangNames.length > 0 ? kandangNames.join(', ') : 'Tidak ada'}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
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 searchChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||
updateFilter('search', e.target.value);
|
||||
};
|
||||
const handleSelectAll = (checked: boolean) => {
|
||||
if (checked && isResponseSuccess(projectFlocks)) {
|
||||
const allIds = projectFlocks.data.map((item) => item.id);
|
||||
setSelectedIds(allIds);
|
||||
setSelectedFlocks(projectFlocks.data);
|
||||
} else {
|
||||
setSelectedIds([]);
|
||||
setSelectedFlocks([]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectRow = (id: number, checked: boolean) => {
|
||||
if (!isResponseSuccess(projectFlocks)) return;
|
||||
|
||||
const targetFlock = projectFlocks.data.find((item) => item.id === id);
|
||||
|
||||
if (!targetFlock) return;
|
||||
|
||||
if (checked) {
|
||||
setSelectedIds((prev) => [...prev, id]);
|
||||
setSelectedFlocks((prev) => [...(prev || []), targetFlock]);
|
||||
} else {
|
||||
setSelectedIds((prev) => prev.filter((val) => val !== id));
|
||||
setSelectedFlocks((prev) =>
|
||||
(prev || []).filter((flock) => flock.id !== id)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const confirmationModalApproveClickHandler = async () => {
|
||||
setIsApproveLoading(true);
|
||||
const approveProjectFlockRes = await ProjectFlockApi.customRequest<
|
||||
BaseApiResponse<ProjectFlock>,
|
||||
'POST'
|
||||
>(`/approve`, {
|
||||
method: 'POST',
|
||||
payload: 'POST',
|
||||
params: {
|
||||
ids: selectedFlocks.map((flock) => flock.id).join(','),
|
||||
},
|
||||
});
|
||||
|
||||
if (isResponseSuccess(approveProjectFlockRes)) {
|
||||
toast.success('Project Flock berhasil di-approve!');
|
||||
confirmModal.closeModal();
|
||||
}
|
||||
if (isResponseError(approveProjectFlockRes)) {
|
||||
toast.error(approveProjectFlockRes?.message as string);
|
||||
confirmModal.closeModal();
|
||||
}
|
||||
setIsApproveLoading(false);
|
||||
};
|
||||
|
||||
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 justify-between items-end gap-2'>
|
||||
<div className='flex flex-col sm:flex-row gap-3 w-full'>
|
||||
<Button
|
||||
href='/production/project-flock/add'
|
||||
color='primary'
|
||||
className='w-full sm:w-fit'
|
||||
>
|
||||
<Icon icon='ic:round-plus' width={24} height={24} />
|
||||
Tambah
|
||||
</Button>
|
||||
<Button
|
||||
variant='outline'
|
||||
color='success'
|
||||
onClick={() => {
|
||||
if (selectedIds.length > 0) {
|
||||
confirmModal.openModal();
|
||||
}
|
||||
}}
|
||||
disabled={!(selectedIds.length > 0)}
|
||||
className='w-full sm:w-fit'
|
||||
>
|
||||
<Icon icon='material-symbols:check' width={24} height={24} />
|
||||
Approve
|
||||
</Button>
|
||||
<div className='ms-auto w-full sm:w-auto'>
|
||||
<DebouncedTextInput
|
||||
name='search'
|
||||
placeholder='Cari Area'
|
||||
value={tableFilterState.search}
|
||||
onChange={searchChangeHandler}
|
||||
className={{
|
||||
wrapper: 'w-full sm:max-w-3xs',
|
||||
input: 'w-full',
|
||||
inputWrapper: 'w-full',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className='hidden sm:flex flex-row justify-end gap-6 w-full'>
|
||||
<SelectInput
|
||||
label='Area'
|
||||
options={optionsArea}
|
||||
isLoading={isLoadingAreas}
|
||||
value={selectedArea}
|
||||
onChange={(val) => {
|
||||
setSelectedArea(val as OptionType);
|
||||
updateFilter(
|
||||
'areaFilter',
|
||||
(val as OptionType)?.value.toString()
|
||||
);
|
||||
}}
|
||||
onInputChange={setAreaSelectInputValue}
|
||||
isClearable
|
||||
/>
|
||||
<SelectInput
|
||||
label='Lokasi'
|
||||
options={optionsLocation}
|
||||
isLoading={isLoadingLocations}
|
||||
value={selectedLocation}
|
||||
onChange={(val) => {
|
||||
setSelectedLocation(val as OptionType);
|
||||
updateFilter(
|
||||
'locationFilter',
|
||||
(val as OptionType)?.value.toString()
|
||||
);
|
||||
}}
|
||||
onInputChange={setLocationSelectInputValue}
|
||||
isClearable
|
||||
/>
|
||||
<SelectInput
|
||||
label='Kandang'
|
||||
options={optionsKandang}
|
||||
isLoading={isLoadingKandang}
|
||||
value={selectedKandang}
|
||||
onChange={(val) => {
|
||||
setSelectedKandang(val as OptionType);
|
||||
updateFilter(
|
||||
'kandangFilter',
|
||||
(val as OptionType)?.value.toString()
|
||||
);
|
||||
}}
|
||||
onInputChange={setKandangSelectInputValue}
|
||||
isClearable
|
||||
/>
|
||||
<DebouncedTextInput
|
||||
name='period'
|
||||
type='number'
|
||||
label='Periode'
|
||||
placeholder='Masukan periode'
|
||||
value={periodInputValue ?? ''}
|
||||
onChange={(e) => {
|
||||
setPeriodInputValue(parseInt(e.target.value));
|
||||
updateFilter('periodFilter', e.target.value);
|
||||
}}
|
||||
/>
|
||||
<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,
|
||||
}}
|
||||
/>
|
||||
|
||||
<ConfirmationModal
|
||||
ref={confirmModal.ref}
|
||||
type='success'
|
||||
text={
|
||||
selectedFlocks.length > 0
|
||||
? `Apakah anda yakin ingin approve Project Flock berikut? (${selectedFlocks
|
||||
.map(
|
||||
(flock) =>
|
||||
`${flock.flock?.name ?? '(Tanpa nama)'} - ${
|
||||
flock.area?.name ?? '-'
|
||||
}`
|
||||
)
|
||||
.join(', ')})`
|
||||
: 'Tidak ada Project Flock yang dipilih.'
|
||||
}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'success',
|
||||
onClick: confirmationModalApproveClickHandler,
|
||||
isLoading: isApproveLoading,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProjectFlockTable;
|
||||
@@ -0,0 +1,61 @@
|
||||
import * as Yup from 'yup';
|
||||
|
||||
export const ProjectFlockFormSchema = Yup.object({
|
||||
// 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()
|
||||
.min(1, 'Flock wajib diisi!')
|
||||
.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()
|
||||
.min(1, 'Area wajib diisi!')
|
||||
.required('Area wajib diisi!'),
|
||||
|
||||
// Kategori
|
||||
category_option: Yup.object({
|
||||
value: Yup.string().required('Nilai Kategori wajib diisi!'),
|
||||
label: Yup.string().required('Label Kategori wajib diisi!'),
|
||||
}).nullable(),
|
||||
category: Yup.string().oneOf(['GROWING', 'LAYING'], 'Kategori wajib diisi!')
|
||||
.required('Kategori 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().min(1, 'FCR wajib diisi!').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()
|
||||
.min(1, 'Lokasi wajib diisi!')
|
||||
.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,814 @@
|
||||
'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,
|
||||
} from '@/services/api/master-data';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { useFormik } from 'formik';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import {
|
||||
ProjectFlockFormSchema,
|
||||
ProjectFlockFormValues,
|
||||
UpdateProjectFlockFormSchema,
|
||||
} from '@/components/pages/production/project-flock/form/ProjectFlockForm.schema';
|
||||
import {
|
||||
CreateProjectFlockPayload,
|
||||
PeriodFlock,
|
||||
ProjectFlock,
|
||||
} from '@/types/api/production/project-flock';
|
||||
import toast from 'react-hot-toast';
|
||||
import TextInput from '@/components/input/TextInput';
|
||||
import { Kandang } from '@/types/api/master-data/kandang';
|
||||
import Collapse from '@/components/Collapse';
|
||||
import { ProjectFlockApi } from '@/services/api/production';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import { FLOCK_CATEGORY_OPTIONS } from '@/config/constant';
|
||||
import { useModal } from '@/components/Modal';
|
||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||
|
||||
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 && initialValues?.kandangs?.length > 0
|
||||
);
|
||||
const [optionsKandang, setOptionsKandang] = useState<Kandang[]>(
|
||||
initialValues?.kandangs ?? []
|
||||
);
|
||||
|
||||
const [selectedFlock, setSelectedFlock] = useState<number>(
|
||||
initialValues?.flock?.id ?? 0
|
||||
);
|
||||
|
||||
const deleteModal = useModal();
|
||||
const confirmModal = useModal();
|
||||
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
const [isApproveLoading, setIsApproveLoading] = useState(false);
|
||||
|
||||
// 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 kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({
|
||||
search: '',
|
||||
location_id: selectedLocation == '' ? '0' : selectedLocation,
|
||||
}).toString()}`;
|
||||
const { data: kandang, isLoading: isLoadingKandang } = useSWR(
|
||||
kandangUrl,
|
||||
KandangApi.getAllFetcher
|
||||
);
|
||||
|
||||
const getPeriodFlocksUrl = `flocks/${selectedFlock}/periods`;
|
||||
|
||||
const { data: periodFlocks, isLoading: isLoadingPeriodFlocks } = useSWR(
|
||||
getPeriodFlocksUrl,
|
||||
() =>
|
||||
ProjectFlockApi.customRequest<BaseApiResponse<PeriodFlock>, 'GET'>(
|
||||
getPeriodFlocksUrl,
|
||||
{ method: 'GET' }
|
||||
)
|
||||
);
|
||||
|
||||
// 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,
|
||||
}))
|
||||
: [];
|
||||
|
||||
useEffect(() => {
|
||||
if (isResponseSuccess(locations)) {
|
||||
const options = locations.data.map((location) => ({
|
||||
value: location.id,
|
||||
label: location.name,
|
||||
}));
|
||||
setOptionsLocation(options);
|
||||
}
|
||||
}, [locations, setSelectedLocation]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isResponseSuccess(kandang)) {
|
||||
if (selectedLocation) {
|
||||
setOptionsKandang(kandang.data);
|
||||
setOpenSelectKandangs(true);
|
||||
} else {
|
||||
setOptionsKandang([]);
|
||||
setOpenSelectKandangs(false);
|
||||
formik.setFieldValue('kandang_ids', []);
|
||||
}
|
||||
}
|
||||
}, [kandang]);
|
||||
|
||||
// Options Handler
|
||||
const areaChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
formik.setFieldValue('area_id', (val as OptionType)?.value);
|
||||
formik.setFieldValue('area', val);
|
||||
|
||||
formik.setFieldTouched('area_id', true);
|
||||
|
||||
setSelectedArea((val as OptionType)?.value as string);
|
||||
setSelectedLocation('');
|
||||
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 categoryChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
formik.setFieldValue('category', (val as OptionType)?.value);
|
||||
formik.setFieldValue('category_option', val);
|
||||
formik.setFieldTouched('category', 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
|
||||
.filter(
|
||||
(kandang) =>
|
||||
kandang.status === 'NON_ACTIVE' ||
|
||||
formik.values.kandang_ids.includes(kandang.id)
|
||||
)
|
||||
.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.error(createProjectFlockRes?.message as string);
|
||||
}
|
||||
};
|
||||
const updateProjectFlockHandler = async (
|
||||
payload: CreateProjectFlockPayload
|
||||
) => {
|
||||
const updateProjectFlockRes = await ProjectFlockApi.update(
|
||||
initialValues?.id as number,
|
||||
payload
|
||||
);
|
||||
|
||||
if (isResponseSuccess(updateProjectFlockRes)) {
|
||||
toast.success(updateProjectFlockRes?.message as string);
|
||||
router.push('/production/project-flock');
|
||||
}
|
||||
if (isResponseError(updateProjectFlockRes)) {
|
||||
setProjectFlockFormErrorMessage(updateProjectFlockRes?.message as string);
|
||||
toast.error(updateProjectFlockRes?.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,
|
||||
category_option: initialValues?.category
|
||||
? {
|
||||
value: initialValues.category,
|
||||
label: initialValues.category,
|
||||
}
|
||||
: 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: initialValues?.area?.id ?? 0,
|
||||
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
|
||||
)[],
|
||||
};
|
||||
}, [initialValues]);
|
||||
|
||||
// Formik
|
||||
const formik = useFormik<ProjectFlockFormValues>({
|
||||
initialValues: formikInitialValues,
|
||||
enableReinitialize: true,
|
||||
validationSchema:
|
||||
formType == 'add' ? ProjectFlockFormSchema : UpdateProjectFlockFormSchema,
|
||||
validateOnBlur: true,
|
||||
validateOnChange: true,
|
||||
validateOnMount: true,
|
||||
onSubmit: async (values) => {
|
||||
setProjectFlockFormErrorMessage('');
|
||||
const payload: CreateProjectFlockPayload = {
|
||||
flock_id: values.flock_id as number,
|
||||
area_id: values.area_id as number,
|
||||
category: values.category as string,
|
||||
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 'edit':
|
||||
await updateProjectFlockHandler(payload);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const { setValues: formikSetValues } = formik;
|
||||
// Effect Initial
|
||||
useEffect(() => {
|
||||
if (formType == 'detail') {
|
||||
formik.setFieldValue('area', {
|
||||
value: initialValues?.area.id,
|
||||
label: initialValues?.area.name,
|
||||
});
|
||||
formik.setFieldValue('area_id', 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]);
|
||||
|
||||
// Aktifkan lokasi jika formType = 'detail'
|
||||
useEffect(() => {
|
||||
if (formType === 'detail') {
|
||||
setDisabledLocation(false);
|
||||
}
|
||||
}, [formType]);
|
||||
|
||||
// Set lokasi otomatis berdasarkan initialValues saat formType = 'detail'
|
||||
useEffect(() => {
|
||||
if (formType != 'add' && initialValues?.location?.id) {
|
||||
setSelectedLocation(initialValues.location?.id.toString());
|
||||
setDisabledLocation(false); // biar dropdown lokasi aktif juga
|
||||
}
|
||||
}, [formType, initialValues]);
|
||||
|
||||
useEffect(() => {
|
||||
formik.validateForm();
|
||||
}, [formik.values]);
|
||||
|
||||
useEffect(() => {
|
||||
if(isResponseSuccess(periodFlocks)){
|
||||
formik.setFieldValue('period', periodFlocks.data.next_period);
|
||||
}
|
||||
}, [periodFlocks]);
|
||||
|
||||
// Actions handler
|
||||
const confirmationModalDeleteClickHandler = async () => {
|
||||
setIsDeleteLoading(true);
|
||||
const deleteProjectFlockRes = await ProjectFlockApi.delete(
|
||||
initialValues?.id as number
|
||||
);
|
||||
|
||||
if (isResponseSuccess(deleteProjectFlockRes)) {
|
||||
toast.success(deleteProjectFlockRes?.message as string);
|
||||
router.push('/production/project-flock');
|
||||
}
|
||||
if (isResponseError(deleteProjectFlockRes)) {
|
||||
toast.error(deleteProjectFlockRes?.message as string);
|
||||
}
|
||||
setIsDeleteLoading(false);
|
||||
};
|
||||
|
||||
const confirmationModalApproveClickHandler = async () => {
|
||||
setIsApproveLoading(true);
|
||||
const approveProjectFlockRes = await ProjectFlockApi.customRequest<
|
||||
BaseApiResponse<ProjectFlock>,
|
||||
'POST'
|
||||
>(`/${initialValues?.id}/approve`, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
if (isResponseSuccess(approveProjectFlockRes)) {
|
||||
toast.success('Project Flock berhasil di-approve!');
|
||||
confirmModal.closeModal();
|
||||
}
|
||||
if (isResponseError(approveProjectFlockRes)) {
|
||||
toast.error(approveProjectFlockRes?.message as string);
|
||||
confirmModal.closeModal();
|
||||
}
|
||||
setIsApproveLoading(false);
|
||||
};
|
||||
|
||||
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>
|
||||
)}
|
||||
{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}
|
||||
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 sm:grid-cols-2 gap-4'>
|
||||
<SelectInput
|
||||
required
|
||||
label='Area'
|
||||
value={formik.values.area as OptionType}
|
||||
onChange={areaChangeHandler}
|
||||
options={optionsArea}
|
||||
isLoading={isLoadingAreas}
|
||||
isError={
|
||||
formik.touched.area_id && Boolean(formik.errors.area_id)
|
||||
}
|
||||
errorMessage={formik.errors.area_id as string}
|
||||
isClearable
|
||||
isDisabled={formType === 'detail'}
|
||||
/>
|
||||
<SelectInput
|
||||
required
|
||||
label='Flock'
|
||||
value={formik.values.flock as OptionType}
|
||||
onChange={(val) => {
|
||||
optionChangeHandler(val, 'flock');
|
||||
setSelectedFlock((val as OptionType)?.value as number);
|
||||
}}
|
||||
options={optionsFlock}
|
||||
isLoading={isLoadingFlocks}
|
||||
isError={
|
||||
formik.touched.flock_id && Boolean(formik.errors.flock_id)
|
||||
}
|
||||
errorMessage={formik.errors.flock_id 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_id &&
|
||||
Boolean(formik.errors.location_id)
|
||||
}
|
||||
errorMessage={formik.errors.location_id 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_id && Boolean(formik.errors.fcr_id)
|
||||
}
|
||||
errorMessage={formik.errors.fcr_id as string}
|
||||
isClearable
|
||||
isDisabled={formType === 'detail'}
|
||||
/>
|
||||
<SelectInput
|
||||
required
|
||||
label='Kategori'
|
||||
value={formik.values.category_option as OptionType}
|
||||
onChange={categoryChangeHandler}
|
||||
options={FLOCK_CATEGORY_OPTIONS}
|
||||
isError={
|
||||
formik.touched.category && Boolean(formik.errors.category)
|
||||
}
|
||||
errorMessage={formik.errors.category as string}
|
||||
isClearable
|
||||
isDisabled={formType === 'detail'}
|
||||
/>
|
||||
<TextInput
|
||||
required
|
||||
type='number'
|
||||
name='period'
|
||||
label='Periode'
|
||||
placeholder='Masukkan periode yang project'
|
||||
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'}
|
||||
disabled={true}
|
||||
isLoading={isLoadingPeriodFlocks}
|
||||
/>
|
||||
</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-${
|
||||
openSelectKandangs ? '180' : '0'
|
||||
} transition-transform hover:text-inherit`}
|
||||
>
|
||||
<Icon
|
||||
icon='material-symbols:keyboard-arrow-down'
|
||||
width={24}
|
||||
height={24}
|
||||
/>
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
className='sm:w-full'
|
||||
titleClassName='w-full p-0!'
|
||||
onOpenChange={setOpenSelectKandangs}
|
||||
open={openSelectKandangs}
|
||||
>
|
||||
<div className='overflow-x-auto'>
|
||||
{isLoadingKandang && (
|
||||
<span className="loading loading-dots loading-xl"></span>
|
||||
)}
|
||||
<table className='table'>
|
||||
{/* head */}
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<label>
|
||||
<input
|
||||
type='checkbox'
|
||||
checked={
|
||||
optionsKandang
|
||||
.filter(
|
||||
(k) =>
|
||||
k.status === 'NON_ACTIVE' ||
|
||||
formik.values.kandang_ids.includes(k.id)
|
||||
)
|
||||
.every((k) =>
|
||||
formik.values.kandang_ids.includes(k.id)
|
||||
) &&
|
||||
optionsKandang.filter(
|
||||
(k) =>
|
||||
k.status === 'NON_ACTIVE' ||
|
||||
formik.values.kandang_ids.includes(k.id)
|
||||
).length > 0
|
||||
}
|
||||
className='checkbox transition-none'
|
||||
disabled={
|
||||
formType === 'detail' ||
|
||||
optionsKandang.filter(
|
||||
(k) => k.status === 'NON_ACTIVE'
|
||||
).length == 0
|
||||
}
|
||||
onChange={
|
||||
formType === 'detail'
|
||||
? () => {}
|
||||
: kandangCheckAll
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</th>
|
||||
<th>Kandang</th>
|
||||
<th>Status</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 transition-none'
|
||||
checked={formik.values.kandang_ids.includes(
|
||||
kandang.id
|
||||
)}
|
||||
onChange={
|
||||
formType === 'detail'
|
||||
? () => {}
|
||||
: kandangChangeHandler
|
||||
}
|
||||
disabled={
|
||||
formType === 'detail' ||
|
||||
kandang.status != 'NON_ACTIVE'
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</th>
|
||||
<td>{kandang.name}</td>
|
||||
<td>{kandang.status}</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>
|
||||
{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
|
||||
ref={deleteModal.ref}
|
||||
type='error'
|
||||
text={`Apakah anda yakin ingin menghapus data Project Flock ini (${initialValues?.flock?.name} - ${initialValues?.area?.name})?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'error',
|
||||
isLoading: isDeleteLoading,
|
||||
onClick: confirmationModalDeleteClickHandler,
|
||||
}}
|
||||
/>
|
||||
|
||||
<ConfirmationModal
|
||||
ref={confirmModal.ref}
|
||||
type='success'
|
||||
text={`Apakah anda yakin ingin approve Project Flock berikut? (${initialValues?.flock?.name} - ${initialValues?.area?.name})?`}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'success',
|
||||
isLoading: isApproveLoading,
|
||||
onClick: confirmationModalApproveClickHandler,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProjectFlockForm;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
import { cn } from '@/lib/helper';
|
||||
import { Color } from '@/types/theme';
|
||||
|
||||
interface StepItemProps {
|
||||
children?: ReactNode;
|
||||
icon?: ReactNode;
|
||||
className?: string;
|
||||
color?: Color;
|
||||
}
|
||||
|
||||
const StepItem = ({ children, icon, className, color }: StepItemProps) => {
|
||||
const stepItemBaseClassName = cn('step', {
|
||||
'step-primary': color === 'primary',
|
||||
'step-secondary': color === 'secondary',
|
||||
'step-accent': color === 'accent',
|
||||
'step-neutral': color === 'neutral',
|
||||
'step-info': color === 'info',
|
||||
'step-success': color === 'success',
|
||||
'step-warning': color === 'warning',
|
||||
'step-error': color === 'error',
|
||||
});
|
||||
|
||||
return (
|
||||
<li className={cn(stepItemBaseClassName, className)}>
|
||||
<span className='step-icon'>{icon}</span>
|
||||
|
||||
<div>{children}</div>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
||||
export default StepItem;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { cn } from '@/lib/helper';
|
||||
|
||||
interface StepsProps {
|
||||
children?: ReactNode;
|
||||
className?: string;
|
||||
direction?: 'horizontal' | 'vertical';
|
||||
}
|
||||
|
||||
const Steps = ({ children, className, direction }: StepsProps) => {
|
||||
const stepsBaseClassName = cn('steps gap-2', {
|
||||
'steps-horizontal': direction === 'horizontal',
|
||||
'steps-vertical': direction === 'vertical',
|
||||
});
|
||||
|
||||
return (
|
||||
<ul className={cn(stepsBaseClassName, 'overflow-visible!', className)}>
|
||||
{children}
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
|
||||
export default Steps;
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Icon } from '@iconify/react';
|
||||
import Button from '../Button';
|
||||
import { cn } from '@/lib/helper';
|
||||
|
||||
interface TableRowOptionsProps {
|
||||
type?: 'dropdown' | 'collapse';
|
||||
recordId: string | number;
|
||||
basePath: string;
|
||||
onDelete?: () => void;
|
||||
queryParam?: string;
|
||||
showEdit?: boolean;
|
||||
showDelete?: boolean;
|
||||
}
|
||||
|
||||
export const TableRowOptions = ({
|
||||
type = 'dropdown',
|
||||
recordId,
|
||||
basePath,
|
||||
onDelete,
|
||||
queryParam = 'id',
|
||||
showEdit = true,
|
||||
showDelete = true,
|
||||
}: TableRowOptionsProps) => (
|
||||
<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={`${basePath}/detail/?${queryParam}=${recordId}`}
|
||||
variant='ghost'
|
||||
color='primary'
|
||||
className='justify-start text-sm'
|
||||
>
|
||||
<Icon icon='mdi:eye-outline' width={16} height={16} />
|
||||
Detail
|
||||
</Button>
|
||||
{showEdit && (
|
||||
<Button
|
||||
href={`${basePath}/detail/edit/?${queryParam}=${recordId}`}
|
||||
variant='ghost'
|
||||
color='warning'
|
||||
className='justify-start text-sm'
|
||||
>
|
||||
<Icon icon='mdi:pencil-outline' width={16} height={16} />
|
||||
Edit
|
||||
</Button>
|
||||
)}
|
||||
{showDelete && onDelete && (
|
||||
<Button
|
||||
onClick={onDelete}
|
||||
variant='ghost'
|
||||
color='error'
|
||||
className='text-error hover:text-inherit justify-start text-sm'
|
||||
>
|
||||
<Icon
|
||||
icon='mdi:delete-outline'
|
||||
width={16}
|
||||
height={16}
|
||||
className='justify-start text-sm'
|
||||
/>
|
||||
Delete
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,33 @@
|
||||
import SelectInput from '../input/SelectInput';
|
||||
|
||||
export interface OptionType {
|
||||
label: string;
|
||||
value: string | number;
|
||||
}
|
||||
|
||||
interface TableRowSizeSelectorProps {
|
||||
value: number;
|
||||
onChange: (val: OptionType | OptionType[] | null) => void;
|
||||
options: OptionType[];
|
||||
}
|
||||
|
||||
export const TableRowSizeSelector = ({
|
||||
value,
|
||||
onChange,
|
||||
options,
|
||||
}: TableRowSizeSelectorProps) => {
|
||||
return (
|
||||
<div className='flex flex-row justify-end'>
|
||||
<SelectInput
|
||||
label='Baris'
|
||||
options={options}
|
||||
value={{
|
||||
label: String(value),
|
||||
value: value,
|
||||
}}
|
||||
onChange={onChange}
|
||||
className={{ wrapper: 'max-w-28' }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Icon } from '@iconify/react';
|
||||
import Button from '../Button';
|
||||
import DebouncedTextInput from '../input/DebouncedTextInput';
|
||||
|
||||
interface TableToolbarProps {
|
||||
addButton?: {
|
||||
href: string;
|
||||
label: string;
|
||||
};
|
||||
search: {
|
||||
value: string;
|
||||
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
||||
placeholder?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const TableToolbar = ({ addButton, search }: TableToolbarProps) => {
|
||||
return (
|
||||
<div className='w-full flex flex-col sm:flex-row justify-between items-end sm:items-center gap-2'>
|
||||
{addButton && (
|
||||
<div className='flex flex-row'>
|
||||
<Button href={addButton.href} color='primary'>
|
||||
<Icon icon='ic:round-plus' width={24} height={24} />
|
||||
{addButton.label}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<DebouncedTextInput
|
||||
name='search'
|
||||
placeholder={search.placeholder || 'Cari...'}
|
||||
value={search.value}
|
||||
onChange={search.onChange}
|
||||
className={{ wrapper: 'sm:max-w-3xs' }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
+63
-12
@@ -12,6 +12,52 @@ export const MAIN_DRAWER_LINKS: MAIN_DRAWER_MENU[] = [
|
||||
icon: 'gg:chart',
|
||||
},
|
||||
|
||||
{
|
||||
title: 'Production',
|
||||
link: '/production',
|
||||
icon: 'material-symbols:conveyor-belt-outline-rounded',
|
||||
submenu: [
|
||||
{
|
||||
title: 'List Flock',
|
||||
link: '/production/project-flock',
|
||||
icon: 'material-symbols:list-alt-add-outline-rounded',
|
||||
},
|
||||
{
|
||||
title: 'Chick In',
|
||||
link: '/production/chickin',
|
||||
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',
|
||||
link: '/master-data',
|
||||
@@ -77,22 +123,16 @@ export const MAIN_DRAWER_LINKS: MAIN_DRAWER_MENU[] = [
|
||||
link: '/master-data/supplier',
|
||||
icon: 'material-symbols:add-business-outline-rounded',
|
||||
},
|
||||
{
|
||||
title: 'Flock',
|
||||
link: '/master-data/flock',
|
||||
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;
|
||||
|
||||
|
||||
export const ROWS_OPTIONS = [
|
||||
{
|
||||
label: '10',
|
||||
@@ -149,6 +189,17 @@ export const CATEGORY_OPTIONS = [
|
||||
},
|
||||
];
|
||||
|
||||
export const FLOCK_CATEGORY_OPTIONS = [
|
||||
{
|
||||
label: 'GROWING',
|
||||
value: 'GROWING',
|
||||
},
|
||||
{
|
||||
label: 'LAYING',
|
||||
value: 'LAYING',
|
||||
},
|
||||
];
|
||||
|
||||
export const PRODUCT_FLAG_OPTIONS = [
|
||||
{ label: 'DOC', value: 'DOC' },
|
||||
{ label: 'PAKAN', value: 'PAKAN' },
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
export function toFormData(
|
||||
value: unknown,
|
||||
form = new FormData(),
|
||||
parentKey?: string
|
||||
) {
|
||||
if (value === undefined || value === null) {
|
||||
if (parentKey) form.append(parentKey, '');
|
||||
return form;
|
||||
}
|
||||
|
||||
if (value instanceof File) {
|
||||
if (!parentKey) throw new Error('File must have a key');
|
||||
form.append(parentKey, value);
|
||||
return form;
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((v, i) => {
|
||||
const key = parentKey ? `${parentKey}[${i}]` : `${i}`;
|
||||
toFormData(v, form, key);
|
||||
});
|
||||
return form;
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
Object.entries(value as Record<string, unknown>).forEach(([k, v]) => {
|
||||
const key = parentKey ? `${parentKey}[${k}]` : k;
|
||||
toFormData(v, form, key);
|
||||
});
|
||||
return form;
|
||||
}
|
||||
|
||||
if (parentKey) form.append(parentKey, String(value));
|
||||
return form;
|
||||
}
|
||||
|
||||
export function containsFile(obj: unknown): boolean {
|
||||
if (!obj) return false;
|
||||
if (obj instanceof File) return true;
|
||||
if (Array.isArray(obj)) return obj.some(containsFile);
|
||||
if (typeof obj === 'object') {
|
||||
return Object.values(obj as Record<string, unknown>).some(containsFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -4,9 +4,11 @@ import { BaseApiResponse } from '@/types/api/api-general';
|
||||
|
||||
export class BaseApiService<T, CreatePayloadGeneric, UpdatePayloadGeneric> {
|
||||
basePath: string;
|
||||
header?: Record<string, string>;
|
||||
|
||||
constructor(basePath: string) {
|
||||
constructor(basePath: string, header?: Record<string, string>) {
|
||||
this.basePath = basePath;
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
async getAllFetcher(endpoint: string): Promise<BaseApiResponse<T[]>> {
|
||||
@@ -23,42 +25,52 @@ export class BaseApiService<T, CreatePayloadGeneric, UpdatePayloadGeneric> {
|
||||
if (axios.isAxiosError<BaseApiResponse<T>>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async create(payload: CreatePayloadGeneric) {
|
||||
const isFormData =
|
||||
typeof FormData !== 'undefined' && payload instanceof FormData;
|
||||
try {
|
||||
const headers = isFormData
|
||||
? { ...(this.header ?? {}) }
|
||||
: { 'Content-Type': 'application/json', ...(this.header ?? {}) };
|
||||
|
||||
const createRes = await httpClient<BaseApiResponse<T>>(this.basePath, {
|
||||
method: 'POST',
|
||||
body: payload,
|
||||
headers,
|
||||
});
|
||||
|
||||
return createRes;
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError<BaseApiResponse<T>>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async update(id: number, payload: UpdatePayloadGeneric) {
|
||||
const isFormData =
|
||||
typeof FormData !== 'undefined' && payload instanceof FormData;
|
||||
try {
|
||||
const updatePath = `${this.basePath}/${id}`;
|
||||
|
||||
const headers = isFormData
|
||||
? { ...(this.header ?? {}) }
|
||||
: { 'Content-Type': 'application/json', ...(this.header ?? {}) };
|
||||
|
||||
const updateRes = await httpClient<BaseApiResponse<T>>(updatePath, {
|
||||
method: 'PATCH',
|
||||
body: payload,
|
||||
headers,
|
||||
});
|
||||
|
||||
return updateRes;
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError<BaseApiResponse<T>>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -69,13 +81,47 @@ export class BaseApiService<T, CreatePayloadGeneric, UpdatePayloadGeneric> {
|
||||
const deleteRes = await httpClient<BaseApiResponse>(deletePath, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
return deleteRes;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError<BaseApiResponse>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async customRequest<ResponseType = T, PayloadType = unknown>(
|
||||
endpoint: string,
|
||||
options?: {
|
||||
method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
||||
payload?: PayloadType;
|
||||
params?: Record<string, string | number | boolean | undefined>;
|
||||
}
|
||||
): Promise<ResponseType | undefined> {
|
||||
try {
|
||||
const urlBase = endpoint.startsWith('http')
|
||||
? endpoint
|
||||
: `${this.basePath.replace(/\/$/, '')}/${endpoint.replace(/^\//, '')}`;
|
||||
|
||||
const url = options?.params
|
||||
? `${urlBase}?${new URLSearchParams(
|
||||
Object.entries(options.params).reduce((acc, [key, value]) => {
|
||||
if (value !== undefined) acc[key] = String(value);
|
||||
return acc;
|
||||
}, {} as Record<string, string>)
|
||||
)}`
|
||||
: urlBase;
|
||||
|
||||
const res = await httpClient<ResponseType>(url, {
|
||||
method: options?.method || 'GET',
|
||||
body: options?.payload,
|
||||
});
|
||||
|
||||
return res;
|
||||
} catch (error: unknown) {
|
||||
if (axios.isAxiosError<ResponseType>(error)) {
|
||||
return error.response?.data;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,33 @@
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
import {
|
||||
InventoryAdjustment,
|
||||
CreateInventoryAdjustmentPayload,
|
||||
CreateProductWarehousePayload,
|
||||
ProductWarehouse,
|
||||
UpdateProductWarehousePayload,
|
||||
} from '@/types/api/inventory/product-warehouse';
|
||||
import {
|
||||
CreateMovementPayload,
|
||||
Movement,
|
||||
UpdateMovementPayload,
|
||||
} from '@/types/api/inventory/movement';
|
||||
import {
|
||||
CreateInventoryAdjustmentPayload,
|
||||
InventoryAdjustment,
|
||||
} from '@/types/api/inventory/adjustment';
|
||||
import { BaseApiService } from './base';
|
||||
|
||||
export const ProductWarehouseApi = new BaseApiService<
|
||||
ProductWarehouse,
|
||||
CreateProductWarehousePayload,
|
||||
UpdateProductWarehousePayload
|
||||
>('/inventory/product-warehouses');
|
||||
|
||||
export const MovementApi = new BaseApiService<
|
||||
Movement,
|
||||
CreateMovementPayload,
|
||||
UpdateMovementPayload
|
||||
>('/inventory/transfers');
|
||||
|
||||
export const inventoryAdjustmentApi = new BaseApiService<
|
||||
InventoryAdjustment,
|
||||
CreateInventoryAdjustmentPayload,
|
||||
unknown
|
||||
>('/inventory/adjustments');
|
||||
InventoryAdjustment,
|
||||
CreateInventoryAdjustmentPayload,
|
||||
unknown
|
||||
>('/inventory/adjustments');
|
||||
|
||||
@@ -59,6 +59,11 @@ import {
|
||||
Fcr,
|
||||
UpdateFcrPayload,
|
||||
} from '@/types/api/master-data/fcr';
|
||||
import {
|
||||
CreateFlockPayload,
|
||||
Flock,
|
||||
UpdateFlockPayload,
|
||||
} from '@/types/api/master-data/flock';
|
||||
|
||||
export const UomApi = new BaseApiService<
|
||||
Uom,
|
||||
@@ -130,3 +135,9 @@ export const FcrApi = new BaseApiService<
|
||||
CreateFcrPayload,
|
||||
UpdateFcrPayload
|
||||
>('/master-data/fcrs');
|
||||
|
||||
export const FlockApi = new BaseApiService<
|
||||
Flock,
|
||||
CreateFlockPayload,
|
||||
UpdateFlockPayload
|
||||
>('/master-data/flocks');
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
ProjectFlock,
|
||||
CreateProjectFlockPayload,
|
||||
} from '@/types/api/production/project-flock';
|
||||
import {
|
||||
Chickin,
|
||||
CreateChickinPayload,
|
||||
UpdateChickinPayload,
|
||||
} from '@/types/api/production/chickin';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
|
||||
export const ProjectFlockApi = new BaseApiService<
|
||||
ProjectFlock,
|
||||
CreateProjectFlockPayload,
|
||||
unknown
|
||||
>('/production/project_flocks');
|
||||
export const ChickinApi = new BaseApiService<
|
||||
Chickin,
|
||||
CreateChickinPayload,
|
||||
UpdateChickinPayload
|
||||
>('/production/chickins');
|
||||
@@ -6,22 +6,43 @@ type AuthStore = {
|
||||
isLoadingUser?: boolean;
|
||||
setUser: (newUserData?: UserWithRoles) => void;
|
||||
setIsLoadingUser: (isLoading?: boolean) => void;
|
||||
permissionCheck: (permissionName: string) => boolean;
|
||||
};
|
||||
|
||||
const useAuthStore = create<AuthStore>()((set) => ({
|
||||
const useAuthStore = create<AuthStore>()((set, get) => ({
|
||||
user: undefined,
|
||||
isLoadingUser: false,
|
||||
setUser: (newUserData) => set({ user: newUserData }),
|
||||
setIsLoadingUser: (isLoading) => set({ isLoadingUser: Boolean(isLoading) }),
|
||||
|
||||
permissionCheck: (name) => {
|
||||
const { user, isLoadingUser } = get();
|
||||
|
||||
if (!isLoadingUser && user) {
|
||||
const isAllowed = user.roles.some((role) => {
|
||||
const isPermissionNameAllowed = role.permissions.some(
|
||||
(permission) => permission.name === name
|
||||
);
|
||||
|
||||
return isPermissionNameAllowed;
|
||||
});
|
||||
|
||||
return isAllowed;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
}));
|
||||
|
||||
export const useAuth = () => {
|
||||
const { user, setUser, isLoadingUser, setIsLoadingUser } = useAuthStore();
|
||||
const { user, setUser, isLoadingUser, setIsLoadingUser, permissionCheck } =
|
||||
useAuthStore();
|
||||
|
||||
return {
|
||||
user,
|
||||
setUser,
|
||||
isLoadingUser,
|
||||
setIsLoadingUser,
|
||||
permissionCheck,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,6 +14,9 @@ export async function httpClient<T, B = unknown>(
|
||||
(!opts.auth && opts.auth !== 'none' && opts.auth !== 'bearer');
|
||||
const isBearerAuth = opts.auth === 'bearer' && !!opts.token;
|
||||
|
||||
const isFormData =
|
||||
typeof FormData !== 'undefined' && opts.body instanceof FormData;
|
||||
|
||||
const config: AxiosRequestConfig = {
|
||||
url: path,
|
||||
method: opts.method ?? 'GET',
|
||||
@@ -22,7 +25,7 @@ export async function httpClient<T, B = unknown>(
|
||||
timeout: opts.timeoutMs ?? 10_000,
|
||||
withCredentials: isCookieAuth && !isBearerAuth,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(isFormData ? {} : { 'Content-Type': 'application/json' }),
|
||||
...(opts.headers ?? {}),
|
||||
...(isBearerAuth && !isCookieAuth
|
||||
? { Authorization: `Bearer ${opts.token}` }
|
||||
|
||||
@@ -4,7 +4,7 @@ import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
|
||||
import { UIStore } from '@/types/stores';
|
||||
import { createMainUiSlice } from './slices/main.slice';
|
||||
import { createMainUiSlice } from '@/stores/ui/slices/main.slice';
|
||||
|
||||
export const useUiStore = create<UIStore>()(
|
||||
devtools(
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
@layer utilities {
|
||||
.step.step-success::before {
|
||||
--step-bg: var(--color-success);
|
||||
--step-fg: var(--color-success-content);
|
||||
}
|
||||
|
||||
.step.step-error::before {
|
||||
--step-bg: var(--color-error);
|
||||
--step-fg: var(--color-error-content);
|
||||
}
|
||||
}
|
||||
Vendored
+38
@@ -24,6 +24,36 @@ export type LogoutResponse = BaseApiResponse;
|
||||
|
||||
export type GetMeResponse = BaseApiResponse<UserWithRoles>;
|
||||
|
||||
export type Client = {
|
||||
id: number;
|
||||
name: stirng;
|
||||
alias: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type Permission = {
|
||||
id: number;
|
||||
name: string;
|
||||
action: string;
|
||||
client: Omit<Client, 'created_at' | 'updated_at'>;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type Role = {
|
||||
id: number;
|
||||
key: string;
|
||||
name: string;
|
||||
client: Omit<Client, 'created_at' | 'updated_at'>;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type RoleWithPermissions = Omit<Role, 'created_at' | 'updated_at'> & {
|
||||
permissions: Omit<Permission, 'created_at' | 'updated_at'>[];
|
||||
};
|
||||
|
||||
export type User = {
|
||||
id: number;
|
||||
email: string;
|
||||
@@ -66,3 +96,11 @@ export type flags =
|
||||
| 'STARTER'
|
||||
| 'FINISHER'
|
||||
| 'OVK';
|
||||
|
||||
export type ApprovalsLine = {
|
||||
action_by?: string;
|
||||
date?: string;
|
||||
notes?: string;
|
||||
role?: string;
|
||||
status: 'approved' | 'rejected' | 'waiting';
|
||||
}[];
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { Product } from '@/types/api/master-data/product';
|
||||
import { Warehouse } from '../master-data/warehouse';
|
||||
import { Warehouse } from '@/types/api/master-data/warehouse';
|
||||
|
||||
export type BaseInventoryAdjustment = {
|
||||
id: number;
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
import { BaseMetadata } from '@/types/api/api-general';
|
||||
import { Supplier } from '@/types/api/master-data/supplier';
|
||||
|
||||
type MovementWarehouse = {
|
||||
id: number;
|
||||
name: string;
|
||||
location: {
|
||||
id: number;
|
||||
name: string;
|
||||
} | null;
|
||||
area: {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type BaseMovement = {
|
||||
id: number;
|
||||
transfer_reason: string;
|
||||
transfer_date: string;
|
||||
source_warehouse: MovementWarehouse;
|
||||
destination_warehouse: MovementWarehouse;
|
||||
details: {
|
||||
id: number;
|
||||
product: {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
quantity: number;
|
||||
before_quantity: number;
|
||||
after_quantity: number;
|
||||
}[];
|
||||
deliveries: {
|
||||
id: number;
|
||||
supplier: Supplier;
|
||||
vehicle_plate: string;
|
||||
driver_name: string;
|
||||
document_number: string;
|
||||
document_path: string;
|
||||
shipping_cost_item: number;
|
||||
shipping_cost_total: number;
|
||||
items: {
|
||||
id: number;
|
||||
stock_transfer_detail_id: number;
|
||||
quantity: number;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
|
||||
export type Movement = BaseMetadata & BaseMovement;
|
||||
|
||||
export type CreateMovementPayload = {
|
||||
transfer_reason: string;
|
||||
transfer_date: string;
|
||||
source_warehouse_id: number;
|
||||
destination_warehouse_id: number;
|
||||
products: {
|
||||
product_id: number;
|
||||
product_qty: number;
|
||||
}[];
|
||||
deliveries: {
|
||||
delivery_cost: number;
|
||||
delivery_cost_per_item: number;
|
||||
document_index?: number;
|
||||
driver_name: string;
|
||||
vehicle_plate: string;
|
||||
supplier_id: number;
|
||||
products: {
|
||||
product_id: number;
|
||||
product_qty: number;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
|
||||
export type UpdateMovementPayload = CreateMovementPayload;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { BaseMetadata } from '@/types/api/api-general';
|
||||
import { Warehouse } from '@/types/api/master-data/warehouse';
|
||||
import { Product } from '@/types/api/master-data/product';
|
||||
|
||||
export type BaseProductWarehouse = {
|
||||
id: number;
|
||||
product_id: number;
|
||||
warehouse_id: number;
|
||||
quantity: number;
|
||||
product: Product;
|
||||
warehouse: Warehouse;
|
||||
};
|
||||
|
||||
export type ProductWarehouse = BaseMetadata & BaseProductWarehouse;
|
||||
|
||||
export type CreateProductWarehousePayload = {
|
||||
product_id: number;
|
||||
warehouse_id: number;
|
||||
quantity: number;
|
||||
};
|
||||
|
||||
export type UpdateProductWarehousePayload = CreateProductWarehousePayload;
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import { BaseMetadata } from "@/types/api/api-general";
|
||||
|
||||
export type BaseFlock = {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type Flock = BaseMetadata & BaseFlock;
|
||||
|
||||
export type CreateFlockPayload = {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdateFlockPayload = CreateFlockPayload;
|
||||
+1
@@ -5,6 +5,7 @@ import { BaseUser } from '@/types/api/user';
|
||||
export type BaseKandang = {
|
||||
id: number;
|
||||
name: string;
|
||||
status: string;
|
||||
location: BaseLocation;
|
||||
pic: BaseUser;
|
||||
};
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { BaseMetadata } from "@/types/api/api-general";
|
||||
import { ProjectFlockKandang } from "@/types/api/production/project-flock-kandang";
|
||||
|
||||
export type BaseChickin = {
|
||||
id?: number;
|
||||
chick_in_date?: string;
|
||||
quantity?: number;
|
||||
note?: string;
|
||||
project_flock_kandang?: ProjectFlockKandang;
|
||||
}
|
||||
|
||||
export type Chickin = BaseMetadata & BaseChickin;
|
||||
|
||||
export type CreateChickinPayload = {
|
||||
project_flock_kandang_id: number;
|
||||
chick_in_date: string;
|
||||
}
|
||||
|
||||
export type UpdateChickinPayload = CreateChickinPayload;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Kandang } from "@/type/master-data/kandang";
|
||||
import { ProjectFlock } from "@/types/api/production/project-flock";
|
||||
|
||||
export type BaseProjectFlockKandang = {
|
||||
id: number;
|
||||
project_flock_id: number;
|
||||
kandang_id: number;
|
||||
kandang: Kandang;
|
||||
project_flock: ProjectFlock;
|
||||
}
|
||||
|
||||
export type ProjectFlockKandang = BaseProjectFlockKandang;
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
import { Area } from "@/types/api/master-data/area";
|
||||
import { Fcr } from "@/types/api/master-data/fcr";
|
||||
import { Flock } from "@/types/api/master-data/flock";
|
||||
import { Kandang } from "@/types/api/master-data/kandang";
|
||||
import { Location } from "@/types/api/master-data/location";
|
||||
import { BaseMetadata } from "@/types/api/api-general";
|
||||
|
||||
export type BaseProjectFlock = {
|
||||
id: number;
|
||||
name: string;
|
||||
status: string;
|
||||
flock: Flock;
|
||||
flock_id: number;
|
||||
area: Area;
|
||||
area_id: number;
|
||||
category: string;
|
||||
fcr: Fcr;
|
||||
fcr_id: number;
|
||||
location: Location;
|
||||
location_id: number;
|
||||
period: number;
|
||||
kandang_ids: number[];
|
||||
kandangs: Kandang[];
|
||||
}
|
||||
|
||||
export type PeriodFlock = {
|
||||
flock: Flock;
|
||||
next_period: number;
|
||||
}
|
||||
|
||||
|
||||
export type ProjectFlock = BaseMetadata & BaseProjectFlock
|
||||
|
||||
export type CreateProjectFlockPayload = {
|
||||
flock_id: number;
|
||||
area_id: number;
|
||||
category: string;
|
||||
fcr_id: number;
|
||||
location_id: number;
|
||||
period: number;
|
||||
kandang_ids: number[];
|
||||
}
|
||||
|
||||
export type UpdateProjectFlockPayload = CreateProjectFlockPayload;
|
||||
Reference in New Issue
Block a user