@selfcommunity/react-core 0.6.7-payments.152 → 0.6.7-payments.156

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.
@@ -18,4 +18,5 @@ export default function useSCFetchCategory({ id, category, cacheStrategy, }: {
18
18
  scCategory: SCCategoryType;
19
19
  setSCCategory: import("react").Dispatch<import("react").SetStateAction<SCCategoryType>>;
20
20
  error: string;
21
+ refreshCategory: () => void;
21
22
  };
@@ -42,6 +42,23 @@ function useSCFetchCategory({ id = null, category = null, cacheStrategy = utils_
42
42
  return Promise.resolve(res.data);
43
43
  });
44
44
  }, [__categoryId]);
45
+ /**
46
+ * Refresh category
47
+ */
48
+ const refreshCategory = (0, react_1.useMemo)(() => () => {
49
+ fetchCategory()
50
+ .then((obj) => {
51
+ const _c = authUserId ? obj : (0, utils_1.objectWithoutProperties)(obj, ['followed']);
52
+ setSCCategory(_c);
53
+ utils_1.LRUCache.set(__categoryCacheKey, _c);
54
+ })
55
+ .catch((err) => {
56
+ utils_1.LRUCache.delete(__categoryCacheKey);
57
+ setError(`Error on refresh category with id ${id}`);
58
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, `Error on refresh category with id ${id}`);
59
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
60
+ });
61
+ }, [__categoryId, setSCCategory, __categoryCacheKey]);
45
62
  /**
46
63
  * If id attempt to get the category by id
47
64
  */
@@ -68,6 +85,6 @@ function useSCFetchCategory({ id = null, category = null, cacheStrategy = utils_
68
85
  utils_1.LRUCache.set(__categoryCacheKey, _c);
69
86
  }
70
87
  }, [category]);
71
- return { scCategory, setSCCategory, error };
88
+ return { scCategory, setSCCategory, error, refreshCategory };
72
89
  }
73
90
  exports.default = useSCFetchCategory;
@@ -20,4 +20,5 @@ export default function useSCFetchCourse({ id, course, cacheStrategy, params, }:
20
20
  scCourse: SCCourseType;
21
21
  setSCCourse: (c: SCCourseType) => void;
22
22
  error: string;
23
+ refreshCourse: () => void;
23
24
  };
@@ -48,6 +48,21 @@ function useSCFetchCourse({ id = null, course = null, cacheStrategy = utils_1.Ca
48
48
  return Promise.resolve(res.data);
49
49
  });
50
50
  }, []);
51
+ /**
52
+ * Refresh course
53
+ */
54
+ const refreshCourse = (0, react_1.useMemo)(() => () => {
55
+ fetchCourse(id)
56
+ .then((e) => {
57
+ setSCCourse(e);
58
+ })
59
+ .catch((err) => {
60
+ utils_1.LRUCache.delete(__courseCacheKey);
61
+ setError(`Error on refresh course with id ${id}`);
62
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, `Error on refresh course with id ${id}`);
63
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
64
+ });
65
+ }, [id, __courseCacheKey, setSCCourse]);
51
66
  /**
52
67
  * If id attempt to get the course by id
53
68
  */
@@ -76,6 +91,6 @@ function useSCFetchCourse({ id = null, course = null, cacheStrategy = utils_1.Ca
76
91
  setSCCourse(course);
77
92
  }
78
93
  }, [course, authUserId]);
79
- return { scCourse, setSCCourse, error };
94
+ return { scCourse, setSCCourse, error, refreshCourse };
80
95
  }
81
96
  exports.default = useSCFetchCourse;
@@ -19,4 +19,5 @@ export default function useSCFetchEvent({ id, event, autoSubscribe, cacheStrateg
19
19
  scEvent: SCEventType;
20
20
  setSCEvent: (e: SCEventType) => void;
21
21
  error: string;
22
+ refreshEvent: () => () => void;
22
23
  };
@@ -68,6 +68,21 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
68
68
  return Promise.resolve(res.data);
69
69
  });
70
70
  }, []);
