mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
refactor(FE-212): rename PurchaseApi to PurchaseRequisitionsApi and update related references in forms and tables
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import useSWR from 'swr';
|
||||
import PurchaseRequisitionsForm from '@/components/pages/purchase/form/request/PurchaseRequisitionsForm';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
import { PurchaseRequisitionsApi } from '@/services/api/purchase';
|
||||
import { isResponseSuccess, isResponseError } from '@/lib/api-helper';
|
||||
|
||||
const PurchaseEdit = () => {
|
||||
@@ -14,7 +14,7 @@ const PurchaseEdit = () => {
|
||||
|
||||
const { data: purchase, isLoading: isLoadingPurchase } = useSWR(
|
||||
purchaseId,
|
||||
(id: number) => PurchaseApi.getSingle(id)
|
||||
(id: number) => PurchaseRequisitionsApi.getSingle(id)
|
||||
);
|
||||
|
||||
if (!purchaseId) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import useSWR from 'swr';
|
||||
import PurchaseRequisitionsForm from '@/components/pages/purchase/form/request/PurchaseRequisitionsForm';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
import { PurchaseRequisitionsApi } from '@/services/api/purchase';
|
||||
import { isResponseSuccess, isResponseError } from '@/lib/api-helper';
|
||||
|
||||
const PurchaseDetail = () => {
|
||||
@@ -14,7 +14,7 @@ const PurchaseDetail = () => {
|
||||
|
||||
const { data: purchase, isLoading: isLoadingPurchase } = useSWR(
|
||||
purchaseId,
|
||||
(id: number) => PurchaseApi.getSingle(id)
|
||||
(id: number) => PurchaseRequisitionsApi.getSingle(id)
|
||||
);
|
||||
|
||||
if (!purchaseId) {
|
||||
|
||||
@@ -25,7 +25,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 { PurchaseApi } from '@/services/api/purchase';
|
||||
import { PurchaseRequisitionsApi } from '@/services/api/purchase';
|
||||
|
||||
const RowOptionsMenu = ({
|
||||
type = 'dropdown',
|
||||
@@ -102,8 +102,8 @@ const PurchaseTable = () => {
|
||||
isLoading,
|
||||
mutate: refreshPurchaseRequests,
|
||||
} = useSWR(
|
||||
`${PurchaseApi.basePath}${getTableFilterQueryString()}`,
|
||||
PurchaseApi.getAllFetcher
|
||||
`${PurchaseRequisitionsApi.basePath}${getTableFilterQueryString()}`,
|
||||
PurchaseRequisitionsApi.getAllFetcher
|
||||
);
|
||||
|
||||
// Modal hooks
|
||||
@@ -236,7 +236,7 @@ const PurchaseTable = () => {
|
||||
setIsDeleteLoading(true);
|
||||
|
||||
try {
|
||||
await PurchaseApi.delete(selectedPurchase?.id as number);
|
||||
await PurchaseRequisitionsApi.delete(selectedPurchase?.id as number);
|
||||
refreshPurchaseRequests();
|
||||
deleteModal.closeModal();
|
||||
toast.success('Berhasil menghapus data permintaan pembelian!');
|
||||
|
||||
@@ -33,7 +33,7 @@ import { Supplier } from '@/types/api/master-data/supplier';
|
||||
import { Product } from '@/types/api/master-data/product';
|
||||
import { ProductWarehouseApi } from '@/services/api/inventory';
|
||||
import { isResponseSuccess, isResponseError } from '@/lib/api-helper';
|
||||
import { PurchaseApi } from '@/services/api/purchase';
|
||||
import { PurchaseRequisitionsApi } from '@/services/api/purchase';
|
||||
|
||||
import Card from '@/components/Card';
|
||||
import {
|
||||
@@ -105,7 +105,7 @@ const PurchaseRequisitionsForm = ({
|
||||
// ===== SUBMISSION HANDLERS =====
|
||||
const createPurchaseRequestHandler = useCallback(
|
||||
async (payload: CreatePurchaseRequisitionsPayload) => {
|
||||
const res = await PurchaseApi.create(payload);
|
||||
const res = await PurchaseRequisitionsApi.create(payload);
|
||||
if (isResponseError(res)) {
|
||||
setPurchaseRequestFormErrorMessage(res.message);
|
||||
return;
|
||||
@@ -121,7 +121,10 @@ const PurchaseRequisitionsForm = ({
|
||||
purchaseRequestId: number,
|
||||
payload: CreatePurchaseRequisitionsPayload
|
||||
) => {
|
||||
const res = await PurchaseApi.update(purchaseRequestId, payload);
|
||||
const res = await PurchaseRequisitionsApi.update(
|
||||
purchaseRequestId,
|
||||
payload
|
||||
);
|
||||
if (isResponseError(res)) {
|
||||
setPurchaseRequestFormErrorMessage(res.message);
|
||||
return;
|
||||
@@ -141,7 +144,7 @@ const PurchaseRequisitionsForm = ({
|
||||
if (!initialValues?.id) return;
|
||||
|
||||
setIsDeleteLoading(true);
|
||||
await PurchaseApi.delete(initialValues.id);
|
||||
await PurchaseRequisitionsApi.delete(initialValues.id);
|
||||
deleteModal.closeModal();
|
||||
toast.success('Successfully delete Purchase Request!');
|
||||
setIsDeleteLoading(false);
|
||||
@@ -582,8 +585,8 @@ const PurchaseRequisitionsForm = ({
|
||||
!formik.values.area_id
|
||||
? 'Pilih Area terlebih dahulu'
|
||||
: formik.values.location_id
|
||||
? 'Pilih Gudang...'
|
||||
: 'Pilih Area dan Lokasi terlebih dahulu'
|
||||
? 'Pilih Gudang...'
|
||||
: 'Pilih Area dan Lokasi terlebih dahulu'
|
||||
}
|
||||
value={formik.values.warehouse}
|
||||
onChange={(val) => {
|
||||
|
||||
@@ -5,8 +5,12 @@ import {
|
||||
} from '@/types/api/purchase/purchase';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
|
||||
export const PurchaseApi = new BaseApiService<
|
||||
export const PurchaseRequisitionsApi = new BaseApiService<
|
||||
Purchase,
|
||||
CreatePurchaseRequisitionsPayload,
|
||||
UpdatePurchaseRequisitionsPayload
|
||||
>('/purchases/requisitions');
|
||||
|
||||
export const PurchaseOrderApi = new BaseApiService<Purchase, unknown, unknown>(
|
||||
'/purchases/orders'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user