mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
fix(FE): adding capacity to kandang and change confirmation modal marketing with note
This commit is contained in:
@@ -50,6 +50,7 @@ const ConfirmationModalWithNotes: React.FC<ConfirmationModalWithNotesProps> = ({
|
|||||||
...primaryButton,
|
...primaryButton,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
primaryButton?.onClick?.(notes);
|
primaryButton?.onClick?.(notes);
|
||||||
|
setNotes('');
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
secondaryButton={secondaryButton}
|
secondaryButton={secondaryButton}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import CheckboxInput from '@/components/input/CheckboxInput';
|
|||||||
import { OptionType } from '@/components/input/SelectInput';
|
import { OptionType } from '@/components/input/SelectInput';
|
||||||
import Modal, { useModal } from '@/components/Modal';
|
import Modal, { useModal } from '@/components/Modal';
|
||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
|
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
||||||
import Table from '@/components/Table';
|
import Table from '@/components/Table';
|
||||||
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
import RowCollapseOptions from '@/components/table/RowCollapseOptions';
|
||||||
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
import RowDropdownOptions from '@/components/table/RowDropdownOptions';
|
||||||
@@ -170,7 +171,7 @@ const SalesOrderTable = () => {
|
|||||||
.filter((row) => row.latest_approval.step_number === 2)
|
.filter((row) => row.latest_approval.step_number === 2)
|
||||||
.map((row) => row.id);
|
.map((row) => row.id);
|
||||||
|
|
||||||
const approveMarketingHandler = async () => {
|
const approveMarketingHandler = async (notes: string) => {
|
||||||
let idsToProcess: number[] = [];
|
let idsToProcess: number[] = [];
|
||||||
|
|
||||||
if (approveAction === 'APPROVED') {
|
if (approveAction === 'APPROVED') {
|
||||||
@@ -191,7 +192,8 @@ const SalesOrderTable = () => {
|
|||||||
|
|
||||||
const approveMarketingRes = await SalesOrderApi.bulkApprovals(
|
const approveMarketingRes = await SalesOrderApi.bulkApprovals(
|
||||||
idsToProcess,
|
idsToProcess,
|
||||||
approveAction
|
approveAction,
|
||||||
|
notes
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isResponseSuccess(approveMarketingRes)) {
|
if (isResponseSuccess(approveMarketingRes)) {
|
||||||
@@ -450,10 +452,10 @@ const SalesOrderTable = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ConfirmationModal
|
<ConfirmationModalWithNotes
|
||||||
ref={confirmationModal.ref}
|
ref={confirmationModal.ref}
|
||||||
type={approveAction === 'APPROVED' ? 'success' : 'error'}
|
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={{
|
secondaryButton={{
|
||||||
text: 'Tidak',
|
text: 'Tidak',
|
||||||
onClick: confirmationModal.closeModal,
|
onClick: confirmationModal.closeModal,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import Card from '@/components/Card';
|
|||||||
import { FormHeader } from '@/components/helper/form/FormHeader';
|
import { FormHeader } from '@/components/helper/form/FormHeader';
|
||||||
import { useModal } from '@/components/Modal';
|
import { useModal } from '@/components/Modal';
|
||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
|
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
||||||
import ApprovalSteps, {
|
import ApprovalSteps, {
|
||||||
useApprovalSteps,
|
useApprovalSteps,
|
||||||
} from '@/components/pages/ApprovalSteps';
|
} from '@/components/pages/ApprovalSteps';
|
||||||
@@ -78,11 +79,12 @@ const SalesOrderDetail = ({
|
|||||||
refresh?.();
|
refresh?.();
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmationModalApproveClickHandler = async () => {
|
const confirmationModalApproveClickHandler = async (notes: string) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const res = await SalesOrderApi.singleApproval(
|
const res = await SalesOrderApi.singleApproval(
|
||||||
initialValues?.id as number,
|
initialValues?.id as number,
|
||||||
approvalAction
|
approvalAction,
|
||||||
|
notes
|
||||||
);
|
);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
confirmationModal.closeModal();
|
confirmationModal.closeModal();
|
||||||
@@ -91,13 +93,17 @@ const SalesOrderDetail = ({
|
|||||||
refreshApproval?.();
|
refreshApproval?.();
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmationModalDeliveryClickHandler = async () => {
|
const confirmationModalDeliveryClickHandler = async (notes: string) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
// await MarketingApi.delivery(initialValues?.id as number);
|
const res = await SalesOrderApi.delivery(
|
||||||
|
initialValues?.id as number,
|
||||||
|
notes
|
||||||
|
);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
deliveryModal.closeModal();
|
deliveryModal.closeModal();
|
||||||
toast.success('Successfully delivered Sales Order!');
|
toast.success(res?.message as string);
|
||||||
refresh?.();
|
refresh?.();
|
||||||
|
refreshApproval?.();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -285,7 +291,7 @@ const SalesOrderDetail = ({
|
|||||||
onClick: confirmationModalDeleteClickHandler,
|
onClick: confirmationModalDeleteClickHandler,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ConfirmationModal
|
<ConfirmationModalWithNotes
|
||||||
ref={confirmationModal.ref}
|
ref={confirmationModal.ref}
|
||||||
type={approvalAction === 'APPROVED' ? 'success' : 'error'}
|
type={approvalAction === 'APPROVED' ? 'success' : 'error'}
|
||||||
text={`Apakah anda yakin ingin ${approvalAction} data penjualan ini?`}
|
text={`Apakah anda yakin ingin ${approvalAction} data penjualan ini?`}
|
||||||
@@ -299,7 +305,7 @@ const SalesOrderDetail = ({
|
|||||||
onClick: confirmationModalApproveClickHandler,
|
onClick: confirmationModalApproveClickHandler,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ConfirmationModal
|
<ConfirmationModalWithNotes
|
||||||
ref={deliveryModal.ref}
|
ref={deliveryModal.ref}
|
||||||
type={'success'}
|
type={'success'}
|
||||||
text={`Apakah anda yakin ingin deliver penjualan ini?`}
|
text={`Apakah anda yakin ingin deliver penjualan ini?`}
|
||||||
|
|||||||
@@ -303,9 +303,9 @@ const SalesForm = ({
|
|||||||
wrapper: 'bg-white w-full',
|
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-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
|
<SalesOrderProductTable
|
||||||
data={memoSalesOrder}
|
data={memoSalesOrder}
|
||||||
rowSelection={rowSelection}
|
rowSelection={rowSelection}
|
||||||
|
|||||||
@@ -1,6 +1,28 @@
|
|||||||
import * as Yup from 'yup';
|
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!'),
|
name: Yup.string().required('Nama wajib diisi!'),
|
||||||
|
|
||||||
locationId: Yup.number()
|
locationId: Yup.number()
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ const KandangForm = ({ type = 'add', initialValues }: KandangFormProps) => {
|
|||||||
label: initialValues.location.name,
|
label: initialValues.location.name,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
capacity: initialValues?.capacity ?? 0,
|
capacity: initialValues?.capacity,
|
||||||
picId: initialValues?.pic?.id ?? 0,
|
picId: initialValues?.pic?.id ?? 0,
|
||||||
pic: initialValues?.pic
|
pic: initialValues?.pic
|
||||||
? {
|
? {
|
||||||
@@ -102,9 +102,9 @@ const KandangForm = ({ type = 'add', initialValues }: KandangFormProps) => {
|
|||||||
|
|
||||||
const kandangPayload: CreateKandangPayload = {
|
const kandangPayload: CreateKandangPayload = {
|
||||||
name: values.name,
|
name: values.name,
|
||||||
location_id: values.locationId,
|
location_id: values.locationId!,
|
||||||
capacity: values.capacity,
|
capacity: values.capacity ? parseInt(values.capacity.toString()) : 0,
|
||||||
pic_id: values.picId,
|
pic_id: values.picId!,
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -256,7 +256,8 @@ const KandangForm = ({ type = 'add', initialValues }: KandangFormProps) => {
|
|||||||
required
|
required
|
||||||
name='capacity'
|
name='capacity'
|
||||||
label='Kapasitas'
|
label='Kapasitas'
|
||||||
value={formik.values.capacity ?? undefined}
|
placeholder='Masukan kapasitas kandang'
|
||||||
|
value={formik.values.capacity}
|
||||||
onChange={formik.handleChange}
|
onChange={formik.handleChange}
|
||||||
onBlur={formik.handleBlur}
|
onBlur={formik.handleBlur}
|
||||||
isError={
|
isError={
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ export class SalesOrderService extends BaseApiService<
|
|||||||
*/
|
*/
|
||||||
async singleApproval(
|
async singleApproval(
|
||||||
id: number,
|
id: number,
|
||||||
action: 'APPROVED' | 'REJECTED'
|
action: 'APPROVED' | 'REJECTED',
|
||||||
|
notes?: string
|
||||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||||
try {
|
try {
|
||||||
const path = `${this.basePath}/approvals`;
|
const path = `${this.basePath}/approvals`;
|
||||||
@@ -78,7 +79,7 @@ export class SalesOrderService extends BaseApiService<
|
|||||||
body: {
|
body: {
|
||||||
action: action,
|
action: action,
|
||||||
approvable_ids: [id],
|
approvable_ids: [id],
|
||||||
notes: `${action} marketing ${id}`,
|
notes: notes || `${action} marketing ${id}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -92,7 +93,8 @@ export class SalesOrderService extends BaseApiService<
|
|||||||
*/
|
*/
|
||||||
async bulkApprovals(
|
async bulkApprovals(
|
||||||
ids: number[],
|
ids: number[],
|
||||||
action: 'APPROVED' | 'REJECTED'
|
action: 'APPROVED' | 'REJECTED',
|
||||||
|
notes?: string
|
||||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||||
try {
|
try {
|
||||||
const path = `${this.basePath}/approvals`;
|
const path = `${this.basePath}/approvals`;
|
||||||
@@ -101,7 +103,7 @@ export class SalesOrderService extends BaseApiService<
|
|||||||
body: {
|
body: {
|
||||||
action: action,
|
action: action,
|
||||||
approvable_ids: ids,
|
approvable_ids: ids,
|
||||||
notes: `${action} marketing ${ids.join(', ')}`,
|
notes: notes || `${action} marketing ${ids.join(', ')}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -109,6 +111,29 @@ export class SalesOrderService extends BaseApiService<
|
|||||||
return undefined;
|
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');
|
export const SalesOrderApi = new SalesOrderService('/marketing/sales-orders');
|
||||||
|
|||||||
Reference in New Issue
Block a user