mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
ready to test
Testing Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -25,10 +25,15 @@ export const UserProvider = ({ children }) => {
|
||||
const [users, setUsers] = useState([]);
|
||||
const [user, setUser] = useState(null);
|
||||
const [sessions, setSessions] = useState([]);
|
||||
const [achievements, setAchievements] = useState([]);
|
||||
const [achievementsLoading, setAchievementsLoading] = useState(false);
|
||||
const [pagination, setPagination] = useState(PAGINATION_INIT);
|
||||
const [attributes, setAttributes] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
const [activity, setActivity] = useState([]);
|
||||
const [activityPagination, setActivityPagination] = useState(PAGINATION_INIT);
|
||||
const [activityLoading, setActivityLoading] = useState(false);
|
||||
|
||||
const request = useCallback(async (fn) => {
|
||||
setLoading(true);
|
||||
@@ -212,6 +217,53 @@ export const UserProvider = ({ children }) => {
|
||||
[request]
|
||||
);
|
||||
|
||||
// ─── GET /api/admin/activity ──────────────────────────────────────────────
|
||||
const fetchActivity = useCallback(
|
||||
({ page = 1, limit = 20, action = undefined, from = undefined, to = undefined } = {}) =>
|
||||
request(async () => {
|
||||
const res = await api.get(`${BASE}/activity`, { params: { page, limit, action, from, to } });
|
||||
const d = res.data?.data;
|
||||
setActivity(d?.activities ?? []);
|
||||
setActivityPagination({
|
||||
page: d?.page ?? 1,
|
||||
limit,
|
||||
totalRecords: d?.total ?? 0,
|
||||
totalPages: d?.totalPages ?? 0,
|
||||
hasPrevPage: (d?.page ?? 1) > 1,
|
||||
hasNextPage: (d?.page ?? 1) < (d?.totalPages ?? 0),
|
||||
});
|
||||
return d;
|
||||
}),
|
||||
[request]
|
||||
);
|
||||
|
||||
// ─── GET /api/admin/users/:id/activity ────────────────────────────────────
|
||||
const fetchUserActivity = useCallback(
|
||||
async (userId, { page = 1, limit = 20, action = undefined } = {}) => {
|
||||
setActivityLoading(true);
|
||||
try {
|
||||
const res = await api.get(`${BASE}/users/${userId}/activity`, { params: { page, limit, action } });
|
||||
const d = res.data?.data;
|
||||
setActivity(d?.activities ?? []);
|
||||
setActivityPagination({
|
||||
page: d?.page ?? 1,
|
||||
limit,
|
||||
totalRecords: d?.total ?? 0,
|
||||
totalPages: d?.totalPages ?? 0,
|
||||
hasPrevPage: (d?.page ?? 1) > 1,
|
||||
hasNextPage: (d?.page ?? 1) < (d?.totalPages ?? 0),
|
||||
});
|
||||
return d;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load activity.");
|
||||
return null;
|
||||
} finally {
|
||||
setActivityLoading(false);
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
// ─── GET /api/admin/users/field-values ────────────────────────────────────
|
||||
const fetchUserFieldValues = useCallback(
|
||||
(field) =>
|
||||
@@ -222,9 +274,25 @@ export const UserProvider = ({ children }) => {
|
||||
[request]
|
||||
);
|
||||
|
||||
// ─── GET /api/admin/users/:id/achievements ────────────────────────────────
|
||||
const fetchUserAchievements = useCallback(async (userId) => {
|
||||
setAchievementsLoading(true);
|
||||
try {
|
||||
const res = await api.get(`${BASE}/users/${userId}/achievements`);
|
||||
setAchievements(res.data?.data ?? []);
|
||||
return res.data?.data;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load achievements.");
|
||||
return [];
|
||||
} finally {
|
||||
setAchievementsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<UserContext.Provider value={{
|
||||
users, user, sessions, pagination, attributes, loading, error,
|
||||
users, user, sessions, achievements, achievementsLoading, pagination, attributes, loading, error,
|
||||
activity, activityPagination, activityLoading,
|
||||
setPagination,
|
||||
fetchUsers, fetchArchivedUsers, fetchUser,
|
||||
addStaffUser, updateUser,
|
||||
@@ -232,6 +300,8 @@ export const UserProvider = ({ children }) => {
|
||||
restoreUser, restoreUsers,
|
||||
fetchUserSessions, terminateSession,
|
||||
fetchUserFieldValues,
|
||||
fetchUserAchievements,
|
||||
fetchActivity, fetchUserActivity,
|
||||
}}>
|
||||
{children}
|
||||
</UserContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user