71
+ /**
72
+ * Refresh event
73
+ */
74
+ const refreshEvent = (0, react_1.useMemo)(() => () => () => {
75
+ fetchEvent(id)
76
+ .then((e) => {
77
+ setSCEvent(e);
78
+ })
79
+ .catch((err) => {
80
+ utils_1.LRUCache.delete(__eventCacheKey);
81
+ setError(`Error on refresh event with id ${id}`);
82
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, `Error on refresh event with id ${id}`);
83
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
84
+ });
85
+ }, [id, setSCEvent, __eventCacheKey]);
71
86
  /**
72
87
  * If id attempt to get the event by id
73
88
  */
@@ -90,6 +105,6 @@ function useSCFetchEvent({ id = null, event = null, autoSubscribe = true, cacheS
90
105
  setSCEvent(event);
91
106
  }
92
107
  }, [event, authUserId]);
93
- return { scEvent, setSCEvent, error };
108
+ return { scEvent, setSCEvent, error, refreshEvent };
94
109
  }
95
110
  exports.default = useSCFetchEvent;
@@ -17,4 +17,5 @@ export default function useSCFetchGroup({ id, group, cacheStrategy, }: {
17
17
  scGroup: SCGroupType;
18
18
  setSCGroup: (group: SCGroupType) => void;
19
19
  error: string;
20
+ refreshGroup: () => void;
20
21
  };
@@ -47,6 +47,21 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
47
47
  return Promise.resolve(res.data);
48
48
  });
49
49
  }, [__groupId]);
50
+ /**
51
+ * Refresh group
52
+ */
53
+ const refreshGroup = (0, react_1.useMemo)(() => () => {
54
+ fetchGroup()
55
+ .then((obj) => {
56
+ setSCGroup(obj);
57
+ })
58
+ .catch((err) => {
59
+ utils_1.LRUCache.delete(__groupCacheKey);
60
+ setError(`Error on refresh group with id ${id}`);
61
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, `Error on refresh group with id ${id}`);
62
+ utils_1.Logger.error(Errors_1.SCOPE_SC_CORE, err.message);
63
+ });
64
+ }, [__groupCacheKey, setSCGroup]);
50
65
  /**
51
66
  * If id attempt to get the group by id
52
67
  */
@@ -69,6 +84,6 @@ function useSCFetchGroup({ id = null, group = null, cacheStrategy = utils_1.Cach
69
84
  setSCGroup(group);
70
85
  }
71
86
  }, [group, authUserId]);
72
- return { scGroup, setSCGroup, error };
87
+ return { scGroup, setSCGroup, error, refreshGroup };
73
88
  }
74
89
  exports.default = useSCFetchGroup;
