mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-212): add DeletePurchaseRequestItemPayload and implement PurchaseDeleteItemsService
This commit is contained in:
@@ -102,17 +102,17 @@ const PurchaseOrderAcceptApprovalForm = ({
|
||||
// ===== SUBMISSION HANDLERS =====
|
||||
const createAcceptApprovalHandler = useCallback(
|
||||
async (payload: CreateAcceptApprovalRequestPayload) => {
|
||||
const purchaseRequisitionId = searchParams.get('purchaseId')
|
||||
const purchaseRequestId = searchParams.get('purchaseId')
|
||||
? parseInt(searchParams.get('purchaseId')!)
|
||||
: initialValues?.id || 1;
|
||||
|
||||
if (!purchaseRequisitionId) {
|
||||
setPurchaseOrderFormErrorMessage('Purchase Requisition ID is required');
|
||||
if (!purchaseRequestId) {
|
||||
setPurchaseOrderFormErrorMessage('Purchase Request ID is required');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await AcceptApprovalApi.acceptApproval(
|
||||
purchaseRequisitionId,
|
||||
purchaseRequestId,
|
||||
payload
|
||||
);
|
||||
|
||||
|
||||
@@ -81,6 +81,10 @@ export type PurchaseAcceptApprovalItemSchema = {
|
||||
transport_total: number | string;
|
||||
};
|
||||
|
||||
export type PurchaseDeleteItemsSchema = {
|
||||
item_ids: number[];
|
||||
};
|
||||
|
||||
const PurchaseStaffApprovalItemObjectSchema: Yup.ObjectSchema<PurchaseStaffApprovalItemSchema> =
|
||||
Yup.object({
|
||||
purchase_item: Yup.object({
|
||||
@@ -249,6 +253,20 @@ export const PurchaseRequestStaffApprovalFormSchema: Yup.ObjectSchema<PurchaseRe
|
||||
.typeError('Item pembelian wajib diisi!'),
|
||||
});
|
||||
|
||||
export const PurchaseDeleteItemsSchema: Yup.ObjectSchema<PurchaseDeleteItemsSchema> =
|
||||
Yup.object({
|
||||
item_ids: Yup.array()
|
||||
.of(
|
||||
Yup.number()
|
||||
.min(1, 'Item ID tidak valid!')
|
||||
.required('Item ID tidak valid!')
|
||||
.typeError('Item ID tidak valid!')
|
||||
)
|
||||
.min(1, 'Minimal harus ada 1 item yang dihapus!')
|
||||
.required('Item yang dihapus wajib diisi!')
|
||||
.typeError('Item yang dihapus wajib diisi!'),
|
||||
});
|
||||
|
||||
export const PurchaseRequestStaffApprovalFormInitialValues: PurchaseRequestStaffApprovalFormSchemaType =
|
||||
{
|
||||
notes: '',
|
||||
@@ -368,3 +386,11 @@ export const PurchaseRequestAcceptApprovalFormDefaultValues = (
|
||||
export type PurchaseRequestAcceptApprovalFormValues = Yup.InferType<
|
||||
typeof PurchaseRequestAcceptApprovalFormSchema
|
||||
>;
|
||||
|
||||
export const PurchaseDeleteItemsInitialValues: PurchaseDeleteItemsSchema = {
|
||||
item_ids: [],
|
||||
};
|
||||
|
||||
export type PurchaseDeleteItemsFormValues = Yup.InferType<
|
||||
typeof PurchaseDeleteItemsSchema
|
||||
>;
|
||||
|
||||
@@ -79,17 +79,17 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
// ===== SUBMISSION HANDLERS =====
|
||||
const createStaffApprovalHandler = useCallback(
|
||||
async (payload: CreateStaffApprovalRequestPayload) => {
|
||||
const purchaseRequisitionId = searchParams.get('purchaseId')
|
||||
const purchaseRequestId = searchParams.get('purchaseId')
|
||||
? parseInt(searchParams.get('purchaseId')!)
|
||||
: initialValues?.id || 1;
|
||||
|
||||
if (!purchaseRequisitionId) {
|
||||
setPurchaseOrderFormErrorMessage('Purchase Requisition ID is required');
|
||||
if (!purchaseRequestId) {
|
||||
setPurchaseOrderFormErrorMessage('Purchase Request ID is required');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await StaffApprovalApi.createStaffApproval(
|
||||
purchaseRequisitionId,
|
||||
purchaseRequestId,
|
||||
payload
|
||||
);
|
||||
|
||||
|
||||
@@ -318,17 +318,17 @@ const PurchaseOrderDetail = ({
|
||||
// ===== SUBMISSION HANDLER =====
|
||||
const createManagerApprovalHandler = useCallback(
|
||||
async (payload: CreateManagerApprovalRequestPayload) => {
|
||||
const purchaseRequisitionId = searchParams.get('purchaseId')
|
||||
const purchaseRequestId = searchParams.get('purchaseId')
|
||||
? parseInt(searchParams.get('purchaseId')!)
|
||||
: purchaseData?.id || 1;
|
||||
|
||||
if (!purchaseRequisitionId) {
|
||||
toast.error('Purchase Requisition ID is required');
|
||||
if (!purchaseRequestId) {
|
||||
toast.error('Purchase Request ID is required');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await ManagerApprovalApi.createManagerApproval(
|
||||
purchaseRequisitionId,
|
||||
purchaseRequestId,
|
||||
payload
|
||||
);
|
||||
|
||||
@@ -377,6 +377,10 @@ const PurchaseOrderDetail = ({
|
||||
};
|
||||
|
||||
const purchaseOrderColumns: ColumnDef<PurchaseItem>[] = [
|
||||
{
|
||||
header: 'No',
|
||||
cell: (props) => props.row.index + 1,
|
||||
},
|
||||
{
|
||||
accessorKey: 'product.name',
|
||||
header: 'Produk',
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
CreateStaffApprovalRequestPayload,
|
||||
CreateManagerApprovalRequestPayload,
|
||||
CreateAcceptApprovalRequestPayload,
|
||||
DeletePurchaseRequestItemPayload,
|
||||
} from '@/types/api/purchase/purchase';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
@@ -18,18 +19,18 @@ export const PurchaseRequestApi = new BaseApiService<
|
||||
export class StaffApprovalService extends BaseApiService<
|
||||
Purchase,
|
||||
CreateStaffApprovalRequestPayload,
|
||||
CreateAcceptApprovalRequestPayload
|
||||
unknown
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
|
||||
async createStaffApproval(
|
||||
purchaseRequisitionId: number,
|
||||
purchaseRequestId: number,
|
||||
payload: CreateStaffApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequisitionId}/approvals/staff`,
|
||||
`${purchaseRequestId}/approvals/staff`,
|
||||
{
|
||||
method: 'POST',
|
||||
payload,
|
||||
@@ -48,11 +49,11 @@ export class ManagerApprovalService extends BaseApiService<
|
||||
}
|
||||
|
||||
async createManagerApproval(
|
||||
purchaseRequisitionId: number,
|
||||
purchaseRequestId: number,
|
||||
payload: CreateManagerApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequisitionId}/approvals/manager`,
|
||||
`${purchaseRequestId}/approvals/manager`,
|
||||
{
|
||||
method: 'POST',
|
||||
payload,
|
||||
@@ -64,18 +65,41 @@ export class ManagerApprovalService extends BaseApiService<
|
||||
export class AcceptApprovalService extends BaseApiService<
|
||||
Purchase,
|
||||
CreateAcceptApprovalRequestPayload,
|
||||
CreateAcceptApprovalRequestPayload
|
||||
unknown
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
|
||||
async acceptApproval(
|
||||
purchaseRequisitionId: number,
|
||||
purchaseRequestId: number,
|
||||
payload: CreateAcceptApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequisitionId}/approvals/receipts`,
|
||||
`${purchaseRequestId}/approvals/receipts`,
|
||||
{
|
||||
method: 'POST',
|
||||
payload,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class PurchaseDeleteItemsService extends BaseApiService<
|
||||
Purchase,
|
||||
DeletePurchaseRequestItemPayload,
|
||||
unknown
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
|
||||
async deleteItems(
|
||||
purchaseRequestId: number,
|
||||
payload: DeletePurchaseRequestItemPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequestId}/items`,
|
||||
{
|
||||
method: 'POST',
|
||||
payload,
|
||||
@@ -89,3 +113,7 @@ export const StaffApprovalApi = new StaffApprovalService('/purchases');
|
||||
export const ManagerApprovalApi = new ManagerApprovalService('/purchases');
|
||||
|
||||
export const AcceptApprovalApi = new AcceptApprovalService('/purchases');
|
||||
|
||||
export const PurchaseDeleteItemsApi = new PurchaseDeleteItemsService(
|
||||
'/purchases'
|
||||
);
|
||||
|
||||
Vendored
+4
@@ -87,4 +87,8 @@ export type CreateAcceptApprovalRequestPayload = {
|
||||
}[];
|
||||
};
|
||||
|
||||
export type DeletePurchaseRequestItemPayload = {
|
||||
item_ids: number[];
|
||||
};
|
||||
|
||||
export type UpdatePurchaseRequestPayload = CreatePurchaseRequestPayload;
|
||||
|
||||
Reference in New Issue
Block a user