fix(FE): adding capacity to kandang and change confirmation modal marketing with note

This commit is contained in:
randy-ar
2025-11-19 13:00:21 +07:00
parent 8662bcb63b
commit 429f2b9109
7 changed files with 97 additions and 40 deletions
@@ -50,6 +50,7 @@ const ConfirmationModalWithNotes: React.FC<ConfirmationModalWithNotesProps> = ({
...primaryButton,
onClick: () => {
primaryButton?.onClick?.(notes);
setNotes('');
},
}}
secondaryButton={secondaryButton}
@@ -5,6 +5,7 @@ import CheckboxInput from '@/components/input/CheckboxInput';
import { OptionType } from '@/components/input/SelectInput';
import Modal, { useModal } from '@/components/Modal';
import ConfirmationModal from '@/components/modal/ConfirmationModal';
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
import Table from '@/components/Table';
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
@@ -170,7 +171,7 @@ const SalesOrderTable = () => {
.filter((row) => row.latest_approval.step_number === 2)
.map((row) => row.id);
const approveMarketingHandler = async () => {
const approveMarketingHandler = async (notes: string) => {
let idsToProcess: number[] = [];
if (approveAction === 'APPROVED') {
@@ -191,7 +192,8 @@ const SalesOrderTable = () => {
const approveMarketingRes = await SalesOrderApi.bulkApprovals(
idsToProcess,
approveAction
approveAction,
notes
);
if (isResponseSuccess(approveMarketingRes)) {
@@ -450,10 +452,10 @@ const SalesOrderTable = () => {
}}
/>
<ConfirmationModal
<ConfirmationModalWithNotes
ref={confirmationModal.ref}
type={approveAction === 'APPROVED' ? 'success' : 'error'}
text={`Apakah anda yakin ingin ${approveAction} data penjualan (${idsToProcess.length} data)?`}
text={`Apakah anda yakin ingin ${approveAction == 'APPROVED' ? 'approve' : 'reject'} data penjualan (${idsToProcess.length} data)?`}
secondaryButton={{
text: 'Tidak',
onClick: confirmationModal.closeModal,
@@ -5,6 +5,7 @@ import Card from '@/components/Card';
import { FormHeader } from '@/components/helper/form/FormHeader';
import { useModal } from '@/components/Modal';
import ConfirmationModal from '@/components/modal/ConfirmationModal';
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
import ApprovalSteps, {
useApprovalSteps,
} from '@/components/pages/ApprovalSteps';
@@ -78,11 +79,12 @@ const SalesOrderDetail = ({
refresh?.();
};
const confirmationModalApproveClickHandler = async () => {
const confirmationModalApproveClickHandler = async (notes: string) => {
setIsLoading(true);
const res = await SalesOrderApi.singleApproval(
initialValues?.id as number,
approvalAction
approvalAction,
notes
);
setIsLoading(false);
confirmationModal.closeModal();
@@ -91,13 +93,17 @@ const SalesOrderDetail = ({
refreshApproval?.();
};
const confirmationModalDeliveryClickHandler = async () => {
const confirmationModalDeliveryClickHandler = async (notes: string) => {
setIsLoading(true);
// await MarketingApi.delivery(initialValues?.id as number);
const res = await SalesOrderApi.delivery(
initialValues?.id as number,
notes
);
setIsLoading(false);
deliveryModal.closeModal();
toast.success('Successfully delivered Sales Order!');
toast.success(res?.message as string);
refresh?.();
refreshApproval?.();
};
return (
@@ -285,7 +291,7 @@ const SalesOrderDetail = ({
onClick: confirmationModalDeleteClickHandler,
}}
/>
<ConfirmationModal
<ConfirmationModalWithNotes
ref={confirmationModal.ref}
type={approvalAction === 'APPROVED' ? 'success' : 'error'}
text={`Apakah anda yakin ingin ${approvalAction} data penjualan ini?`}
@@ -299,7 +305,7 @@ const SalesOrderDetail = ({
onClick: confirmationModalApproveClickHandler,
}}
/>
<ConfirmationModal
<ConfirmationModalWithNotes
ref={deliveryModal.ref}
type={'success'}
text={`Apakah anda yakin ingin deliver penjualan ini?`}
@@ -303,9 +303,9 @@ const SalesForm = ({
wrapper: 'bg-white w-full',
}}
>
{/* <div className='text-blue-500'>{JSON.stringify(initialValues)}</div>
<div className='text-blue-500'>{JSON.stringify(initialValues)}</div>
<div className='text-green-500'>{JSON.stringify(formik.values)}</div>
<div className='text-red-500'>{JSON.stringify(formik.errors)}</div> */}
<div className='text-red-500'>{JSON.stringify(formik.errors)}</div>
<SalesOrderProductTable
data={memoSalesOrder}
rowSelection={rowSelection}
@@ -1,6 +1,28 @@
import * as Yup from 'yup';
export const KandangFormSchema = Yup.object({
type KandangFormSchemaType = {
name: string;
locationId: number | undefined;
location:
| {
value: number;
label: string;
}
| undefined
| null;
capacity: number | undefined;
picId: number | undefined;
pic:
| {
value: number;
label: string;
}
| undefined
| null;
};
export const KandangFormSchema: Yup.ObjectSchema<KandangFormSchemaType> =
Yup.object({
name: Yup.string().required('Nama wajib diisi!'),
locationId: Yup.number()
@@ -82,7 +82,7 @@ const KandangForm = ({ type = 'add', initialValues }: KandangFormProps) => {
label: initialValues.location.name,
}
: null,
capacity: initialValues?.capacity ?? 0,
capacity: initialValues?.capacity,
picId: initialValues?.pic?.id ?? 0,
pic: initialValues?.pic
? {
@@ -102,9 +102,9 @@ const KandangForm = ({ type = 'add', initialValues }: KandangFormProps) => {
const kandangPayload: CreateKandangPayload = {
name: values.name,
location_id: values.locationId,
capacity: values.capacity,
pic_id: values.picId,
location_id: values.locationId!,
capacity: values.capacity ? parseInt(values.capacity.toString()) : 0,
pic_id: values.picId!,
};
switch (type) {
@@ -256,7 +256,8 @@ const KandangForm = ({ type = 'add', initialValues }: KandangFormProps) => {
required
name='capacity'
label='Kapasitas'
value={formik.values.capacity ?? undefined}
placeholder='Masukan kapasitas kandang'
value={formik.values.capacity}
onChange={formik.handleChange}
onBlur={formik.handleBlur}
isError={
+29 -4
View File
@@ -69,7 +69,8 @@ export class SalesOrderService extends BaseApiService<
*/
async singleApproval(
id: number,
action: 'APPROVED' | 'REJECTED'
action: 'APPROVED' | 'REJECTED',
notes?: string
): Promise<BaseApiResponse<{ message: string }> | undefined> {
try {
const path = `${this.basePath}/approvals`;
@@ -78,7 +79,7 @@ export class SalesOrderService extends BaseApiService<
body: {
action: action,
approvable_ids: [id],
notes: `${action} marketing ${id}`,
notes: notes || `${action} marketing ${id}`,
},
});
} catch (error) {
@@ -92,7 +93,8 @@ export class SalesOrderService extends BaseApiService<
*/
async bulkApprovals(
ids: number[],
action: 'APPROVED' | 'REJECTED'
action: 'APPROVED' | 'REJECTED',
notes?: string
): Promise<BaseApiResponse<{ message: string }> | undefined> {
try {
const path = `${this.basePath}/approvals`;
@@ -101,7 +103,7 @@ export class SalesOrderService extends BaseApiService<
body: {
action: action,
approvable_ids: ids,
notes: `${action} marketing ${ids.join(', ')}`,
notes: notes || `${action} marketing ${ids.join(', ')}`,
},
});
} catch (error) {
@@ -109,6 +111,29 @@ export class SalesOrderService extends BaseApiService<
return undefined;
}
}
/**
* Delivery
*/
async delivery(
id: number,
notes?: string
): Promise<BaseApiResponse<{ message: string }> | undefined> {
try {
const path = `${this.basePath}/deliveries`;
return await httpClient<BaseApiResponse<{ message: string }>>(path, {
method: 'POST',
body: {
action: 'APPROVED',
approvable_ids: [id],
notes: notes || `Delivery marketing ${id}`,
},
});
} catch (error) {
console.error('Error delivery marketing:', error);
return undefined;
}
}
}
export const SalesOrderApi = new SalesOrderService('/marketing/sales-orders');