@@ -93,8 +93,8 @@ function useSCJoinedCoursesManager(user) {
93
93
  // Only if user is authenticated
94
94
  api_services_1.http
95
95
  .request({
96
- url: api_services_1.Endpoints.GetJoinedCourses.url(),
97
- method: api_services_1.Endpoints.GetJoinedCourses.method,
96
+ url: api_services_1.Endpoints.GetUserJoinedCourses.url({ id: user.id }),
97
+ method: api_services_1.Endpoints.GetUserJoinedCourses.method,
98
98
  })
99
99
  .then((res) => {
100
100
  if (res.status >= 300) {
@@ -93,8 +93,8 @@ function useSCSubscribedEventsManager(user) {
93
93
  // Only if user is authenticated
94
94
  api_services_1.http
95
95
  .request({
96
- url: api_services_1.Endpoints.GetUserEvents.url(),
97
- method: api_services_1.Endpoints.GetUserEvents.method,
96
+ url: api_services_1.Endpoints.GetUserSubscribedEvents.url({ id: user.id }),
97
+ method: api_services_1.Endpoints.GetUserSubscribedEvents.method,
98
98
  })
99
99
  .then((res) => {
100
100
  if (res.status >= 300) {
@@ -93,8 +93,8 @@ function useSCSubscribedGroupsManager(user) {
93
93
  // Only if user is authenticated
94
94
  api_services_1.http
95
95
  .request({
96
- url: api_services_1.Endpoints.GetUserGroups.url(),
97
- method: api_services_1.Endpoints.GetUserGroups.method,
96
+ url: api_services_1.Endpoints.GetUserSubscribedGroups.url({ id: user.id }),
97
+ method: api_services_1.Endpoints.GetUserSubscribedGroups.method,
98
98
  })
99
99
  .then((res) => {
100
100
  if (res.status >= 300) {
@@ -18,4 +18,5 @@ export default function useSCFetchCategory({ id, category, cacheStrategy, }: {
18
18
  scCategory: SCCategoryType;
19
19
  setSCCategory: import("react").Dispatch<import("react").SetStateAction<SCCategoryType>>;
20
20
  error: string;
21
+ refreshCategory: () => void;
21
22
  };
@@ -40,6 +40,23 @@ export default function useSCFetchCategory({ id = null, category = null, cacheSt
40
40
  return Promise.resolve(res.data);
41
41
  });
42
42
  }, [__categoryId]);
43
+ /**
44
+ * Refresh category
45
+ */
46
+ const refreshCategory = useMemo(() => () => {
47
+ fetchCategory()
48
+ .then((obj) => {
49
+ const _c = authUserId ? obj : objectWithoutProperties(obj, ['followed']);
50
+ setSCCategory(_c);
51
+ LRUCache.set(__categoryCacheKey, _c);
52
+ })
53
+ .catch((err) => {
54
+ LRUCache.delete(__categoryCacheKey);
55
+ setError(`Error on refresh category with id ${id}`);
56
+ Logger.error(SCOPE_SC_CORE, `Error on refresh category with id ${id}`);
57
+ Logger.error(SCOPE_SC_CORE, err.message);
58
+ });
59
+ }, [__categoryId, setSCCategory, __categoryCacheKey]);
43
60
  /**
44
61
  * If id attempt to get the category by id
45
62
  */
@@ -66,5 +83,5 @@ export default function useSCFetchCategory({ id = null, category = null, cacheSt
66
83
  LRUCache.set(__categoryCacheKey, _c);
67
84
  }
68
85
  }, [category]);
69
- return { scCategory, setSCCategory, error };
86
+ return { scCategory, setSCCategory, error, refreshCategory };
70
87
  }
@@ -20,4 +20,5 @@ export default function useSCFetchCourse({ id, course, cacheStrategy, params, }:
20
20
  scCourse: SCCourseType;
21
21
  setSCCourse: (c: SCCourseType) => void;
22
22
  error: string;
23
+ refreshCourse: () => void;
23
24
  };
@@ -46,6 +46,21 @@ export default function useSCFetchCourse({ id = null, course = null, cacheStrate
46
46
  return Promise.resolve(res.data);
47
47
  });
48
48
  }, []);
49
+ /**
50
+ * Refresh course
51
+ */
52
+ const refreshCourse = useMemo(() => () => {
53
+ fetchCourse(id)
54
+ .then((e) => {
55
+ setSCCourse(e);
56
+ })
57
+ .catch((err) => {
58
+ LRUCache.delete(__courseCacheKey);
59
+ setError(`Error on refresh course with id ${id}`);
60
+ Logger.error(SCOPE_SC_CORE, `Error on refresh course with id ${id}`);
61
+ Logger.error(SCOPE_SC_CORE, err.message);
62
+ });
63
+ }, [id, __courseCacheKey, setSCCourse]);
49
64
  /**
50
65
  * If id attempt to get the course by id
51
66
  */
@@ -74,5 +89,5 @@ export default function useSCFetchCourse({ id = null, course = null, cacheStrate
74
89
  setSCCourse(course);
75
90
  }
76
91
  }, [course, authUserId]);
77
- return { scCourse, setSCCourse, error };
92
+ return { scCourse, setSCCourse, error, refreshCourse };
78
93
  }
@@ -19,4 +19,5 @@ export default function useSCFetchEvent({ id, event, autoSubscribe, cacheStrateg
19
19
  scEvent: SCEventType;
20
20
  setSCEvent: (e: SCEventType) => void;
21
21
  error: string;
22
+ refreshEvent: () => () => void;
22
23
  };
@@ -66,6 +66,21 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
66
66
  return Promise.resolve(res.data);
67
67
  });
68
68
  }, []);
69
+ /**
70
+ * Refresh event
71
+ */
72
+ const refreshEvent = useMemo(() => () => () => {
73
+ fetchEvent(id)
74
+ .then((e) => {
75
+ setSCEvent(e);
76
+ })
77
+ .catch((err) => {
78
+ LRUCache.delete(__eventCacheKey);
79
+ setError(`Error on refresh event with id ${id}`);
80
+ Logger.error(SCOPE_SC_CORE, `Error on refresh event with id ${id}`);
81
+ Logger.error(SCOPE_SC_CORE, err.message);
82
+ });
83
+ }, [id, setSCEvent, __eventCacheKey]);
69
84
  /**
70
85
  * If id attempt to get the event by id
71
86
  */
@@ -88,5 +103,5 @@ export default function useSCFetchEvent({ id = null, event = null, autoSubscribe
88
103
  setSCEvent(event);
89
104
  }
90
105
  }, [event, authUserId]);
91
- return { scEvent, setSCEvent, error };
106
+ return { scEvent, setSCEvent, error, refreshEvent };
92
107
  }
