From 97acc17ca55e6d60e3c1ee11097eb0bee829647d Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Wed, 3 Jun 2026 14:05:06 +0700 Subject: [PATCH 1/3] feat: add inline edit for chick-in date in chickin logs - Add updateChickinDate method to ChickinService (PATCH /production/chickins/chick-in-date) - Add pencil icon button next to each chickin date in ChickLogsView - Clicking the icon toggles an inline DateInput with Simpan/Batal buttons - Save button is disabled and shows loading state while request is in flight Co-Authored-By: Claude Sonnet 4.6 --- .../chickin/form/tabs/ChickLogsView.tsx | 74 ++++++++++++++++++- src/services/api/production/chickin.ts | 24 ++++++ 2 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx index acb8c18b..6fbde87a 100644 --- a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx +++ b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx @@ -2,16 +2,17 @@ import Alert from '@/components/Alert'; import Button from '@/components/Button'; import Card from '@/components/Card'; import RequirePermission from '@/components/helper/RequirePermission'; +import DateInput from '@/components/input/DateInput'; import PillBadge from '@/components/PillBadge'; import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; import { formatDate, formatNumber } from '@/lib/helper'; import { ChickinApi } from '@/services/api/production/chickin'; +import { useChickinStore } from '@/stores/production/chickin/chickin.store'; import { BaseApproval } from '@/types/api/api-general'; import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang'; import { Icon } from '@iconify/react'; import { useState } from 'react'; import toast from 'react-hot-toast'; -import { useChickinStore } from '@/stores/production/chickin/chickin.store'; const ChickinLogsView = ({ initialValues, @@ -23,6 +24,9 @@ const ChickinLogsView = ({ rawDataApprovals: BaseApproval[]; }) => { const [chickinErrorMessage, setChickinErrorMessage] = useState(''); + const [editingChickinId, setEditingChickinId] = useState(null); + const [editDate, setEditDate] = useState(''); + const [isEditLoading, setIsEditLoading] = useState(false); const { openChickinApproveModal, openChickinDeleteModal } = useChickinStore(); const handleClickApprove = () => { @@ -44,6 +48,23 @@ const ChickinLogsView = ({ }); }; + const handleSaveChickinDate = async () => { + setIsEditLoading(true); + const res = await ChickinApi.updateChickinDate( + initialValues.id as number, + formatDate(editDate, 'YYYY-MM-DD') + ); + setIsEditLoading(false); + if (isResponseSuccess(res)) { + toast.success(res?.message as string); + setEditingChickinId(null); + afterSubmit && afterSubmit(); + } + if (isResponseError(res)) { + toast.error(res?.message as string); + } + }; + const handleDeleteChickin = (chickinId: number) => { openChickinDeleteModal(chickinId, async () => { const deleteRes = await ChickinApi.delete(chickinId); @@ -133,9 +154,54 @@ const ChickinLogsView = ({ {' '} Tanggal Chick In -
- {formatDate(chickin.chick_in_date, 'DD MMM YYYY')} -
+ {editingChickinId === chickin.id ? ( +
+ setEditDate(e.target.value)} + /> +
+ + +
+
+ ) : ( +
+ + {formatDate(chickin.chick_in_date, 'DD MMM YYYY')} + + +
+ )} {/* Kandang */} diff --git a/src/services/api/production/chickin.ts b/src/services/api/production/chickin.ts index 0efaa0f9..d250e450 100644 --- a/src/services/api/production/chickin.ts +++ b/src/services/api/production/chickin.ts @@ -6,6 +6,7 @@ import { import { BaseApiService } from '@/services/api/base'; import { BaseApiResponse } from '@/types/api/api-general'; import { httpClient } from '@/services/http/client'; +import axios from 'axios'; export class ChickinService extends BaseApiService< Chickin, @@ -16,6 +17,29 @@ export class ChickinService extends BaseApiService< super(basePath); } + async updateChickinDate( + projectFlockKandangId: number, + chickInDate: string + ): Promise | undefined> { + try { + return await httpClient>( + `${this.basePath}/chick-in-date`, + { + method: 'PATCH', + body: { + project_flock_kandang_id: projectFlockKandangId, + chick_in_date: chickInDate, + }, + } + ); + } catch (error: unknown) { + if (axios.isAxiosError>(error)) { + return error.response?.data; + } + return undefined; + } + } + /** * Approve single marketing data */ From f167916a21df70d401b473a0354510c05d0de77a Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Wed, 3 Jun 2026 14:20:43 +0700 Subject: [PATCH 2/3] fix: replace throw error with axios error handling in SalesOrderService and MarketingExportService All catch blocks in singleApproval, bulkApprovals (both classes), and delivery now return error.response?.data for axios errors and undefined otherwise, consistent with the BaseApiService pattern. Co-Authored-By: Claude Sonnet 4.6 --- src/services/api/marketing/marketing.ts | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/services/api/marketing/marketing.ts b/src/services/api/marketing/marketing.ts index 2cd225a5..4ded8cc2 100644 --- a/src/services/api/marketing/marketing.ts +++ b/src/services/api/marketing/marketing.ts @@ -45,8 +45,11 @@ export class SalesOrderService extends BaseApiService< notes: notes || `${action} marketing ${id}`, }, }); - } catch (error) { - throw error; + } catch (error: unknown) { + if (axios.isAxiosError>(error)) { + return error.response?.data; + } + return undefined; } } @@ -68,8 +71,11 @@ export class SalesOrderService extends BaseApiService< notes: notes || `${action} marketing ${ids.join(', ')}`, }, }); - } catch (error) { - throw error; + } catch (error: unknown) { + if (axios.isAxiosError>(error)) { + return error.response?.data; + } + return undefined; } } @@ -110,8 +116,11 @@ export class SalesOrderService extends BaseApiService< notes: notes || `Delivery marketing ${id}`, }, }); - } catch (error) { - throw error; + } catch (error: unknown) { + if (axios.isAxiosError>(error)) { + return error.response?.data; + } + return undefined; } } } @@ -142,8 +151,11 @@ class MarketingExportService extends BaseApiService< notes: notes, }, }); - } catch (error) { - throw error; + } catch (error: unknown) { + if (axios.isAxiosError>(error)) { + return error.response?.data; + } + return undefined; } } From 4151829cb8afe77fd6f34b6b38c6b6eb57859ddf Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Wed, 3 Jun 2026 14:24:39 +0700 Subject: [PATCH 3/3] fix: disabled deliver item button if is submitting and set the is loading prop --- src/components/pages/marketing/DeliveryOrderFormModal.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/pages/marketing/DeliveryOrderFormModal.tsx b/src/components/pages/marketing/DeliveryOrderFormModal.tsx index fe98603d..89783a9e 100644 --- a/src/components/pages/marketing/DeliveryOrderFormModal.tsx +++ b/src/components/pages/marketing/DeliveryOrderFormModal.tsx @@ -847,7 +847,8 @@ const DeliveryOrderFormModal = ({}: { initialValues?: Marketing }) => { } }} className='p-3 shadow-button-soft text-base-100 rounded-lg text-sm font-semibold' - disabled={deliveryRejected} + disabled={deliveryRejected || isLoading} + isLoading={isLoading} > {marketing?.data?.latest_approval?.step_number === 1 && 'Approve'}