refactor(FE-106-91-339-238): Slicing UI Chickin DOC Refactored

This commit is contained in:
randy-ar
2025-11-04 13:24:10 +07:00
parent 219cbedbcd
commit d8637923bd
24 changed files with 780 additions and 709 deletions
@@ -9,7 +9,6 @@ import ConfirmationModal from '@/components/modal/ConfirmationModal';
import Table from '@/components/Table';
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
import RowOptionsMenuWrapper from '@/components/table/RowOptionsMenuWrapper';
import { ROWS_OPTIONS } from '@/config/constant';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { cn } from '@/lib/helper';
@@ -60,7 +59,7 @@ const RowOptionsMenu = ({
</Button>
{props.row.original.approval.step_name === 'Aktif' && (
<Button
href={`/production/chickin/add?projectFlockId=${props.row.original.id}`}
href={`/production/project-flock/chickin/add?projectFlockId=${props.row.original.id}`}
variant='ghost'
color='success'
className='justify-start text-sm'
@@ -84,13 +83,12 @@ const RowOptionsMenu = ({
onClick={deleteClickHandler}
variant='ghost'
color='error'
className='text-error hover:text-inherit'
className='text-error hover:text-inherit justify-start text-sm'
>
<Icon
icon='material-symbols:delete-outline-rounded'
width={16}
height={16}
className='justify-start text-sm'
/>
Delete
</Button>
@@ -499,7 +497,7 @@ const ProjectFlockTable = () => {
return (
<>
{currentPageSize > 1 && (
{currentPageSize > 2 && (
<RowDropdownOptions isLast2Rows={isLast2Rows}>
<RowOptionsMenu
type='dropdown'
@@ -509,7 +507,7 @@ const ProjectFlockTable = () => {
</RowDropdownOptions>
)}
{currentPageSize <= 1 && (
{currentPageSize <= 2 && (
<RowCollapseOptions>
<RowOptionsMenu
type='collapse'
@@ -576,18 +574,6 @@ const ProjectFlockTable = () => {
ref={confirmModal.ref}
type='success'
text={`Apakah anda yakin ingin reject data transfer ke laying ini (${selectedRowIds.length} data)?`}
// 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',
}}
@@ -0,0 +1,308 @@
'use client';
import Badge from '@/components/Badge';
import Button from '@/components/Button';
import Card from '@/components/Card';
import SelectInput, { OptionType } from '@/components/input/SelectInput';
import PillBadge from '@/components/PillBadge';
import Table from '@/components/Table';
import { isResponseSuccess } from '@/lib/api-helper';
import { cn } from '@/lib/helper';
import { ProjectFlockApi } from '@/services/api/production';
import { useTableFilter } from '@/services/hooks/useTableFilter';
import { Kandang } from '@/types/api/master-data/kandang';
import { ProjectFlock } from '@/types/api/production/project-flock';
import { Icon } from '@iconify/react';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import useSWR from 'swr';
const ProjectFlockChickinDetail = ({
projectFlockId,
}: {
projectFlockId: number | undefined;
}) => {
const router = useRouter();
// Tables Props
const { state: tableFilterState } = useTableFilter({
initial: { search: '' },
paramMap: { page: 'page', pageSize: 'limit' },
});
// States
const [searchProjectFlock, setSearchProjectFlock] = useState('');
const [selectedProjectFlock, setSelectedProjectFlock] =
useState<OptionType | null>(null);
const [projectFlock, setProjectFlock] = useState<ProjectFlock>();
// Fetch Data
const { data: listProjectFlock, isLoading: isLoadingListProjectFlock } =
useSWR(
`${ProjectFlockApi.basePath}?${new URLSearchParams({
search: searchProjectFlock,
}).toString()}`,
ProjectFlockApi.getAllFetcher
);
// Mapping Options
const options = isResponseSuccess(listProjectFlock)
? listProjectFlock?.data.map((projectFlock) => {
return {
value: projectFlock.id,
label: `${projectFlock?.flock?.name} - Periode ${projectFlock?.period}`,
};
})
: [];
// Handle Function
const handleChickinClick = async (kandang: Kandang) => {
router.push(
`/production/project-flock/chickin/add/kandang?projectFlockKandangId=${kandang.project_flock_kandang_id}&projectFlockId=${projectFlockId ?? selectedProjectFlock?.value}`
);
};
const handleChangeProjectFlock = (val: OptionType | null) => {
setSelectedProjectFlock(val);
if (isResponseSuccess(listProjectFlock) && val) {
const selected = listProjectFlock.data.find(
(pf) => pf.id === Number(val.value)
);
setProjectFlock(selected);
} else {
setProjectFlock(undefined);
}
if (projectFlockId) {
router.push('/production/project-flock/chickin/add');
}
if (!val && projectFlockId) {
router.push('/production/project-flock/chickin/add');
}
};
useEffect(() => {
if (projectFlockId && isResponseSuccess(listProjectFlock)) {
setProjectFlock(
listProjectFlock.data.find((pf) => pf.id === Number(projectFlockId))
);
}
}, [projectFlockId, listProjectFlock]);
return (
<>
<div className='flex flex-col gap-4 w-full my-4'>
<div className='max-w-full sm:max-w-1/2 md:max-w-3/5 lg:max-w-2/5'>
<SelectInput
required
label='Ganti Project Flock'
placeholder='Pilih Project Flock'
options={options}
onInputChange={(val) => {
setSearchProjectFlock(val);
}}
isLoading={isLoadingListProjectFlock}
value={
projectFlock
? {
label: `${projectFlock?.flock?.name}`,
value: projectFlock?.id,
}
: null
}
onChange={(val) => {
handleChangeProjectFlock(val as OptionType | null);
}}
isSearchable
isClearable
startAdornment={
projectFlock && (
<Badge
variant='soft'
color='success'
size='sm'
className={{
badge: 'whitespace-nowrap font-semibold',
}}
>
Periode {projectFlock?.period}
</Badge>
)
}
/>
</div>
</div>
<Card
title='Informasi Flock'
className={{
wrapper: 'w-full bg-white mb-3',
}}
>
<Table<ProjectFlock>
emptyContent={
<div className='w-full p-5 text-center'>
<span className='text-lg opacity-50'>
Pilih project flock terlebih dahulu...
</span>
</div>
}
data={projectFlock ? [projectFlock] : []}
columns={[
{
header: 'Area',
accessorKey: 'area.name',
},
{
header: 'Lokasi',
accessorKey: 'location.name',
},
{
header: 'Nama Flock',
accessorKey: 'flock.name',
},
{
header: 'Kategori',
accessorKey: 'category',
},
{
header: 'Status',
accessorKey: 'status',
cell: (props) => {
return props.row.original.approval?.step_name ? (
<PillBadge
color={(() => {
switch (
props.row.original.approval?.step_name.toUpperCase()
) {
case 'AKTIF':
return 'red';
case 'PENGAJUAN':
return 'green';
default:
return 'gray';
}
})()}
content={props.row.original.approval?.step_name
.toLowerCase()
.replace(/_/g, ' ')
.replace(/\b\w/g, (char) => char.toUpperCase())}
/>
) : (
'-'
);
},
},
{
header: 'Periode',
accessorKey: 'period',
},
{
header: 'FCR Layer',
accessorKey: 'fcr.name',
},
]}
page={undefined}
className={{
containerClassName: cn({
'mb-20': projectFlock && projectFlock.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',
}}
/>
</Card>
<Card
title='Daftar Kandang'
className={{
wrapper: 'w-full bg-white',
}}
>
<Table<Kandang>
emptyContent={
<div className='w-full p-5 text-center'>
<span className='text-lg opacity-50'>
Pilih project flock terlebih dahulu...
</span>
</div>
}
data={projectFlock ? projectFlock.kandangs : []}
columns={[
{
header: '#',
cell: (props) =>
tableFilterState.pageSize * (tableFilterState.page - 1) +
props.row.index +
1,
},
{
accessorFn: () => (projectFlock ? projectFlock.area.name : ''),
header: 'Area',
},
{
accessorFn: () =>
projectFlock ? projectFlock.location.name : '',
header: 'Lokasi',
},
{
accessorKey: 'name',
header: 'Kandang',
},
{
accessorKey: 'capacity',
header: 'Kapasitas',
},
{
accessorKey: 'pic.name',
header: 'Penanggung Jawab',
},
{
header: 'Aksi',
cell: (props) => {
return (
<>
<Button
color='success'
variant='outline'
onClick={() => {
handleChickinClick(props.row.original);
}}
>
<Icon
icon='mdi:home-import-outline'
width={24}
height={24}
/>
Chickin
</Button>
</>
);
},
},
]}
page={undefined}
className={{
containerClassName: cn({
'mb-20': projectFlock && projectFlock.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',
}}
/>
</Card>
</>
);
};
export default ProjectFlockChickinDetail;
@@ -77,7 +77,7 @@ const ProjectFlockForm = ({
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
const [isApproveLoading, setIsApproveLoading] = useState(false);
const [isApprovedDisabled, setIsApprovedDisabled] = useState(
initialValues?.approval.step_name == 'Pengajuan' ? false : true
initialValues?.approval?.step_name == 'Pengajuan' ? false : true
);
const [isRejectedDisabled, setIsRejectedDisabled] =
useState(!isApprovedDisabled);
@@ -726,7 +726,25 @@ const ProjectFlockForm = ({
</div>
</form>
{formType != 'add' && (
<div className='w-full'>
<div className='flex flex-row gap-2 mb-6'>
{formType != 'edit' && (
<Button
onClick={() => {
router.push(
`/production/project-flock/detail/edit?projectFlockId=${initialValues?.id}`
);
}}
color='warning'
>
<Icon
icon='mdi:pencil-outline'
width={16}
height={16}
className='justify-start text-sm'
/>
Edit
</Button>
)}
<Button
onClick={() => {
if (initialValues?.id) {
@@ -121,6 +121,10 @@ const ProjectFlockKandangTable = ({
);
},
},
{
accessorFn: (row) => row.capacity,
header: 'Kapasitas',
},
{
accessorFn: (row) => row.pic?.name,
header: 'Penanggung Jawab',