@@ -17,4 +17,5 @@ export default function useSCFetchGroup({ id, group, cacheStrategy, }: {
17
17
  scGroup: SCGroupType;
18
18
  setSCGroup: (group: SCGroupType) => void;
19
19
  error: string;
20
+ refreshGroup: () => void;
20
21
  };
@@ -45,6 +45,21 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
45
45
  return Promise.resolve(res.data);
46
46
  });
47
47
  }, [__groupId]);
48
+ /**
49
+ * Refresh group
50
+ */
51
+ const refreshGroup = useMemo(() => () => {
52
+ fetchGroup()
53
+ .then((obj) => {
54
+ setSCGroup(obj);
55
+ })
56
+ .catch((err) => {
57
+ LRUCache.delete(__groupCacheKey);
58
+ setError(`Error on refresh group with id ${id}`);
59
+ Logger.error(SCOPE_SC_CORE, `Error on refresh group with id ${id}`);
60
+ Logger.error(SCOPE_SC_CORE, err.message);
61
+ });
62
+ }, [__groupCacheKey, setSCGroup]);
48
63
  /**
49
64
  * If id attempt to get the group by id
50
65
  */
@@ -67,5 +82,5 @@ export default function useSCFetchGroup({ id = null, group = null, cacheStrategy
67
82
  setSCGroup(group);
68
83
  }
69
84
  }, [group, authUserId]);
70
- return { scGroup, setSCGroup, error };
85
+ return { scGroup, setSCGroup, error, refreshGroup };
71
86
  }
@@ -90,8 +90,8 @@ export default function useSCJoinedCoursesManager(user) {
90
90
  // Only if user is authenticated
91
91
  http
92
92
  .request({
93
- url: Endpoints.GetJoinedCourses.url(),
94
- method: Endpoints.GetJoinedCourses.method,
93
+ url: Endpoints.GetUserJoinedCourses.url({ id: user.id }),
94
+ method: Endpoints.GetUserJoinedCourses.method,
95
95
  })
96
96
  .then((res) => {
97
97
  if (res.status >= 300) {
@@ -90,8 +90,8 @@ export default function useSCSubscribedEventsManager(user) {
90
90
  // Only if user is authenticated
91
91
  http
92
92
  .request({
93
- url: Endpoints.GetUserEvents.url(),
94
- method: Endpoints.GetUserEvents.method,
93
+ url: Endpoints.GetUserSubscribedEvents.url({ id: user.id }),
94
+ method: Endpoints.GetUserSubscribedEvents.method,
95
95
  })
96
96
  .then((res) => {
97
97
  if (res.status >= 300) {
@@ -90,8 +90,8 @@ export default function useSCSubscribedGroupsManager(user) {
90
90
  // Only if user is authenticated
91
91
  http
92
92
  .request({
93
- url: Endpoints.GetUserGroups.url(),
94
- method: Endpoints.GetUserGroups.method,
93
+ url: Endpoints.GetUserSubscribedGroups.url({ id: user.id }),
94
+ method: Endpoints.GetUserSubscribedGroups.method,
95
95
  })
96
96
  .then((res) => {
97
97
  if (res.status >= 300) {