@asaleh37/ui-base 25.11.6 → 25.12.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asaleh37/ui-base",
3
- "version": "25.11.6",
3
+ "version": "25.12.10",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Ahmed Saleh Mohamed",
@@ -1,4 +1,4 @@
1
- import { useRef } from 'react';
1
+ import { useRef } from "react";
2
2
  import { useTranslation } from "react-i18next";
3
3
  import { useForm } from "react-hook-form";
4
4
  import { useParams } from "react-router-dom";
@@ -13,9 +13,10 @@ export { useIsMobile } from "./UseMobile";
13
13
  export { default as useSession } from "./UseSession";
14
14
  export { useWindow } from "./UseWindow";
15
15
  export { default as useApiActions } from "./useApiActions";
16
+ export { default as useCommonStore } from "./useCommonStore";
16
17
  export { useDispatch };
17
18
  export { useSelector };
18
19
  export { useParams };
19
20
  export { useForm, zodResolver, z };
20
21
  export { useTranslation };
21
- export {useNavigate};
22
+ export { useNavigate };
@@ -0,0 +1,29 @@
1
+ import { useDispatch, useSelector } from "react-redux";
2
+ import { StoreMetaData } from "../types";
3
+ import useAxios from "./useAxios";
4
+ import { setStoreData } from "../redux/features/common/CommonStoreSlice";
5
+
6
+ const useCommonStore = (storeKey: string) => {
7
+ const dispatch = useDispatch();
8
+ const { handleGetRequest } = useAxios();
9
+ const store: StoreMetaData = useSelector(
10
+ (state: any) => state?.commonStores?.stores[storeKey]
11
+ );
12
+ const reload = async () => {
13
+ if (store && store?.url) {
14
+ await handleGetRequest({
15
+ endPointURI: store.url,
16
+ showMask: true,
17
+ successCallBkFn: (response: any) => {
18
+ dispatch(setStoreData({ storeKey, data: response.data }));
19
+ },
20
+ failureCallBkFn: () => {
21
+ dispatch(setStoreData({ storeKey, data: [] }));
22
+ },
23
+ });
24
+ }
25
+ };
26
+ return { reload, data: store?.data, store };
27
+ };
28
+
29
+ export default useCommonStore;