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'} 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/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; } } 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 */