shelflife-react-hooks 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.esm.js +5 -5
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/context/ProductContext.tsx +2 -7
- package/src/context/StorageContext.tsx +3 -2
- package/src/context/api/productApi.ts +5 -4
- package/src/context/api/storageApi.ts +5 -4
- package/src/index.ts +1 -0
- package/src/type/PaginatedResponse.ts +9 -0
- package/src/type/models.ts +1 -0
- package/src/type/product.ts +2 -1
|
@@ -18,12 +18,7 @@ import {
|
|
|
18
18
|
updateProductRequest,
|
|
19
19
|
uploadProductIconRequest
|
|
20
20
|
} from './api/productApi.js';
|
|
21
|
-
|
|
22
|
-
type ProductQuery = {
|
|
23
|
-
barcode?: string;
|
|
24
|
-
name?: string;
|
|
25
|
-
category?: string;
|
|
26
|
-
};
|
|
21
|
+
import type { PaginatedResponse } from '../type/PaginatedResponse.js';
|
|
27
22
|
|
|
28
23
|
type ProductContextValue = {
|
|
29
24
|
products: Product[];
|
|
@@ -31,7 +26,7 @@ type ProductContextValue = {
|
|
|
31
26
|
isLoading: boolean;
|
|
32
27
|
isError: boolean;
|
|
33
28
|
error: Error | null;
|
|
34
|
-
fetchProducts: (search
|
|
29
|
+
fetchProducts: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Product>>;
|
|
35
30
|
fetchProduct: (id: number) => Promise<Product | null>;
|
|
36
31
|
createProduct: (dto: CreateProductRequest) => Promise<Product>;
|
|
37
32
|
updateProduct: (id: number, dto: UpdateProductRequest) => Promise<Product>;
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
fetchStorageRequest,
|
|
17
17
|
fetchStoragesRequest
|
|
18
18
|
} from './api/storageApi.js';
|
|
19
|
+
import type { PaginatedResponse } from '../type/PaginatedResponse.js';
|
|
19
20
|
|
|
20
21
|
type StorageContextValue = {
|
|
21
22
|
storages: Storage[];
|
|
@@ -23,7 +24,7 @@ type StorageContextValue = {
|
|
|
23
24
|
isLoading: boolean;
|
|
24
25
|
isError: boolean;
|
|
25
26
|
error: Error | null;
|
|
26
|
-
fetchStorages: (search?: string, size?: number, page?: number) => Promise<Storage
|
|
27
|
+
fetchStorages: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Storage>>;
|
|
27
28
|
fetchStorage: (id: number) => Promise<Storage | null>;
|
|
28
29
|
createStorage: (dto: CreateStorageRequest) => Promise<Storage>;
|
|
29
30
|
changeStorageName: (id: number, dto: ChangeStorageNameRequest) => Promise<Storage>;
|
|
@@ -55,7 +56,7 @@ export const StorageProvider = ({ baseUrl, children }: StorageProviderProps) =>
|
|
|
55
56
|
setError
|
|
56
57
|
}), [baseUrl, token]);
|
|
57
58
|
|
|
58
|
-
const fetchStorages = useCallback((search: string = "", size: number = 0, page: number = 0) => fetchStoragesRequest(apiConfig, search,
|
|
59
|
+
const fetchStorages = useCallback((search: string = "", size: number = 0, page: number = 0) => fetchStoragesRequest(apiConfig, search, size, page), [apiConfig]);
|
|
59
60
|
const fetchStorage = useCallback((id: number) => fetchStorageRequest(apiConfig, id), [apiConfig]);
|
|
60
61
|
const createStorage = useCallback(
|
|
61
62
|
(dto: CreateStorageRequest) => createStorageRequest(apiConfig, dto),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Product } from '../../type/models.js';
|
|
2
|
+
import type { PaginatedResponse } from '../../type/PaginatedResponse.js';
|
|
2
3
|
import type { ProductCreateError } from '../../type/product.js';
|
|
3
4
|
import type { CreateProductRequest, UpdateProductRequest } from '../../type/requests.js';
|
|
4
5
|
import { buildAuthHeaders, normalizeBaseUrl, readArrayBuffer, readJson } from '../http.js';
|
|
@@ -27,7 +28,7 @@ export const fetchProductsRequest = async (
|
|
|
27
28
|
search: string,
|
|
28
29
|
size: number,
|
|
29
30
|
page: number
|
|
30
|
-
): Promise<Product
|
|
31
|
+
): Promise<PaginatedResponse<Product>> => runWithRequestState(config, async () => {
|
|
31
32
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
32
33
|
let url = `${normalizedBaseUrl}/api/products?search=${search}`;
|
|
33
34
|
if (size > 0)
|
|
@@ -41,13 +42,13 @@ export const fetchProductsRequest = async (
|
|
|
41
42
|
throw new Error('Failed to fetch products');
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
const payload = await readJson<Product
|
|
45
|
+
const payload = await readJson<PaginatedResponse<Product>>(response);
|
|
45
46
|
if (payload) {
|
|
46
|
-
config.setProducts(payload);
|
|
47
|
+
config.setProducts(payload.data);
|
|
47
48
|
return payload;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
return [];
|
|
51
|
+
return { data: [], currentPage: 0, hasNext: false, hasPrevious: false, pageSize: 0, totalItems: 0, totalPages: 0 };
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
export const fetchProductRequest = async (
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Storage } from '../../type/models.js';
|
|
2
|
+
import type { PaginatedResponse } from '../../type/PaginatedResponse.js';
|
|
2
3
|
import type { ChangeStorageNameRequest, CreateStorageRequest } from '../../type/requests.js';
|
|
3
4
|
import type { CreateStorageError } from '../../type/storage.js';
|
|
4
5
|
import { buildAuthHeaders, normalizeBaseUrl, readJson } from '../http.js';
|
|
@@ -27,7 +28,7 @@ export const fetchStoragesRequest = async (
|
|
|
27
28
|
search: string,
|
|
28
29
|
size: number,
|
|
29
30
|
page: number
|
|
30
|
-
): Promise<Storage
|
|
31
|
+
): Promise<PaginatedResponse<Storage>> => runWithRequestState(
|
|
31
32
|
config,
|
|
32
33
|
async () => {
|
|
33
34
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
@@ -43,13 +44,13 @@ export const fetchStoragesRequest = async (
|
|
|
43
44
|
throw new Error('Failed to fetch storages');
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
const payload = await readJson<Storage
|
|
47
|
+
const payload = await readJson<PaginatedResponse<Storage>>(response);
|
|
47
48
|
if (payload) {
|
|
48
|
-
config.setStorages(payload);
|
|
49
|
+
config.setStorages(payload.data);
|
|
49
50
|
return payload;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
return [];
|
|
53
|
+
return { data: [], currentPage: 0, hasNext: false, hasPrevious: false, pageSize: 0, totalItems: 0, totalPages: 0 };
|
|
53
54
|
}
|
|
54
55
|
);
|
|
55
56
|
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './type/base.js';
|
|
|
3
3
|
export * from './type/item.js';
|
|
4
4
|
export * from './type/member.js';
|
|
5
5
|
export * from './type/models.js';
|
|
6
|
+
export * from './type/PaginatedResponse.js';
|
|
6
7
|
export * from './type/product.js';
|
|
7
8
|
export * from './type/requests.js';
|
|
8
9
|
export * from './type/runninglow.js';
|
package/src/type/models.ts
CHANGED