shelflife-react-hooks 1.0.19 → 1.0.20
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 +22 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +22 -0
- package/dist/index.esm.js.map +1 -1
- package/package.json +36 -36
- package/src/context/AuthContext.tsx +161 -161
- package/src/context/InviteContext.tsx +74 -74
- package/src/context/ProductContext.tsx +131 -121
- package/src/context/RunningLowContext.tsx +100 -100
- package/src/context/ShoppingListContext.tsx +76 -76
- package/src/context/StorageContext.tsx +105 -105
- package/src/context/StorageItemContext.tsx +157 -157
- package/src/context/StorageMemberContext.tsx +84 -84
- package/src/context/UserContext.tsx +109 -109
- package/src/context/__tests__/contexts.test.tsx +370 -370
- package/src/context/api/authApi.ts +155 -155
- package/src/context/api/inviteApi.ts +65 -65
- package/src/context/api/productApi.ts +223 -201
- package/src/context/api/requestState.ts +24 -24
- package/src/context/api/runningLowApi.ts +141 -141
- package/src/context/api/shoppingListApi.ts +161 -161
- package/src/context/api/storageApi.ts +166 -166
- package/src/context/api/storageItemApi.ts +260 -260
- package/src/context/api/storageMemberApi.ts +84 -84
- package/src/context/api/userApi.ts +161 -161
- package/src/context/http.ts +22 -22
- package/src/index.ts +21 -21
- package/src/type/PaginatedResponse.ts +8 -8
- package/src/type/auth.ts +79 -79
- package/src/type/base.ts +21 -21
- package/src/type/item.ts +12 -12
- package/src/type/member.ts +6 -6
- package/src/type/models.ts +56 -56
- package/src/type/product.ts +11 -11
- package/src/type/requests.ts +60 -60
- package/src/type/runninglow.ts +13 -13
- package/src/type/shoppingList.ts +13 -13
- package/src/type/storage.ts +7 -7
- package/src/type/user.ts +11 -11
- package/tsconfig.json +46 -46
- package/tsup.config.ts +10 -10
- package/vitest.config.ts +8 -8
package/dist/index.d.cts
CHANGED
|
@@ -264,9 +264,11 @@ declare const useInvites: () => InviteContextValue;
|
|
|
264
264
|
type ProductContextValue = {
|
|
265
265
|
products: Product[];
|
|
266
266
|
product: Product | null;
|
|
267
|
+
categories: string[];
|
|
267
268
|
isLoading: boolean;
|
|
268
269
|
isError: boolean;
|
|
269
270
|
error: Error | null;
|
|
271
|
+
fetchCategories: () => Promise<string[] | null>;
|
|
270
272
|
fetchProducts: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Product>>;
|
|
271
273
|
fetchProduct: (id: number) => Promise<Product | null>;
|
|
272
274
|
createProduct: (dto: CreateProductRequest) => Promise<Product>;
|
package/dist/index.d.ts
CHANGED
|
@@ -264,9 +264,11 @@ declare const useInvites: () => InviteContextValue;
|
|
|
264
264
|
type ProductContextValue = {
|
|
265
265
|
products: Product[];
|
|
266
266
|
product: Product | null;
|
|
267
|
+
categories: string[];
|
|
267
268
|
isLoading: boolean;
|
|
268
269
|
isError: boolean;
|
|
269
270
|
error: Error | null;
|
|
271
|
+
fetchCategories: () => Promise<string[] | null>;
|
|
270
272
|
fetchProducts: (search?: string, size?: number, page?: number) => Promise<PaginatedResponse<Product>>;
|
|
271
273
|
fetchProduct: (id: number) => Promise<Product | null>;
|
|
272
274
|
createProduct: (dto: CreateProductRequest) => Promise<Product>;
|
package/dist/index.esm.js
CHANGED
|
@@ -506,6 +506,21 @@ var fetchProductRequest = async (config, id) => runWithRequestState(config, asyn
|
|
|
506
506
|
config.setProducts((previous) => updateById2(previous, payload));
|
|
507
507
|
return payload;
|
|
508
508
|
});
|
|
509
|
+
var fetchCategoriesRequest = async (config) => runWithRequestState(config, async () => {
|
|
510
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
511
|
+
const response = await fetch(`${normalizedBaseUrl}/api/products/categories`, {
|
|
512
|
+
headers: buildAuthHeaders(config.token)
|
|
513
|
+
});
|
|
514
|
+
if (!response.ok) {
|
|
515
|
+
throw new Error("Failed to fetch categories");
|
|
516
|
+
}
|
|
517
|
+
const payload = await readJson(response);
|
|
518
|
+
if (!payload) {
|
|
519
|
+
throw new Error("Category response missing data");
|
|
520
|
+
}
|
|
521
|
+
config.setCategories(payload);
|
|
522
|
+
return payload;
|
|
523
|
+
});
|
|
509
524
|
var createProductRequest = async (config, dto) => runWithRequestState(config, async () => {
|
|
510
525
|
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
511
526
|
const response = await fetch(`${normalizedBaseUrl}/api/products`, {
|
|
@@ -595,6 +610,7 @@ import { jsx as jsx3 } from "react/jsx-runtime";
|
|
|
595
610
|
var ProductContext = createContext3(void 0);
|
|
596
611
|
var ProductProvider = ({ baseUrl, children }) => {
|
|
597
612
|
const { token } = useAuth();
|
|
613
|
+
const [categories, setCategories] = useState3([]);
|
|
598
614
|
const [products, setProducts] = useState3([]);
|
|
599
615
|
const [product, setProduct] = useState3(null);
|
|
600
616
|
const [isLoading, setIsLoading] = useState3(false);
|
|
@@ -603,6 +619,7 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
603
619
|
const apiConfig = useMemo3(() => ({
|
|
604
620
|
baseUrl,
|
|
605
621
|
token,
|
|
622
|
+
setCategories,
|
|
606
623
|
setProducts,
|
|
607
624
|
setProduct,
|
|
608
625
|
setIsLoading,
|
|
@@ -613,6 +630,7 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
613
630
|
(search = "", size = 0, page = 0) => fetchProductsRequest(apiConfig, search, size, page),
|
|
614
631
|
[apiConfig]
|
|
615
632
|
);
|
|
633
|
+
const fetchCategories = useCallback3(() => fetchCategoriesRequest(apiConfig), [apiConfig]);
|
|
616
634
|
const fetchProduct = useCallback3((id) => fetchProductRequest(apiConfig, id), [apiConfig]);
|
|
617
635
|
const createProduct = useCallback3(
|
|
618
636
|
(dto) => createProductRequest(apiConfig, dto),
|
|
@@ -634,6 +652,8 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
634
652
|
isLoading,
|
|
635
653
|
isError,
|
|
636
654
|
error,
|
|
655
|
+
categories,
|
|
656
|
+
fetchCategories,
|
|
637
657
|
fetchProducts,
|
|
638
658
|
fetchProduct,
|
|
639
659
|
createProduct,
|
|
@@ -647,11 +667,13 @@ var ProductProvider = ({ baseUrl, children }) => {
|
|
|
647
667
|
error,
|
|
648
668
|
fetchProduct,
|
|
649
669
|
fetchProducts,
|
|
670
|
+
fetchCategories,
|
|
650
671
|
getProductIcon,
|
|
651
672
|
isError,
|
|
652
673
|
isLoading,
|
|
653
674
|
product,
|
|
654
675
|
products,
|
|
676
|
+
categories,
|
|
655
677
|
updateProduct,
|
|
656
678
|
uploadProductIcon
|
|
657
679
|
]);
|