ready to test

Testing

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-06-22 10:07:20 +08:00
parent 56d984a26a
commit fbef7cb6e6
283 changed files with 25961 additions and 1072 deletions
+75
View File
@@ -0,0 +1,75 @@
/***********************************************************************************************************************************************************************
* File Name : GroupContext.jsx
* Type : Context / Provider
* Description : Client group context.
* Covers: fetching the current user's groups and a single group detail.
* Used by: GroupList.jsx
***********************************************************************************************************************************************************************/
import { createContext, useCallback, useContext, useState } from 'react';
import api from '@/utils/api.util';
import { toast } from 'sonner';
const BASE = '/client/groups';
const GroupContext = createContext(null);
export function useGroup() {
const ctx = useContext(GroupContext);
if (!ctx) throw new Error('useGroup must be used within a GroupProvider');
return ctx;
}
export function GroupProvider({ children }) {
const [groups, setGroups] = useState([]);
const [group, setGroup] = useState(null);
const [loading, setLoading] = useState(false);
const request = useCallback(async (fn) => {
setLoading(true);
try {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? 'Something went wrong.';
toast.error(message);
return null;
} finally {
setLoading(false);
}
}, []);
// ─── GET MY GROUPS ────────────────────────────────────────────────────────
// GET /client/groups
const fetchGroups = useCallback(
() =>
request(async () => {
const res = await api.get(BASE);
const data = res.data?.data ?? [];
setGroups(data);
return data;
}),
[request]
);
// ─── GET ONE GROUP ────────────────────────────────────────────────────────
// GET /client/groups/:groupId
const fetchGroup = useCallback(
(groupId) =>
request(async () => {
const res = await api.get(`${BASE}/${groupId}`);
const data = res.data?.data ?? null;
setGroup(data);
return data;
}),
[request]
);
return (
<GroupContext.Provider value={{
groups, group,
loading,
fetchGroups, fetchGroup,
}}>
{children}
</GroupContext.Provider>
);
}