mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-22 22:35:45 +00:00
refactor(FE-212,213): unify purchase API service references in Purchase components
This commit is contained in:
@@ -22,7 +22,7 @@ import { isResponseSuccess } from '@/lib/api-helper';
|
||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||
import { ROWS_OPTIONS } from '@/config/constant';
|
||||
import { Purchase } from '@/types/api/purchase/purchase';
|
||||
import { PurchaseRequestApi } from '@/services/api/purchase';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
|
||||
// ===== INTERFACES =====
|
||||
interface RowOptionsMenuProps {
|
||||
@@ -110,8 +110,8 @@ const PurchaseTable = () => {
|
||||
isLoading,
|
||||
mutate: refreshPurchaseRequests,
|
||||
} = useSWR(
|
||||
`${PurchaseRequestApi.basePath}${getTableFilterQueryString()}`,
|
||||
PurchaseRequestApi.getAllFetcher
|
||||
`${PurchaseApi.basePath}${getTableFilterQueryString()}`,
|
||||
PurchaseApi.getAllFetcher
|
||||
);
|
||||
|
||||
// ===== TABLE COLUMNS DEFINITION =====
|
||||
@@ -208,7 +208,7 @@ const PurchaseTable = () => {
|
||||
setIsDeleteLoading(true);
|
||||
|
||||
try {
|
||||
await PurchaseRequestApi.delete(selectedPurchase?.id as number);
|
||||
await PurchaseApi.delete(selectedPurchase?.id as number);
|
||||
refreshPurchaseRequests();
|
||||
deleteModal.closeModal();
|
||||
toast.success('Berhasil menghapus data permintaan pembelian!');
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
PurchaseRequestAcceptApprovalFormSchema,
|
||||
} from './PurchaseOrderForm.schema';
|
||||
import { isResponseError } from '@/lib/api-helper';
|
||||
import { AcceptApprovalApi } from '@/services/api/purchase';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
import {
|
||||
CreateAcceptApprovalRequestPayload,
|
||||
Purchase,
|
||||
@@ -93,7 +93,7 @@ const PurchaseOrderAcceptApprovalForm = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await AcceptApprovalApi.acceptApproval(
|
||||
const res = await PurchaseApi.acceptApproval.create(
|
||||
purchaseRequestId,
|
||||
payload
|
||||
);
|
||||
@@ -113,7 +113,7 @@ const PurchaseOrderAcceptApprovalForm = ({
|
||||
|
||||
const updateAcceptApprovalHandler = useCallback(
|
||||
async (purchaseId: number, payload: CreateAcceptApprovalRequestPayload) => {
|
||||
const res = await AcceptApprovalApi.acceptApproval(purchaseId, payload);
|
||||
const res = await PurchaseApi.acceptApproval.create(purchaseId, payload);
|
||||
if (isResponseError(res)) {
|
||||
setPurchaseOrderFormErrorMessage(res.message);
|
||||
return;
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
PurchaseRequestStaffApprovalFormSchema,
|
||||
} from './PurchaseOrderForm.schema';
|
||||
import { isResponseError } from '@/lib/api-helper';
|
||||
import { StaffApprovalApi } from '@/services/api/purchase';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
import {
|
||||
CreateStaffApprovalRequestPayload,
|
||||
UpdateStaffApprovalRequestPayload,
|
||||
@@ -84,7 +84,7 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await StaffApprovalApi.createStaffApproval(
|
||||
const res = await PurchaseApi.staffApproval.create(
|
||||
purchaseRequestId,
|
||||
payload
|
||||
);
|
||||
@@ -104,7 +104,7 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
|
||||
const updateStaffApprovalHandler = useCallback(
|
||||
async (purchaseId: number, payload: UpdateStaffApprovalRequestPayload) => {
|
||||
const res = await StaffApprovalApi.updateStaffApproval(
|
||||
const res = await PurchaseApi.staffApproval.update(
|
||||
purchaseId,
|
||||
payload
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
import { Supplier } from '@/types/api/master-data/supplier';
|
||||
import { Product } from '@/types/api/master-data/product';
|
||||
import { isResponseSuccess, isResponseError } from '@/lib/api-helper';
|
||||
import { PurchaseRequestApi } from '@/services/api/purchase';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
|
||||
import Card from '@/components/Card';
|
||||
import {
|
||||
@@ -99,7 +99,7 @@ const PurchaseRequestForm = ({
|
||||
// ===== SUBMISSION HANDLERS =====
|
||||
const createPurchaseRequestHandler = useCallback(
|
||||
async (payload: CreatePurchaseRequestPayload) => {
|
||||
const res = await PurchaseRequestApi.create(payload);
|
||||
const res = await PurchaseApi.create(payload);
|
||||
if (isResponseError(res)) {
|
||||
setPurchaseRequestFormErrorMessage(res.message);
|
||||
return;
|
||||
@@ -115,7 +115,7 @@ const PurchaseRequestForm = ({
|
||||
purchaseRequestId: number,
|
||||
payload: CreatePurchaseRequestPayload
|
||||
) => {
|
||||
const res = await PurchaseRequestApi.update(purchaseRequestId, payload);
|
||||
const res = await PurchaseApi.update(purchaseRequestId, payload);
|
||||
if (isResponseError(res)) {
|
||||
setPurchaseRequestFormErrorMessage(res.message);
|
||||
return;
|
||||
@@ -135,7 +135,7 @@ const PurchaseRequestForm = ({
|
||||
if (!initialValues?.id) return;
|
||||
|
||||
setIsDeleteLoading(true);
|
||||
await PurchaseRequestApi.delete(initialValues.id);
|
||||
await PurchaseApi.delete(initialValues.id);
|
||||
deleteModal.closeModal();
|
||||
toast.success('Successfully delete Purchase Request!');
|
||||
setIsDeleteLoading(false);
|
||||
|
||||
@@ -26,10 +26,7 @@ import {
|
||||
Purchase,
|
||||
PurchaseItem,
|
||||
} from '@/types/api/purchase/purchase';
|
||||
import {
|
||||
ManagerApprovalApi,
|
||||
PurchaseDeleteItemsApi,
|
||||
} from '@/services/api/purchase';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
import { isResponseError } from '@/lib/api-helper';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
@@ -230,7 +227,7 @@ const PurchaseOrderDetail = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await ManagerApprovalApi.createManagerApproval(
|
||||
const res = await PurchaseApi.managerApproval.create(
|
||||
purchaseRequestId,
|
||||
payload
|
||||
);
|
||||
@@ -276,7 +273,7 @@ const PurchaseOrderDetail = ({
|
||||
setIsDeleteLoading(true);
|
||||
|
||||
try {
|
||||
const res = await PurchaseDeleteItemsApi.deleteItems(purchaseRequestId, {
|
||||
const res = await PurchaseApi.items.delete(purchaseRequestId, {
|
||||
item_ids: itemIdsToDelete,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user