From f08fae4f77de45eace467609b1577ba62fd5d4af Mon Sep 17 00:00:00 2001 From: rstubryan Date: Wed, 31 Dec 2025 13:00:48 +0700 Subject: [PATCH 01/27] refactor(FE): Enable reinitialize and map expedition vendor --- .../form/order/PurchaseOrderAcceptApprovalForm.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx b/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx index d6ef5952..85d5a6e2 100644 --- a/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx +++ b/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx @@ -164,6 +164,7 @@ const PurchaseOrderAcceptApprovalForm = ({ validationSchema: PurchaseRequestAcceptApprovalFormSchema, validateOnChange: true, validateOnBlur: true, + enableReinitialize: true, onSubmit: async (values) => { const payload: CreateAcceptApprovalRequestPayload = { action: 'APPROVED', @@ -238,7 +239,12 @@ const PurchaseOrderAcceptApprovalForm = ({ travel_number: item.travel_number || '', travel_document_path: item.travel_document_path || '', vehicle_number: item.vehicle_number || '', - expedition_vendor: null, + expedition_vendor: item.expedition_vendor + ? { + value: item.expedition_vendor.id, + label: item.expedition_vendor.name, + } + : null, expedition_vendor_id: item.expedition_vendor_id || 0, received_qty: item.total_qty || '', transport_per_item: item.transport_per_item || '', From a5188950962fe30663c29490ff00e36168a42cc3 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 2 Jan 2026 08:47:08 +0700 Subject: [PATCH 02/27] refactor(FE): Conditionally render sampling and result sections --- .../detail/UniformityDetailsPreview.tsx | 83 ++++++++++--------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx b/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx index d98bba23..21be03d7 100644 --- a/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx +++ b/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx @@ -229,49 +229,52 @@ const UniformityDetailsPreview = ({ {/* Form Section */}
- {uniformity_details && uniformity_details.length > 0 ? ( + {info_umum || sampling || result ? (
{/* Sampling and Range */} -
-

Sampling and Range

- - data={samplingTableData} - columns={columnsSampling} - pageSize={4} - className={{ - containerClassName: 'mb-0', - paginationClassName: 'hidden', - }} - /> -
- {/* Result */} -
-

Result

- - data={resultTableData} - columns={resultColumns} - pageSize={4} - className={{ - containerClassName: 'mb-0', - paginationClassName: 'hidden', - }} - /> -
+ {sampling && ( +
+

Sampling and Range

+ + data={samplingTableData} + columns={columnsSampling} + pageSize={4} + className={{ + containerClassName: 'mb-0', + paginationClassName: 'hidden', + }} + /> +
+ )} - {/* Body Weight Details Button */} -
- -
- {/*{!uniformity_details || uniformity_details.length === 0 ? ( - <> - ) : null}*/} + {/* Result */} + {result && ( +
+

Result

+ + data={resultTableData} + columns={resultColumns} + pageSize={4} + className={{ + containerClassName: 'mb-0', + paginationClassName: 'hidden', + }} + /> +
+ )} + + {!uniformity_details || uniformity_details.length === 0 ? ( +
+ +
+ ) : null} {/* Body Weight Details */} {uniformity_details && uniformity_details.length > 0 && ( From b1f4b4dc4b2e821a55d170a89e10638bcfac6944 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 2 Jan 2026 09:03:42 +0700 Subject: [PATCH 03/27] refactor(FE): Refresh uniformities on successful mutation --- .../pages/production/uniformity/UniformityTable.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/pages/production/uniformity/UniformityTable.tsx b/src/components/pages/production/uniformity/UniformityTable.tsx index cf981732..c3851b85 100644 --- a/src/components/pages/production/uniformity/UniformityTable.tsx +++ b/src/components/pages/production/uniformity/UniformityTable.tsx @@ -355,6 +355,12 @@ const UniformityTable = ({ refresh }: { refresh?: () => void }) => { mutate: refreshUniformities, } = useSWR(uniformitySwrKey, UniformityApi.getAllFetcher); + useEffect(() => { + if (isSuccess) { + refreshUniformities(); + } + }, [isSuccess, refreshUniformities]); + // ===== FILTER HANDLERS ===== const handleFilterLocationChange = useCallback( (val: OptionType | OptionType[] | null) => { From 6a3d2c0dcd1fd9668ebc660b9c26b9cdefdebc6a Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 2 Jan 2026 09:07:30 +0700 Subject: [PATCH 04/27] refactor(FE): Drop refresh prop and simplify UniformityTable --- .../uniformity/UniformityPageWrapper.tsx | 4 +-- .../production/uniformity/UniformityTable.tsx | 26 +++++-------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/components/pages/production/uniformity/UniformityPageWrapper.tsx b/src/components/pages/production/uniformity/UniformityPageWrapper.tsx index bbc82665..ac14ebb5 100644 --- a/src/components/pages/production/uniformity/UniformityPageWrapper.tsx +++ b/src/components/pages/production/uniformity/UniformityPageWrapper.tsx @@ -41,9 +41,7 @@ export default function UniformityPageWrapper({ return ( <>
- !isOpen && router.push('/production/uniformity')} - /> +
{ - // Uniformity data is never locked - checkbox is always enabled - return false; -}; - -const canApproveRejectUniformity = (uniformity: Uniformity): boolean => { - return uniformity.status === 'CREATED' || uniformity.status === 'Pengajuan'; -}; - -interface UniformityPreviewData { - id: string; - label: string; - value: string; -} - const UniformityConfirmationPreview = ({ uniformity, }: { uniformity?: Uniformity; }) => { - const data: UniformityPreviewData[] = [ + const data: DetailOptionType[] = [ { id: 'tanggal', label: 'Tanggal', @@ -100,7 +88,7 @@ const UniformityConfirmationPreview = ({ }, ]; - const columns: ColumnDef[] = [ + const columns: ColumnDef[] = [ { accessorKey: 'label', header: 'Label', @@ -148,7 +136,7 @@ const UniformityConfirmationPreview = ({ ); }; -const UniformityTable = ({ refresh }: { refresh?: () => void }) => { +const UniformityTable = () => { const router = useRouter(); const searchParams = useSearchParams(); const isSuccess = useUniformityStore((s) => s.isSuccess); From 1c77deeee7eb1be0ed6b1cfbebf06ab94779314d Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 2 Jan 2026 10:00:14 +0700 Subject: [PATCH 05/27] refactor(FE): Move Movement FormData into API service --- .../inventory/movement/form/MovementForm.tsx | 35 ++++++++----------- src/services/api/inventory.ts | 32 +++++++++++++++-- src/types/api/inventory/movement.d.ts | 7 +++- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/components/pages/inventory/movement/form/MovementForm.tsx b/src/components/pages/inventory/movement/form/MovementForm.tsx index ae9b68d9..a4c24330 100644 --- a/src/components/pages/inventory/movement/form/MovementForm.tsx +++ b/src/components/pages/inventory/movement/form/MovementForm.tsx @@ -55,16 +55,8 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { // ===== FORM HANDLERS ===== 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 - ); + async (payload: CreateMovementPayload) => { + const res = await MovementApi.createMovement(payload); if (isResponseError(res)) { setMovementFormErrorMessage(res.message); return; @@ -218,20 +210,23 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { }); const payload: CreateMovementPayload = { - transfer_reason: values.transfer_reason, - transfer_date: values.transfer_date, - source_warehouse_id: values.source_warehouse_id, - destination_warehouse_id: values.destination_warehouse_id, - products: values.products.map((p) => ({ - product_id: p.product_id, - product_qty: parseInt(p.product_qty.toString()) || 0, - })), - deliveries: deliveriesPayload, + data: { + transfer_reason: values.transfer_reason, + transfer_date: values.transfer_date, + source_warehouse_id: values.source_warehouse_id, + destination_warehouse_id: values.destination_warehouse_id, + products: values.products.map((p) => ({ + product_id: p.product_id, + product_qty: parseInt(p.product_qty.toString()) || 0, + })), + deliveries: deliveriesPayload, + }, + documents: documents.length > 0 ? documents : undefined, }; switch (type) { case 'add': - await createMovementHandler(payload, documents); + await createMovementHandler(payload); break; } }, diff --git a/src/services/api/inventory.ts b/src/services/api/inventory.ts index fa406917..70a7c8f9 100644 --- a/src/services/api/inventory.ts +++ b/src/services/api/inventory.ts @@ -1,4 +1,5 @@ import { BaseApiService } from '@/services/api/base'; +import { BaseApiResponse } from '@/types/api/api-general'; import { CreateProductWarehousePayload, ProductWarehouse, @@ -20,11 +21,38 @@ export const ProductWarehouseApi = new BaseApiService< UpdateProductWarehousePayload >('/inventory/product-warehouses'); -export const MovementApi = new BaseApiService< +export class MovementApiService extends BaseApiService< Movement, CreateMovementPayload, unknown ->('/inventory/transfers'); +> { + constructor(basePath: string) { + super(basePath); + } + + async createMovement( + payload: CreateMovementPayload + ): Promise | undefined> { + const formData = new FormData(); + + // Append data as JSON string + formData.append('data', JSON.stringify(payload.data)); + + // Append documents if any + if (payload.documents && payload.documents.length > 0) { + payload.documents.forEach((file) => { + formData.append('documents', file); + }); + } + + return await this.customRequest>('', { + method: 'POST', + payload: formData as unknown as Record, + }); + } +} + +export const MovementApi = new MovementApiService('/inventory/transfers'); export const InventoryAdjustmentApi = new BaseApiService< InventoryAdjustment, diff --git a/src/types/api/inventory/movement.d.ts b/src/types/api/inventory/movement.d.ts index 53dfa61d..3114518f 100644 --- a/src/types/api/inventory/movement.d.ts +++ b/src/types/api/inventory/movement.d.ts @@ -49,7 +49,7 @@ export type BaseMovement = { export type Movement = BaseMetadata & BaseMovement; -export type CreateMovementPayload = { +export type CreateMovementPayloadData = { transfer_reason: string; transfer_date: string; source_warehouse_id: number; @@ -71,3 +71,8 @@ export type CreateMovementPayload = { }[]; }[]; }; + +export type CreateMovementPayload = { + data: CreateMovementPayloadData; + documents?: File[]; +}; From 57fa67c05a5821f9b43127469831a2d06e08a99a Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 2 Jan 2026 14:22:57 +0700 Subject: [PATCH 06/27] refactor(FE): Support MovementDocument in movement form --- .../movement/form/MovementForm.schema.ts | 13 ++-- .../inventory/movement/form/MovementForm.tsx | 67 +++++++++++++------ src/types/api/inventory/movement.d.ts | 9 +++ 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/components/pages/inventory/movement/form/MovementForm.schema.ts b/src/components/pages/inventory/movement/form/MovementForm.schema.ts index 5ea844ab..9b2c8557 100644 --- a/src/components/pages/inventory/movement/form/MovementForm.schema.ts +++ b/src/components/pages/inventory/movement/form/MovementForm.schema.ts @@ -1,5 +1,5 @@ import * as Yup from 'yup'; -import { Movement } from '@/types/api/inventory/movement'; +import { Movement, MovementDocument } from '@/types/api/inventory/movement'; type MovementFormSchemaType = { transfer_reason: string; @@ -29,7 +29,7 @@ type MovementFormSchemaType = { deliveries: { delivery_cost?: number | string; delivery_cost_per_item?: number | string; - document?: File | string | null; + document?: File | MovementDocument | null; document_path?: string | null; driver_name: string; vehicle_plate: string; @@ -61,7 +61,7 @@ export type ProductSchema = { export type DeliverySchema = { delivery_cost?: number | string; delivery_cost_per_item?: number | string; - document?: File | string | null; + document?: File | MovementDocument | null; document_path?: string | null; driver_name: string; vehicle_plate: string; @@ -129,13 +129,12 @@ const DeliveryObjectSchema: Yup.ObjectSchema = Yup.object({ }), document_path: Yup.string().optional(), document_index: Yup.number().optional(), - document: Yup.mixed() + document: Yup.mixed() .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; + return true; }), driver_name: Yup.string().required('Nama sopir wajib diisi!'), vehicle_plate: Yup.string().required('Plat nomor wajib diisi!'), @@ -241,7 +240,7 @@ export const getMovementFormInitialValues = ( 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: d.document ?? null, document_path: d.document_path ?? null, driver_name: d.driver_name ?? '', vehicle_plate: d.vehicle_plate ?? '', diff --git a/src/components/pages/inventory/movement/form/MovementForm.tsx b/src/components/pages/inventory/movement/form/MovementForm.tsx index a4c24330..3c49295e 100644 --- a/src/components/pages/inventory/movement/form/MovementForm.tsx +++ b/src/components/pages/inventory/movement/form/MovementForm.tsx @@ -35,6 +35,7 @@ import FileInput from '@/components/input/FileInput'; import CheckboxInput from '@/components/input/CheckboxInput'; import Badge from '@/components/Badge'; import Card from '@/components/Card'; +import { S3_PUBLIC_BASE_URL } from '@/config/constant'; interface MovementFormProps { type?: 'add' | 'edit' | 'detail'; @@ -1532,27 +1533,51 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { {type === 'detail' ? ( <>
- + {delivery.document_path ? ( + + ) : delivery.document && + delivery.document instanceof File === false ? ( + + ) : ( + + )}
) : ( diff --git a/src/types/api/inventory/movement.d.ts b/src/types/api/inventory/movement.d.ts index 3114518f..2f6caceb 100644 --- a/src/types/api/inventory/movement.d.ts +++ b/src/types/api/inventory/movement.d.ts @@ -14,6 +14,14 @@ type MovementWarehouse = { }; }; +export type MovementDocument = { + id: number; + path: string; + name: string; + ext: string; + size: number; +}; + export type BaseMovement = { id: number; transfer_reason: string; @@ -39,6 +47,7 @@ export type BaseMovement = { document_path: string; shipping_cost_item: number; shipping_cost_total: number; + document?: MovementDocument; items: { id: number; stock_transfer_detail_id: number; From 9562ce7b40deebc7d9ce3b0b6c2dcff98136f37d Mon Sep 17 00:00:00 2001 From: randy-ar Date: Fri, 2 Jan 2026 15:11:06 +0700 Subject: [PATCH 07/27] fix(FE): remove bypass permission in marketing detail and form page --- .../marketing/detail/MarketingDetail.tsx | 72 +++---------------- .../pages/marketing/form/MarketingForm.tsx | 19 +---- .../sales-order/SalesOrderProductForm.tsx | 5 +- .../table-view/DeliveryOrderProductTable.tsx | 60 ---------------- 4 files changed, 13 insertions(+), 143 deletions(-) diff --git a/src/components/pages/marketing/detail/MarketingDetail.tsx b/src/components/pages/marketing/detail/MarketingDetail.tsx index 4c9f1a34..677ea422 100644 --- a/src/components/pages/marketing/detail/MarketingDetail.tsx +++ b/src/components/pages/marketing/detail/MarketingDetail.tsx @@ -77,10 +77,6 @@ const MarketingDetail = ({ confirmationModal.openModal(); }; - const deliveryClickHandler = () => { - deliveryModal.openModal(); - }; - const deleteClickHandler = () => { deleteModal.openModal(); }; @@ -135,7 +131,7 @@ const MarketingDetail = ({
{initialValues?.latest_approval?.step_number == 1 && ( <> - {/* + - */} - + - {/* + - */} - + )} {initialValues?.latest_approval?.step_number != 1 && ( <> - {/* - */} - + )}
@@ -466,7 +426,7 @@ const MarketingDetail = ({
{initialValues?.latest_approval?.step_number != 3 && ( <> - {/* + - */} - + )} - {/* + - */} - +
- {/*
- {JSON.stringify(formik.values)} -
-
- {JSON.stringify(formik.errors)} -
*/} - {/* + - */} - + )} diff --git a/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx b/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx index 75aa3ba6..aa9dd9e8 100644 --- a/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx +++ b/src/components/pages/marketing/form/repeater/sales-order/SalesOrderProductForm.tsx @@ -11,7 +11,7 @@ import SelectInput, { useSelect, } from '@/components/input/SelectInput'; import { Kandang } from '@/types/api/master-data/kandang'; -import { KandangApi, WarehouseApi } from '@/services/api/master-data'; +import { WarehouseApi } from '@/services/api/master-data'; import { ProductWarehouse } from '@/types/api/inventory/product-warehouse'; import { ProductWarehouseApi } from '@/services/api/inventory'; import NumberInput from '@/components/input/NumberInput'; @@ -180,9 +180,6 @@ const SalesOrderProductForm = ({ )} - {/* - {JSON.stringify(formik.errors)} - */}
{ const cols = [ - // { - // id: 'select', - // header: ({ - // table, - // }: { - // table: TanStack.Table; - // }) => ( - //
- // - //
- // ), - // cell: ({ - // row, - // }: { - // row: TanStack.Row; - // }) => ( - //
- // - //
- // ), - // }, { accessorFn: (row: DeliveryOrderProductFormValues) => row.do_number, header: 'No. Pengiriman', @@ -188,18 +156,6 @@ const DeliveryOrderProductTable = ({ )} {!props.row.original.qty && '-'} - {/* {formType == 'add_deliver' && ( - - )} */}
), @@ -248,22 +204,6 @@ const DeliveryOrderProductTable = ({ Tambah Pengiriman - {/* {selectedRowIds.length > 0 && ( - - )} */} ); From c6e9e98ce182658c56fbcbf0706482ba11576823 Mon Sep 17 00:00:00 2001 From: kris Date: Sat, 3 Jan 2026 12:42:09 +0000 Subject: [PATCH 08/27] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e02ea8ee..e80a7e02 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ stages: # ========================================================== default: tags: - - self-hosted + - server-development-biznet interruptible: true # ========================================================== From 7579cd55332d25b61d6585b26e5daa47c4bfe424 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 5 Jan 2026 08:56:09 +0700 Subject: [PATCH 09/27] refactor(FE): Remove Kandang prop and center Uniformity gauge --- .../production/uniformity/UniformityChart.tsx | 3 --- .../uniformity/chart/UniformityGaugeChart.tsx | 20 ++++++------------- .../skeleton/UniformityGaugeChartSkeleton.tsx | 2 +- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/components/pages/production/uniformity/UniformityChart.tsx b/src/components/pages/production/uniformity/UniformityChart.tsx index 1b58b16c..233d9d67 100644 --- a/src/components/pages/production/uniformity/UniformityChart.tsx +++ b/src/components/pages/production/uniformity/UniformityChart.tsx @@ -72,7 +72,6 @@ const UniformityChart = () => { // const gaugeChartData: GaugeChartData = { // value: 0, // label: '', - // kandang: 'Kandang Cirangga', // week: 'Week 2', // currentValue: 512, // totalValue: 1024, @@ -81,7 +80,6 @@ const UniformityChart = () => { const gaugeChartData: GaugeChartData = { value: 52, label: 'Uniformity', - kandang: 'Kandang Cirangga', week: 'Week 2', currentValue: 512, totalValue: 1024, @@ -128,7 +126,6 @@ const UniformityChart = () => { = ({ value, label, - kandang, week, currentValue, totalValue, @@ -34,7 +31,7 @@ const UniformityGaugeChart: React.FC = ({ const inactiveColor = '#f0f0f0'; return ( -
+
@@ -76,18 +73,13 @@ const UniformityGaugeChart: React.FC = ({ -
-
- -
-
-
- {kandang} - - +
+
+
+ {week}
diff --git a/src/components/pages/production/uniformity/skeleton/UniformityGaugeChartSkeleton.tsx b/src/components/pages/production/uniformity/skeleton/UniformityGaugeChartSkeleton.tsx index 02ec70c1..436fab9a 100644 --- a/src/components/pages/production/uniformity/skeleton/UniformityGaugeChartSkeleton.tsx +++ b/src/components/pages/production/uniformity/skeleton/UniformityGaugeChartSkeleton.tsx @@ -28,7 +28,7 @@ const UniformityGaugeChartSkeleton: React.FC< const inactiveColor = '#f0f0f0'; return ( -
+
From 62b05bf9c0cb699d76f781b056f870168664afb0 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 5 Jan 2026 09:11:54 +0700 Subject: [PATCH 10/27] refactor(FE): Add week navigation to UniformityGaugeChart --- .../uniformity/chart/UniformityGaugeChart.tsx | 73 +++++++++++++------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/src/components/pages/production/uniformity/chart/UniformityGaugeChart.tsx b/src/components/pages/production/uniformity/chart/UniformityGaugeChart.tsx index e8d2a5ca..04fbef9c 100644 --- a/src/components/pages/production/uniformity/chart/UniformityGaugeChart.tsx +++ b/src/components/pages/production/uniformity/chart/UniformityGaugeChart.tsx @@ -1,7 +1,8 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Cell, Pie, PieChart, ResponsiveContainer } from 'recharts'; import Card from '@/components/Card'; import { formatNumber } from '@/lib/helper'; +import { Icon } from '@iconify/react'; interface UniformityGaugeChartProps { value: number; @@ -9,6 +10,9 @@ interface UniformityGaugeChartProps { week?: string; currentValue?: number; totalValue?: number; + onWeekChange?: (direction: 'prev' | 'next') => void; + hasPrevWeek?: boolean; + hasNextWeek?: boolean; } const UniformityGaugeChart: React.FC = ({ @@ -17,6 +21,9 @@ const UniformityGaugeChart: React.FC = ({ week, currentValue, totalValue, + onWeekChange, + hasPrevWeek = false, + hasNextWeek = false, }) => { const numberOfSegments = 50; const filledSegments = Math.round((value / 100) * numberOfSegments); @@ -70,29 +77,49 @@ const UniformityGaugeChart: React.FC = ({
- -
-
-
- - {week} - +
+ + +
+
+
+ + {week} + +
+
+ + {formatNumber(currentValue ?? 0)} + + From + + {formatNumber(totalValue ?? 0)} + +
-
- - {formatNumber(currentValue ?? 0)} - - From - {formatNumber(totalValue ?? 0)} -
-
-
-
+
+ + +
); }; From 5e3648b38526c308d7dab0530a097a0f63a7691b Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Mon, 5 Jan 2026 11:11:34 +0700 Subject: [PATCH 11/27] chore: update permission name from lti.finance.transaction to lti.finance.transactions --- src/components/pages/finance/FinanceDetail.tsx | 2 +- src/components/pages/finance/FinanceTable.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/pages/finance/FinanceDetail.tsx b/src/components/pages/finance/FinanceDetail.tsx index c7057efa..7f24178f 100644 --- a/src/components/pages/finance/FinanceDetail.tsx +++ b/src/components/pages/finance/FinanceDetail.tsx @@ -162,7 +162,7 @@ const FinanceDetail = ({ finance }: { finance: Finance }) => { )} - +
From f183ee5c7a54eebcda2a0d7e0e19cbe252332af3 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Mon, 5 Jan 2026 11:23:47 +0700 Subject: [PATCH 14/27] chore: update permission name --- src/config/route-permission.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/config/route-permission.ts b/src/config/route-permission.ts index 101dbb6d..c25f6981 100644 --- a/src/config/route-permission.ts +++ b/src/config/route-permission.ts @@ -75,8 +75,8 @@ export const ROUTE_PERMISSIONS: Record = { '/expense/realization/edit/': ['lti.expense.update.realization'], // Finance - '/finance/': ['lti.finance.transaction.list'], - '/finance/detail/': ['lti.finance.transaction.detail'], + '/finance/': ['lti.finance.transactions.list'], + '/finance/detail/': ['lti.finance.transactions.detail'], '/finance/add/': ['lti.finance.payments.create'], '/finance/detail/edit/': ['lti.finance.payments.update'], '/finance/add/initial-balance/': ['lti.finance.initial_balances.create'], @@ -94,10 +94,7 @@ export const ROUTE_PERMISSIONS: Record = { '/report/logistic-stock/': ['lti.repport.purchasesupplier.list'], '/report/expense/': ['lti.repport.expense.list'], '/report/marketing/': ['lti.repport.delivery.list'], - - // TODO: change to real permission - // '/report/production-result/': ['lti.repport.production_result.list'], - '/report/production-result/': ['lti.repport.delivery.list'], + '/report/production-result/': ['lti.repport.production_result.list'], // Inventory '/inventory/adjustment/': ['lti.inventory.list'], From 9838cf347ba07014076eb197aaacbfe1cff15e8a Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Mon, 5 Jan 2026 11:27:38 +0700 Subject: [PATCH 15/27] feat(FE-443,444): create exportProductionResultToExcel method --- src/services/api/report/production-result.ts | 260 ++++++++----------- 1 file changed, 115 insertions(+), 145 deletions(-) diff --git a/src/services/api/report/production-result.ts b/src/services/api/report/production-result.ts index 98997e9b..251e3eb4 100644 --- a/src/services/api/report/production-result.ts +++ b/src/services/api/report/production-result.ts @@ -1,145 +1,12 @@ -import { sleep } from '@/lib/helper'; +import * as XLSX from 'xlsx'; +import toast from 'react-hot-toast'; +import { formatDate } from '@/lib/helper'; +import { isResponseSuccess } from '@/lib/api-helper'; import { BaseApiService } from '@/services/api/base'; -import { httpClientFetcher } from '@/services/http/client'; +import { httpClient, httpClientFetcher } from '@/services/http/client'; import { BaseApiResponse } from '@/types/api/api-general'; import { ProductionResult } from '@/types/api/report/production-result'; - -// TODO: delete this dummy data -const PRODUCTION_RESULT_DUMMY_DATA: BaseApiResponse = { - code: 200, - status: 'success', - message: 'Get Laporan Hasil Produksi successfully', - meta: { - page: 1, - limit: 1, - total_pages: 2, - total_results: 2, - }, - data: [ - { - created_user: { - id: 1, - id_user: 1001, - email: 'user@example.com', - name: 'John Doe', - }, - project_flock: { - id: 1, - name: 'PROJECT', - category: 'LAYING', - kandang: { - id: 1, - name: 'Cikaum', - }, - }, - created_at: '2025-01-01T08:00:00Z', - updated_at: '2025-01-02T10:30:00Z', - - woa: 25, - - bw: 62.5, - std_bw: 60, - uniformity: 88, - std_uniformity: '90% up', - - dep_kum: 3.2, - dep_std: 2.5, - - butiran_utuh: 850, - butiran_putih: 50, - butiran_retak: 70, - butiran_pecah: 30, - butiran_jumlah: 1000, - total_butir: 1000, - - kg_utuh: 52.3, - kg_putih: 3.1, - kg_retak: 4.2, - kg_pecah: 1.9, - kg_jumlah: 61.5, - total_kg: 61.5, - - persen_utuh: 85, - persen_putih: 5, - persen_retak: 7, - persen_pecah: 3, - - hd: 92, - hd_std: 90, - fi: 115, - fi_std: 667, - em: 85, - em_std: 83, - ew: 62, - ew_std: 60, - fcr: 2.1, - fcr_std: 2.0, - hh: 96, - hh_std: 95, - }, - { - created_user: { - id: 1, - id_user: 1001, - email: 'user@example.com', - name: 'John Doe', - }, - project_flock: { - id: 1, - name: 'PROJECT', - category: 'LAYING', - kandang: { - id: 1, - name: 'Cikaum', - }, - }, - created_at: '2025-01-01T08:00:00Z', - updated_at: '2025-01-02T10:30:00Z', - - woa: 25, - - bw: 62.5, - std_bw: 60, - uniformity: 88, - std_uniformity: '90% up', - - dep_kum: 3.2, - dep_std: 2.5, - - butiran_utuh: 850, - butiran_putih: 50, - butiran_retak: 70, - butiran_pecah: 30, - butiran_jumlah: 1000, - total_butir: 1000, - - kg_utuh: 52.3, - kg_putih: 3.1, - kg_retak: 4.2, - kg_pecah: 1.9, - kg_jumlah: 61.5, - total_kg: 61.5, - - persen_utuh: 85, - persen_putih: 5, - persen_retak: 7, - persen_pecah: 3, - - hd: 92, - hd_std: 90, - fi: 115, - fi_std: 110, - em: 85, - em_std: 83, - ew: 62, - ew_std: 60, - fcr: 2.1, - fcr_std: 2.0, - hh: 96, - hh_std: 95, - }, - ], -}; +import { BaseProjectFlockKandang } from '@/types/api/production/project-flock-kandang'; export class ProductionResultReportApiService extends BaseApiService< ProductionResult, @@ -153,14 +20,117 @@ export class ProductionResultReportApiService extends BaseApiService< async getAllProductionResultFetcher( endpoint: string ): Promise> { - // return await httpClientFetcher>( - // endpoint - // ); + return await httpClientFetcher>( + endpoint + ); + } - await sleep(1000); + async exportProductionResultToExcel( + projectFlockKandangs: BaseProjectFlockKandang[] | null + ) { + try { + const mappedProductionResults: { + projectFlockKandang: BaseProjectFlockKandang; + productionResult: ProductionResult[] | null; + }[] = []; - return PRODUCTION_RESULT_DUMMY_DATA; + projectFlockKandangs?.forEach(async (projectFlockKandang) => { + const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`; + const getProductionResultRes = await httpClient< + BaseApiResponse + >(getProductionResultPath); + + mappedProductionResults.push({ + projectFlockKandang, + productionResult: isResponseSuccess(getProductionResultRes) + ? getProductionResultRes.data + : null, + }); + }); + + const rows = mappedProductionResults; + if (!rows || rows.length === 0) { + toast.error('Tidak ada data untuk diexport.'); + return; + } + + // Group by Project Flock Kandang Name + const groupedData: Record< + string, + Record[] + > = {}; + + rows.forEach((row) => { + const kandangName = row.projectFlockKandang.kandang.name || 'Unknown'; + if (!groupedData[kandangName]) { + groupedData[kandangName] = []; + } + + row.productionResult?.forEach((productionResult) => { + groupedData[kandangName].push({ + woa: productionResult.woa, + bw: productionResult.bw, + std_bw: productionResult.std_bw, + uniformity: productionResult.uniformity, + std_uniformity: productionResult.std_uniformity, + dep_kum: productionResult.dep_kum, + dep_std: productionResult.dep_std, + butiran_utuh: productionResult.butiran_utuh, + butiran_putih: productionResult.butiran_putih, + butiran_retak: productionResult.butiran_retak, + butiran_pecah: productionResult.butiran_pecah, + butiran_jumlah: productionResult.butiran_jumlah, + total_butir: productionResult.total_butir, + kg_utuh: productionResult.kg_utuh, + kg_putih: productionResult.kg_putih, + kg_retak: productionResult.kg_retak, + kg_pecah: productionResult.kg_pecah, + kg_jumlah: productionResult.kg_jumlah, + total_kg: productionResult.total_kg, + persen_utuh: productionResult.persen_utuh, + persen_putih: productionResult.persen_putih, + persen_retak: productionResult.persen_retak, + persen_pecah: productionResult.persen_pecah, + hd: productionResult.hd, + hd_std: productionResult.hd_std, + fi: productionResult.fi, + fi_std: productionResult.fi_std, + em: productionResult.em, + em_std: productionResult.em_std, + ew: productionResult.ew, + ew_std: productionResult.ew_std, + fcr: productionResult.fcr, + fcr_std: productionResult.fcr_std, + hh: productionResult.hh, + hh_std: productionResult.hh_std, + project_flock_name: productionResult.project_flock.name, + project_flock_category: productionResult.project_flock.category, + kandang_name: productionResult.project_flock.kandang.name, + created_at: formatDate(productionResult.created_at, 'YYYY-MM-DD'), + updated_at: formatDate(productionResult.updated_at, 'YYYY-MM-DD'), + }); + }); + }); + + const wb = XLSX.utils.book_new(); + + Object.keys(groupedData).forEach((sheetName) => { + const ws = XLSX.utils.json_to_sheet(groupedData[sheetName]); + // Sheet names cannot exceed 31 chars + const safeSheetName = sheetName.substring(0, 31); + XLSX.utils.book_append_sheet(wb, ws, safeSheetName); + }); + + const productionResultExcelFileName = `laporan-hasil-produksi-${formatDate(Date.now(), 'YYYY-MM-DD')}-${rows[0].projectFlockKandang.project_flock.flock_name}.xlsx`; + + XLSX.writeFile(wb, productionResultExcelFileName); + } catch (error) { + console.error(error); + toast.error('Gagal melakukan export laporan hasil produksi! Coba lagi.'); + } } } -export const ProductionResultReportApi = new ProductionResultReportApiService(); +export const ProductionResultReportApi = new ProductionResultReportApiService( + '/reports/production-result' +); From f9f4c5b67cf8f19c7b7d5fe3743dc160cf651b45 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Mon, 5 Jan 2026 11:30:28 +0700 Subject: [PATCH 16/27] Merge branch 'development' into feat/FE/US-81/production-result-report From 203782c25836437e0226ed708550e8aff9d39ed6 Mon Sep 17 00:00:00 2001 From: randy-ar Date: Mon, 5 Jan 2026 13:05:10 +0700 Subject: [PATCH 17/27] fix(FE): adjust permission finance --- src/components/pages/finance/FinanceDetail.tsx | 2 +- src/components/pages/finance/FinanceTable.tsx | 11 +++++++++-- src/config/route-permission.ts | 9 +++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/pages/finance/FinanceDetail.tsx b/src/components/pages/finance/FinanceDetail.tsx index c7057efa..7f24178f 100644 --- a/src/components/pages/finance/FinanceDetail.tsx +++ b/src/components/pages/finance/FinanceDetail.tsx @@ -162,7 +162,7 @@ const FinanceDetail = ({ finance }: { finance: Finance }) => { )} - + )} + {FINANCE_INJECTION_STATUS.includes(finance.transaction_type) && ( + + + + )}
@@ -124,14 +119,12 @@ const ClosingProductionDataTabContent = ({ /> @@ -148,17 +141,17 @@ const ClosingProductionDataTabContent = ({ /> @@ -191,17 +184,37 @@ const ClosingProductionDataTabContent = ({ /> + + + + - + + {/* Laying Specific Fields */} + {performance.hen_day_act !== undefined && ( + <> + + + + )} + + {performance.egg_mass !== undefined && ( + <> + + + + )} + + {performance.egg_weight !== undefined && ( + <> + + + + )} + + {performance.hen_housed_act !== undefined && ( + <> + + + + )} From d7ef86e24be11358a9d60f4d02628aeb6c2d6753 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 5 Jan 2026 13:46:21 +0700 Subject: [PATCH 22/27] refactor(FE): Add default page/limit to location and flock queries --- .../pages/production/uniformity/form/UniformityForm.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/pages/production/uniformity/form/UniformityForm.tsx b/src/components/pages/production/uniformity/form/UniformityForm.tsx index 2daac10d..bbca72f8 100644 --- a/src/components/pages/production/uniformity/form/UniformityForm.tsx +++ b/src/components/pages/production/uniformity/form/UniformityForm.tsx @@ -97,12 +97,16 @@ const UniformityForm = ({ setInputValue: setLocationSelectInputValue, options: locationOptions, isLoadingOptions: isLoadingLocations, - } = useSelect(LocationApi.basePath, 'id', 'name', 'search'); + } = useSelect(LocationApi.basePath, 'id', 'name', 'search', { + page: '1', + limit: '100', + }); // ===== FETCH PROJECT FLOCKS DATA ===== const projectFlocksUrl = useMemo(() => { const params = new URLSearchParams({ search: projectFlockSearchValue || '', + page: '1', limit: '100', }); if (selectedLocation) { @@ -141,6 +145,7 @@ const UniformityForm = ({ const approvedProjectFlockKandangsUrl = useMemo(() => { const params = new URLSearchParams({ step_name: 'Disetujui', + page: '1', limit: '100', }); return `${ProjectFlockKandangApi.basePath}?${params.toString()}`; From 2c29cffa456bcd5d817f08312e795fb3768ef247 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 5 Jan 2026 14:50:10 +0700 Subject: [PATCH 23/27] refactor(FE): Remove overflow-visible class from table wrapper --- src/components/pages/production/recording/RecordingTable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pages/production/recording/RecordingTable.tsx b/src/components/pages/production/recording/RecordingTable.tsx index e5bd30cb..39b17ef7 100644 --- a/src/components/pages/production/recording/RecordingTable.tsx +++ b/src/components/pages/production/recording/RecordingTable.tsx @@ -872,7 +872,7 @@ const RecordingTable = () => { 'mb-20': isResponseSuccess(recordings) && recordings?.data?.length === 0, }), - tableWrapperClassName: 'overflow-x-auto min-h-full overflow-visible!', + 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: From d2b19cbd7bdd1edba7c452c8a0ed488f8d73ddba Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 5 Jan 2026 15:07:09 +0700 Subject: [PATCH 24/27] refactor(FE): Force form remount on initialValues change --- .../order/PurchaseOrderAcceptApprovalForm.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx b/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx index 85d5a6e2..b90a7c91 100644 --- a/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx +++ b/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx @@ -52,9 +52,14 @@ const PurchaseOrderAcceptApprovalForm = ({ const searchParams = useSearchParams(); const [purchaseOrderFormErrorMessage, setPurchaseOrderFormErrorMessage] = useState(''); + const [key, setKey] = useState(0); const isRejected = initialValues?.latest_approval?.action === 'REJECTED'; + useEffect(() => { + setKey((prev) => prev + 1); + }, [initialValues?.id]); + // ===== UTILITY FUNCTIONS ===== const isRepeaterInputError = ( idx: number, @@ -164,7 +169,7 @@ const PurchaseOrderAcceptApprovalForm = ({ validationSchema: PurchaseRequestAcceptApprovalFormSchema, validateOnChange: true, validateOnBlur: true, - enableReinitialize: true, + enableReinitialize: false, onSubmit: async (values) => { const payload: CreateAcceptApprovalRequestPayload = { action: 'APPROVED', @@ -252,7 +257,7 @@ const PurchaseOrderAcceptApprovalForm = ({ }); formik.setFieldValue('items', updatedItems); } - }, [purchaseItems, initialValues]); + }, [purchaseItems, initialValues, key]); useEffect(() => { if ( @@ -342,7 +347,11 @@ const PurchaseOrderAcceptApprovalForm = ({ }; return ( -
+

{type === 'add' @@ -705,7 +714,9 @@ const PurchaseOrderAcceptApprovalForm = ({ color='warning' className='px-4' onClick={() => { - formik.resetForm(); + if (type === 'add') { + formik.resetForm(); + } setPurchaseOrderFormErrorMessage(''); onCancel?.(); onModalClose?.(); From fd32b55ad90db7cb1d9875caa719ca460bf6547c Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 5 Jan 2026 15:13:00 +0700 Subject: [PATCH 25/27] refactor(FE): Provide defaults for missing info_umum fields --- .../uniformity/detail/UniformityDetail.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/pages/production/uniformity/detail/UniformityDetail.tsx b/src/components/pages/production/uniformity/detail/UniformityDetail.tsx index 0cc39d9a..4d0cd887 100644 --- a/src/components/pages/production/uniformity/detail/UniformityDetail.tsx +++ b/src/components/pages/production/uniformity/detail/UniformityDetail.tsx @@ -119,11 +119,13 @@ const UniformityDetail: React.FC = ({ const statusValue = latest_approval?.action ?? '-'; const valueMap: Record = { - tanggal: formatDate(info_umum.tanggal, 'DD MMMM YYYY'), - 'lokasi-farm': info_umum.lokasi_farm, - 'project-flock': info_umum.project_flock, - kandang: info_umum.kandang, - 'document-name': info_umum.file_name, + tanggal: info_umum?.tanggal + ? formatDate(info_umum.tanggal, 'DD MMMM YYYY') + : '-', + 'lokasi-farm': info_umum?.lokasi_farm ?? '-', + 'project-flock': info_umum?.project_flock ?? '-', + kandang: info_umum?.kandang ?? '-', + 'document-name': info_umum?.file_name ?? '-', 'approval-status': statusValue, }; From c24aebe02d5b355c85401f6dc77dca9ec7e50121 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Mon, 5 Jan 2026 15:29:52 +0700 Subject: [PATCH 26/27] refactor(FE): Highlight ideal ranges in Uniformity charts --- .../production/uniformity/UniformityChart.tsx | 78 +++++++++++++++---- .../uniformity/chart/UniformityBarChart.tsx | 16 +++- 2 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/components/pages/production/uniformity/UniformityChart.tsx b/src/components/pages/production/uniformity/UniformityChart.tsx index 233d9d67..58a8f9c8 100644 --- a/src/components/pages/production/uniformity/UniformityChart.tsx +++ b/src/components/pages/production/uniformity/UniformityChart.tsx @@ -1,13 +1,15 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import Card from '@/components/Card'; import UniformityBarChart from '@/components/pages/production/uniformity/chart/UniformityBarChart'; import UniformityGaugeChart from '@/components/pages/production/uniformity/chart/UniformityGaugeChart'; import UniformityBarChartSkeleton from '@/components/pages/production/uniformity/skeleton/UniformityBarChartSkeleton'; import UniformityGaugeChartSkeleton from '@/components/pages/production/uniformity/skeleton/UniformityGaugeChartSkeleton'; +import { UniformityDetailItem } from '@/types/api/production/uniformity'; interface BarChartData { name: string; uv: number; + isIdeal?: boolean; } interface GaugeChartData { @@ -19,9 +21,18 @@ interface GaugeChartData { totalValue?: number; } -const UniformityChart = () => { - // TODO: Replace with actual API call - const barChartData: BarChartData[] = [ +interface UniformityChartProps { + barChartData?: BarChartData[]; + gaugeChartData?: GaugeChartData; + uniformityDetails?: UniformityDetailItem[]; +} + +const UniformityChart = ({ + barChartData: initialBarChartData, + gaugeChartData: initialGaugeChartData, + uniformityDetails, +}: UniformityChartProps) => { + const defaultBarChartData: BarChartData[] = [ { name: '48-52', uv: 80, @@ -68,16 +79,7 @@ const UniformityChart = () => { }, ]; - // TODO: Replace with actual API call - // const gaugeChartData: GaugeChartData = { - // value: 0, - // label: '', - // week: 'Week 2', - // currentValue: 512, - // totalValue: 1024, - // }; - - const gaugeChartData: GaugeChartData = { + const defaultGaugeChartData: GaugeChartData = { value: 52, label: 'Uniformity', week: 'Week 2', @@ -85,6 +87,48 @@ const UniformityChart = () => { totalValue: 1024, }; + const defaultUniformityDetails: UniformityDetailItem[] = [ + { id: 1, weight: 61, range: 'Ideal' }, + { id: 2, weight: 62, range: 'Ideal' }, + { id: 3, weight: 63, range: 'Ideal' }, + { id: 4, weight: 64, range: 'Ideal' }, + { id: 5, weight: 65, range: 'Ideal' }, + { id: 6, weight: 66, range: 'Ideal' }, + { id: 7, weight: 67, range: 'Ideal' }, + ]; + + const detailsToUse = uniformityDetails || defaultUniformityDetails; + + const barChartData = useMemo(() => { + const dataToProcess = initialBarChartData || defaultBarChartData; + + if (!detailsToUse || detailsToUse.length === 0) { + return dataToProcess; + } + + return dataToProcess.map((bar) => { + const rangeMatch = bar.name.match(/(\d+)-(\d+)/); + if (!rangeMatch) return bar; + + const minWeight = parseInt(rangeMatch[1], 10); + const maxWeight = parseInt(rangeMatch[2], 10); + + const hasIdealWeight = detailsToUse.some((detail) => { + const weight = detail.weight; + return ( + detail.range === 'Ideal' && weight >= minWeight && weight <= maxWeight + ); + }); + + return { + ...bar, + isIdeal: hasIdealWeight, + }; + }); + }, [initialBarChartData, detailsToUse]); + + const gaugeChartData = initialGaugeChartData || defaultGaugeChartData; + return (
{ )}

- {gaugeChartData.value === 0 ? ( + {gaugeChartData && gaugeChartData.value === 0 ? ( { > - ) : ( + ) : gaugeChartData ? ( { totalValue={gaugeChartData.totalValue} /> - )} + ) : null} ); }; diff --git a/src/components/pages/production/uniformity/chart/UniformityBarChart.tsx b/src/components/pages/production/uniformity/chart/UniformityBarChart.tsx index 5960a006..34dc134e 100644 --- a/src/components/pages/production/uniformity/chart/UniformityBarChart.tsx +++ b/src/components/pages/production/uniformity/chart/UniformityBarChart.tsx @@ -3,6 +3,7 @@ import { Bar, BarChart, CartesianGrid, + Cell, Rectangle, ResponsiveContainer, Tooltip, @@ -25,6 +26,7 @@ interface CustomTooltipProps { interface BarChartData { name: string; uv: number; + isIdeal?: boolean; } interface UniformityBarChartProps { @@ -105,9 +107,6 @@ const UniformityBarChart: React.FC = ({ data }) => { = ({ data }) => { radius={[25, 25, 0, 0]} /> } - /> + > + {data.map((entry, index) => ( + + ))} + ); From 24499d110aaf5f6a89ccac9db70ce6bbbfe8cef2 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Tue, 6 Jan 2026 08:36:23 +0700 Subject: [PATCH 27/27] refactor(FE): Refactor Uniformity charts to use API data --- .../production/uniformity/UniformityChart.tsx | 156 +++++++----------- .../production/uniformity/UniformityTable.tsx | 50 +++++- .../uniformity/chart/UniformityBarChart.tsx | 19 +++ 3 files changed, 125 insertions(+), 100 deletions(-) diff --git a/src/components/pages/production/uniformity/UniformityChart.tsx b/src/components/pages/production/uniformity/UniformityChart.tsx index 58a8f9c8..77d1608d 100644 --- a/src/components/pages/production/uniformity/UniformityChart.tsx +++ b/src/components/pages/production/uniformity/UniformityChart.tsx @@ -4,89 +4,20 @@ import UniformityBarChart from '@/components/pages/production/uniformity/chart/U import UniformityGaugeChart from '@/components/pages/production/uniformity/chart/UniformityGaugeChart'; import UniformityBarChartSkeleton from '@/components/pages/production/uniformity/skeleton/UniformityBarChartSkeleton'; import UniformityGaugeChartSkeleton from '@/components/pages/production/uniformity/skeleton/UniformityGaugeChartSkeleton'; -import { UniformityDetailItem } from '@/types/api/production/uniformity'; - -interface BarChartData { - name: string; - uv: number; - isIdeal?: boolean; -} - -interface GaugeChartData { - value: number; - label: string; - kandang?: string; - week?: string; - currentValue?: number; - totalValue?: number; -} +import { + UniformityDetailItem, + Uniformity, +} from '@/types/api/production/uniformity'; interface UniformityChartProps { - barChartData?: BarChartData[]; - gaugeChartData?: GaugeChartData; + uniformityData?: Uniformity | null; uniformityDetails?: UniformityDetailItem[]; } const UniformityChart = ({ - barChartData: initialBarChartData, - gaugeChartData: initialGaugeChartData, + uniformityData, uniformityDetails, }: UniformityChartProps) => { - const defaultBarChartData: BarChartData[] = [ - { - name: '48-52', - uv: 80, - }, - { - name: '52-56', - uv: 120, - }, - { - name: '56-60', - uv: 160, - }, - { - name: '60-64', - uv: 200, - }, - { - name: '64-68', - uv: 160, - }, - { - name: '68-72', - uv: 120, - }, - { - name: '72-76', - uv: 80, - }, - { - name: '76-80', - uv: 120, - }, - { - name: '84-88', - uv: 160, - }, - { - name: '88-92', - uv: 200, - }, - { - name: '92-96', - uv: 160, - }, - ]; - - const defaultGaugeChartData: GaugeChartData = { - value: 52, - label: 'Uniformity', - week: 'Week 2', - currentValue: 512, - totalValue: 1024, - }; - const defaultUniformityDetails: UniformityDetailItem[] = [ { id: 1, weight: 61, range: 'Ideal' }, { id: 2, weight: 62, range: 'Ideal' }, @@ -100,34 +31,63 @@ const UniformityChart = ({ const detailsToUse = uniformityDetails || defaultUniformityDetails; const barChartData = useMemo(() => { - const dataToProcess = initialBarChartData || defaultBarChartData; - - if (!detailsToUse || detailsToUse.length === 0) { - return dataToProcess; + if (!uniformityData) { + return []; } - return dataToProcess.map((bar) => { - const rangeMatch = bar.name.match(/(\d+)-(\d+)/); - if (!rangeMatch) return bar; + if (!detailsToUse || detailsToUse.length === 0) { + return []; + } - const minWeight = parseInt(rangeMatch[1], 10); - const maxWeight = parseInt(rangeMatch[2], 10); + const weights = detailsToUse.map((d) => d.weight); + const minWeight = Math.floor(Math.min(...weights) / 5) * 5; + const maxWeight = Math.ceil(Math.max(...weights) / 5) * 5; - const hasIdealWeight = detailsToUse.some((detail) => { - const weight = detail.weight; - return ( - detail.range === 'Ideal' && weight >= minWeight && weight <= maxWeight - ); - }); + const rangeSize = maxWeight - minWeight < 11 ? 4 : 5; + const ranges: string[] = []; + + for (let start = minWeight; start <= maxWeight; start += rangeSize) { + const end = start + rangeSize; + ranges.push(`${start}-${end}`); + } + + const totalIdealCount = detailsToUse.filter( + (d) => d.range === 'Ideal' + ).length; + + return ranges.map((range) => { + const [minStr, maxStr] = range.split('-').map(Number); + const min = minStr; + const max = maxStr; + + const birdsInRange = detailsToUse.filter( + (d) => d.weight >= min && d.weight < max + ).length; + + const hasIdeal = detailsToUse.some( + (d) => d.range === 'Ideal' && d.weight >= min && d.weight < max + ); return { - ...bar, - isIdeal: hasIdealWeight, + name: range, + uv: birdsInRange, + isIdeal: hasIdeal, + idealCount: hasIdeal ? totalIdealCount : undefined, }; }); - }, [initialBarChartData, detailsToUse]); + }, [uniformityData, detailsToUse]); - const gaugeChartData = initialGaugeChartData || defaultGaugeChartData; + const gaugeChartData = useMemo(() => { + if (!uniformityData) return undefined; + + return { + value: uniformityData.uniformity, + label: 'Uniformity', + week: `Week ${uniformityData.week}`, + currentValue: uniformityData.uniform_qty, + totalValue: uniformityData.chick_qty_of_weight, + }; + }, [uniformityData]); return (
@@ -140,14 +100,14 @@ const UniformityChart = ({ }} >
- {barChartData.length === 0 ? ( + {!uniformityData || barChartData.length === 0 ? ( ) : ( )}
- {gaugeChartData && gaugeChartData.value === 0 ? ( + {!uniformityData || !gaugeChartData ? ( - ) : gaugeChartData ? ( + ) : ( - ) : null} + )}
); }; diff --git a/src/components/pages/production/uniformity/UniformityTable.tsx b/src/components/pages/production/uniformity/UniformityTable.tsx index 0a7483f2..e031e2c4 100644 --- a/src/components/pages/production/uniformity/UniformityTable.tsx +++ b/src/components/pages/production/uniformity/UniformityTable.tsx @@ -13,6 +13,7 @@ import { UniformityApi } from '@/services/api/uniformity'; import { DetailOptionType, type Uniformity, + type UniformityDetail, } from '@/types/api/production/uniformity'; import { isResponseSuccess } from '@/lib/api-helper'; import { type BaseApiResponse } from '@/types/api/api-general'; @@ -79,7 +80,7 @@ const UniformityConfirmationPreview = ({ { id: 'file-uniformity', label: 'File Uniformity', - value: '-', // File name tidak tersedia di GET ALL response + value: '-', }, { id: 'status', @@ -136,6 +137,51 @@ const UniformityConfirmationPreview = ({ ); }; +const UniformityChartWrapper = ({ + uniformitySwrKey, +}: { + uniformitySwrKey: string; +}) => { + const { data: uniformities } = useSWR( + uniformitySwrKey, + UniformityApi.getAllFetcher + ); + + const uniformityData = useMemo(() => { + if (isResponseSuccess(uniformities) && uniformities?.data?.length > 0) { + return uniformities.data[0]; + } + return null; + }, [uniformities]); + + const shouldFetchDetails = !!uniformityData; + const uniformityDetailSwrKey = useMemo(() => { + if (!uniformityData) return null; + return `${UniformityApi.basePath}/${uniformityData.id}?with_details=true`; + }, [uniformityData]); + + const { data: uniformityDetailResponse } = useSWR( + uniformityDetailSwrKey, + shouldFetchDetails ? UniformityApi.getAllFetcher : null + ); + + const uniformityDetails = useMemo(() => { + if (shouldFetchDetails && isResponseSuccess(uniformityDetailResponse)) { + const detailData = + uniformityDetailResponse.data as unknown as UniformityDetail; + return detailData.uniformity_details; + } + return undefined; + }, [shouldFetchDetails, uniformityDetailResponse]); + + return ( + + ); +}; + const UniformityTable = () => { const router = useRouter(); const searchParams = useSearchParams(); @@ -830,7 +876,7 @@ const UniformityTable = () => {
- +
+

Uniformity 2025

+
+
+
+ {chartData.idealCount} of Birds +
+ {labelStr} +
+ + ); + } + return (

Uniformity 2025