testing 127.0.0.1 issue

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-07 13:40:07 +08:00
parent 244aa607f7
commit 6624c0d27f
62 changed files with 662 additions and 1889 deletions
+4 -24
View File
@@ -19,12 +19,7 @@ export function AdminAchievementsProvider({ children }) {
setLoading(true);
try { return await fn(); }
catch (err) {
toast(err?.response?.data?.message ?? "Something went wrong.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Something went wrong.");
return null;
} finally { setLoading(false); }
}, []);
@@ -46,12 +41,7 @@ export function AdminAchievementsProvider({ children }) {
const createAchievement = useCallback((payload) =>
request(async () => {
const { data } = await api.post("/admin/achievements", payload);
toast("Achievement created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Achievement created.");
return data.data;
}), [request]);
@@ -62,12 +52,7 @@ export function AdminAchievementsProvider({ children }) {
prev.map((a) => (String(a.achievement_definition_id) === String(id) ? data.data : a))
);
if (achievement && String(achievement.achievement_definition_id) === String(id)) setAchievement(data.data);
toast("Achievement updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Achievement updated.");
return data.data;
}), [request, achievement]);
@@ -75,12 +60,7 @@ export function AdminAchievementsProvider({ children }) {
request(async () => {
await api.delete(`/admin/achievements/${id}`);
setAchievements((prev) => prev.filter((a) => String(a.achievement_definition_id) !== String(id)));
toast("Achievement deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Achievement deleted.");
return true;
}), [request]);
+9 -54
View File
@@ -34,12 +34,7 @@ export function AdvertisementsProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? "Something went wrong.";
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -105,12 +100,7 @@ export function AdvertisementsProvider({ children }) {
const advertisement = res.data?.data?.data ?? null;
if (advertisement) {
setAdvertisements((prev) => [advertisement, ...prev]);
toast("Advertisement created successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Advertisement created successfully.");
}
return res.data;
}),
@@ -126,12 +116,7 @@ export function AdvertisementsProvider({ children }) {
if (advertisement) {
setAdvertisements((prev) => prev.map((a) => (a.advertisement_id === advertisementId ? advertisement : a)));
setSelectedAdvertisement(advertisement);
toast("Advertisement updated successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Advertisement updated successfully.");
}
return res.data;
}),
@@ -147,12 +132,7 @@ export function AdvertisementsProvider({ children }) {
});
setAdvertisements((prev) => prev.filter((a) => a.advertisement_id !== advertisementId));
setSelectedAdvertisement((prev) => (prev?.advertisement_id === advertisementId ? null : prev));
toast("Advertisement archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Advertisement archived.");
return res.data;
}),
[request]
@@ -166,12 +146,7 @@ export function AdvertisementsProvider({ children }) {
data: { ids, deletedBy },
});
setAdvertisements((prev) => prev.filter((a) => !ids.includes(a.advertisement_id)));
toast(`${ids.length} advertisement(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} advertisement(s) archived.`);
return res.data;
}),
[request]
@@ -185,12 +160,7 @@ export function AdvertisementsProvider({ children }) {
const advertisement = res.data?.data?.data ?? null;
if (advertisement) {
setAdvertisements((prev) => prev.filter((a) => a.advertisement_id !== advertisementId));
toast("Advertisement restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Advertisement restored.");
}
return res.data;
}),
@@ -203,12 +173,7 @@ export function AdvertisementsProvider({ children }) {
request(async () => {
const res = await api.patch("/admin/advertisements/bulk-restore", { ids });
setAdvertisements((prev) => prev.filter((a) => !ids.includes(a.advertisement_id)));
toast(`${ids.length} advertisement(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} advertisement(s) restored.`);
return res.data;
}),
[request]
@@ -220,12 +185,7 @@ export function AdvertisementsProvider({ children }) {
request(async () => {
const res = await api.delete(`/admin/advertisements/${advertisementId}/permanent`);
setAdvertisements((prev) => prev.filter((a) => a.advertisement_id !== advertisementId));
toast("Advertisement permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Advertisement permanently deleted.");
return res.data;
}),
[request]
@@ -237,12 +197,7 @@ export function AdvertisementsProvider({ children }) {
request(async () => {
const res = await api.delete("/admin/advertisements/bulk/permanent", { data: { ids } });
setAdvertisements((prev) => prev.filter((a) => !ids.includes(a.advertisement_id)));
toast(`${ids.length} advertisement(s) permanently deleted.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} advertisement(s) permanently deleted.`);
return res.data;
}),
[request]
+9 -54
View File
@@ -69,12 +69,7 @@ export function AssetsProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? "Something went wrong.";
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -206,12 +201,7 @@ export function AssetsProvider({ children }) {
if (asset) {
setAssets((prev) => [asset, ...prev]);
invalidateListCache();
toast("Asset uploaded successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Asset uploaded successfully.");
}
return res.data;
}),
@@ -237,12 +227,7 @@ export function AssetsProvider({ children }) {
setAssets((prev) => prev.map((a) => (a.asset_id === assetId ? asset : a)));
setSelectedAsset(asset);
invalidateListCache();
toast("Asset updated successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Asset updated successfully.");
}
return res.data;
}),
@@ -259,12 +244,7 @@ export function AssetsProvider({ children }) {
setAssets((prev) => prev.filter((a) => a.asset_id !== assetId));
setSelectedAsset((prev) => (prev?.asset_id === assetId ? null : prev));
invalidateListCache();
toast("Asset archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Asset archived.");
return res.data;
}),
[request]
@@ -279,12 +259,7 @@ export function AssetsProvider({ children }) {
});
setAssets((prev) => prev.filter((a) => !ids.includes(a.asset_id)));
invalidateListCache();
toast(`${ids.length} asset(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} asset(s) archived.`);
return res.data;
}),
[request]
@@ -299,12 +274,7 @@ export function AssetsProvider({ children }) {
if (asset) {
setAssets((prev) => prev.filter((a) => a.asset_id !== assetId));
invalidateListCache();
toast("Asset restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Asset restored.");
}
return res.data;
}),
@@ -318,12 +288,7 @@ export function AssetsProvider({ children }) {
const res = await api.patch("/admin/assets/bulk-restore", { ids });
setAssets((prev) => prev.filter((a) => !ids.includes(a.asset_id)));
invalidateListCache();
toast(`${ids.length} asset(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} asset(s) restored.`);
return res.data;
}),
[request]
@@ -337,12 +302,7 @@ export function AssetsProvider({ children }) {
setAssets((prev) => prev.filter((a) => a.asset_id !== assetId));
setSelectedAsset((prev) => (prev?.asset_id === assetId ? null : prev));
invalidateListCache();
toast("Asset permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Asset permanently deleted.");
return res.data;
}),
[request]
@@ -357,12 +317,7 @@ export function AssetsProvider({ children }) {
});
setAssets((prev) => prev.filter((a) => !ids.includes(a.asset_id)));
invalidateListCache();
toast(`${ids.length} asset(s) permanently deleted.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} asset(s) permanently deleted.`);
return res.data;
}),
[request]
+5 -30
View File
@@ -13,12 +13,7 @@ export function AdminCategoriesProvider({ children }) {
setLoading(true);
try { return await fn(); }
catch (err) {
toast(err?.response?.data?.message ?? "Something went wrong.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Something went wrong.");
return null;
} finally { setLoading(false); }
}, []);
@@ -37,48 +32,28 @@ export function AdminCategoriesProvider({ children }) {
const createCategory = useCallback((payload) => wrap(async () => {
const { data } = await api.post("/admin/categories", payload);
toast("Category created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Category created.");
return data.data;
}), [wrap]);
const updateCategory = useCallback((id, payload) => wrap(async () => {
const { data } = await api.put(`/admin/categories/${id}`, payload);
setCategory(data.data ?? null);
toast("Category updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Category updated.");
return data.data;
}), [wrap]);
const archiveCategory = useCallback((id) => wrap(async () => {
await api.delete(`/admin/categories/${id}`);
setCategories((prev) => prev.filter((c) => c.id !== id));
toast("Category archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Category archived.");
return true;
}), [wrap]);
const restoreCategory = useCallback((id) => wrap(async () => {
await api.post(`/admin/categories/${id}/restore`);
setCategories((prev) => prev.filter((c) => c.id !== id));
toast("Category restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Category restored.");
return true;
}), [wrap]);
@@ -43,12 +43,7 @@ export function AdminCourseReadingProgressProvider({ children }) {
setProgressList(data.data ?? []);
setDetailCache({});
} catch (err) {
toast(err?.response?.data?.message ?? 'Could not load reading progress.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? 'Could not load reading progress.');
} finally {
setListLoading(false);
}
@@ -65,12 +60,7 @@ export function AdminCourseReadingProgressProvider({ children }) {
setDetailCache((prev) => ({ ...prev, [userId]: breakdown }));
return breakdown;
} catch (err) {
toast(err?.response?.data?.message ?? 'Could not load user progress.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? 'Could not load user progress.');
return null;
} finally {
setDetailLoading(false);
+55 -330
View File
@@ -52,18 +52,8 @@ export function CoursesProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? "Something went wrong.";
if (err.status === 404 && message) toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
else toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
if (err.status === 404 && message) toast(message);
else toast(message);
return null;
} finally {
setLoading(false);
@@ -121,12 +111,7 @@ export function CoursesProvider({ children }) {
const course = data?.data?.data ?? null;
if (course) {
setCourses((prev) => [course, ...prev]);
toast("Course created successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Course created successfully.");
}
return data;
}),
@@ -141,12 +126,7 @@ export function CoursesProvider({ children }) {
if (course) {
setCourses((prev) => prev.map((c) => (c.course_id === courseId ? course : c)));
setCourse(course);
toast("Course updated successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Course updated successfully.");
}
return data;
}),
@@ -159,12 +139,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}`);
setCourses((prev) => prev.filter((c) => c.course_id !== courseId));
setCourse((prev) => (prev?.course_id === courseId ? null : prev));
toast("Course archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Course archived.");
return data;
}),
[request],
@@ -175,12 +150,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/bulk`, { data: { ids } });
setCourses((prev) => prev.filter((c) => !ids.includes(c.course_id)));
toast("Courses archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Courses archived.");
return data;
}),
[request],
@@ -211,12 +181,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setCourses((prev) => prev.filter((c) => c.course_id !== courseId));
toast("Course restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Course restored.");
}
return data;
}),
@@ -228,12 +193,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.patch(`${BASE}/restore/bulk`, { ids });
setCourses((prev) => prev.filter((c) => !ids.includes(c.course_id)));
toast("Courses restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Courses restored.");
return data;
}),
[request],
@@ -245,12 +205,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}/permanent`);
setCourses((prev) => prev.filter((c) => c.course_id !== courseId));
setCourse((prev) => (prev?.course_id === courseId ? null : prev));
toast("Course permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Course permanently deleted.");
return data;
}),
[request],
@@ -261,12 +216,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/bulk/permanent`, { data: { ids } });
setCourses((prev) => prev.filter((c) => !ids.includes(c.course_id)));
toast("Courses permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Courses permanently deleted.");
return data;
}),
[request],
@@ -305,12 +255,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.put(`${BASE}/${courseId}/prerequisites`, { prerequisites });
setPrerequisites(prerequisites);
toast("Prerequisites updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Prerequisites updated.");
return data;
}),
[request],
@@ -360,12 +305,7 @@ export function CoursesProvider({ children }) {
const unit = data?.data?.data ?? null;
if (unit) {
setUnits((prev) => [...prev, unit]);
toast("Unit created successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Unit created successfully.");
}
return data;
}),
@@ -380,12 +320,7 @@ export function CoursesProvider({ children }) {
if (unit) {
setUnits((prev) => prev.map((u) => (u.unit_id === unitId ? unit : u)));
setUnit(unit);
toast("Unit updated successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Unit updated successfully.");
}
return data;
}),
@@ -398,12 +333,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}`);
setUnits((prev) => prev.filter((u) => u.unit_id !== unitId));
setUnit((prev) => (prev?.unit_id === unitId ? null : prev));
toast("Unit archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Unit archived.");
return data;
}),
[request],
@@ -414,12 +344,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/units/bulk`, { data: { ids } });
setUnits((prev) => prev.filter((u) => !ids.includes(u.unit_id)));
toast("Units archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Units archived.");
return data;
}),
[request],
@@ -451,12 +376,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setUnits((prev) => prev.filter((u) => u.unit_id !== unitId));
toast("Unit restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Unit restored.");
}
return data;
}),
@@ -468,12 +388,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.patch(`${BASE}/${courseId}/units/restore/bulk`, { ids } );
setUnits((prev) => prev.filter((u) => !ids.includes(u.unit_id)));
toast("Units restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Units restored.");
return data;
}),
[request],
@@ -485,12 +400,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/permanent`);
setUnits((prev) => prev.filter((u) => u.unit_id !== unitId));
setUnit((prev) => (prev?.unit_id === unitId ? null : prev));
toast("Unit permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Unit permanently deleted.");
return data;
}),
[request],
@@ -501,12 +411,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/units/bulk/permanent`, { data: { ids } });
setUnits((prev) => prev.filter((u) => !ids.includes(u.unit_id)));
toast("Units permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Units permanently deleted.");
return data;
}),
[request],
@@ -545,12 +450,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setQuiz(result);
toast("Quiz created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Quiz created.");
}
return data;
}),
@@ -564,12 +464,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setQuiz(result);
toast("Quiz updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Quiz updated.");
}
return data;
}),
@@ -582,12 +477,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/quiz/${quizId}`, { data: { deletedBy } });
setQuiz(null);
setQuestions([]);
toast("Quiz archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Quiz archived.");
return data;
}),
[request],
@@ -613,12 +503,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setQuiz(result);
toast("Quiz restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Quiz restored.");
}
return data;
}),
@@ -647,12 +532,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setQuestions((prev) => [...prev, result]);
toast("Question added.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question added.");
}
return data;
}),
@@ -666,12 +546,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setQuestions((prev) => prev.map((q) => (q.question_id === questionId ? result : q)));
toast("Question updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question updated.");
}
return data;
}),
@@ -684,12 +559,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.put(`${BASE}/${courseId}/units/${unitId}/quiz/${quizId}/questions/bulk-sync`, { questions, updatedBy });
const result = data?.data?.data ?? [];
setQuestions(result);
toast("Quiz saved.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Quiz saved.");
return data;
}),
[request],
@@ -700,12 +570,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/quiz/${quizId}/questions/${questionId}`, { data: { deletedBy } });
setQuestions((prev) => prev.filter((q) => q.question_id !== questionId));
toast("Question archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question archived.");
return data;
}),
[request],
@@ -716,12 +581,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/quiz/${quizId}/questions/bulk`, { data: { ids, deletedBy } });
setQuestions((prev) => prev.filter((q) => !ids.includes(q.question_id)));
toast("Questions archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Questions archived.");
return data;
}),
[request],
@@ -742,12 +602,7 @@ export function CoursesProvider({ children }) {
(courseId, unitId, quizId, questionId, restoredBy) =>
request(async () => {
const { data } = await api.patch(`${BASE}/${courseId}/units/${unitId}/quiz/${quizId}/questions/${questionId}/restore`, { restoredBy });
toast("Question restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question restored.");
return data;
}),
[request],
@@ -757,12 +612,7 @@ export function CoursesProvider({ children }) {
(courseId, unitId, quizId, ids, restoredBy) =>
request(async () => {
const { data } = await api.patch(`${BASE}/${courseId}/units/${unitId}/quiz/${quizId}/questions/restore/bulk`, { ids, restoredBy });
toast("Questions restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Questions restored.");
return data;
}),
[request],
@@ -797,12 +647,7 @@ export function CoursesProvider({ children }) {
const lesson = data?.data?.data ?? null;
if (lesson) {
setLessons((prev) => [...prev, lesson]);
toast("Lesson created successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lesson created successfully.");
}
return data;
}),
@@ -817,12 +662,7 @@ export function CoursesProvider({ children }) {
if (lesson) {
setLessons((prev) => prev.map((l) => (l.lesson_id === lessonId ? lesson : l)));
setLesson(lesson);
toast("Lesson updated successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lesson updated successfully.");
}
return data;
}),
@@ -835,12 +675,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/lessons/${lessonId}`);
setLessons((prev) => prev.filter((l) => l.lesson_id !== lessonId));
setLesson((prev) => (prev?.lesson_id === lessonId ? null : prev));
toast("Lesson archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lesson archived.");
return data;
}),
[request],
@@ -851,12 +686,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/lessons/bulk`, { data: { ids } });
setLessons((prev) => prev.filter((l) => !ids.includes(l.lesson_id)));
toast("Lessons archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lessons archived.");
return data;
}),
[request],
@@ -888,12 +718,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setLessons((prev) => prev.filter((l) => l.lesson_id !== lessonId));
toast("Lesson restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lesson restored.");
}
return data;
}),
@@ -905,12 +730,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.patch(`${BASE}/${courseId}/units/${unitId}/lessons/restore/bulk`, { ids });
setLessons((prev) => prev.filter((l) => !ids.includes(l.lesson_id)));
toast("Lessons restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lessons restored.");
return data;
}),
[request],
@@ -922,12 +742,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/lessons/${lessonId}/permanent`);
setLessons((prev) => prev.filter((l) => l.lesson_id !== lessonId));
setLesson((prev) => (prev?.lesson_id === lessonId ? null : prev));
toast("Lesson permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lesson permanently deleted.");
return data;
}),
[request],
@@ -938,12 +753,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/lessons/bulk/permanent`, { data: { ids } });
setLessons((prev) => prev.filter((l) => !ids.includes(l.lesson_id)));
toast("Lessons permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lessons permanently deleted.");
return data;
}),
[request],
@@ -971,12 +781,7 @@ export function CoursesProvider({ children }) {
const page = data?.data?.data ?? null;
if (page) {
setLessonPage(page);
toast("Lesson page saved.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Lesson page saved.");
}
return data;
}),
@@ -1006,12 +811,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setAssessment(result);
toast("Assessment created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Assessment created.");
}
return data;
}),
@@ -1025,12 +825,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setAssessment(result);
toast("Assessment updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Assessment updated.");
}
return data;
}),
@@ -1043,12 +838,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.delete(`${BASE}/${courseId}/assessment/${assessmentId}`, { data: { deletedBy } });
setAssessment(null);
setQuestions([]);
toast("Assessment archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Assessment archived.");
return data;
}),
[request],
@@ -1074,12 +864,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setAssessment(result);
toast("Assessment restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Assessment restored.");
}
return data;
}),
@@ -1108,12 +893,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setQuestions((prev) => [...prev, result]);
toast("Question added.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question added.");
}
return data;
}),
@@ -1127,12 +907,7 @@ export function CoursesProvider({ children }) {
const result = data?.data?.data ?? null;
if (result) {
setQuestions((prev) => prev.map((q) => (q.question_id === questionId ? result : q)));
toast("Question updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question updated.");
}
return data;
}),
@@ -1145,12 +920,7 @@ export function CoursesProvider({ children }) {
const { data } = await api.put(`${BASE}/${courseId}/assessment/${assessmentId}/questions/bulk-sync`, { questions, updatedBy });
const result = data?.data?.data ?? [];
setQuestions(result);
toast("Assessment saved.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Assessment saved.");
return data;
}),
[request],
@@ -1161,12 +931,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/assessment/${assessmentId}/questions/${questionId}`, { data: { deletedBy } });
setQuestions((prev) => prev.filter((q) => q.question_id !== questionId));
toast("Question archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question archived.");
return data;
}),
[request],
@@ -1177,12 +942,7 @@ export function CoursesProvider({ children }) {
request(async () => {
const { data } = await api.delete(`${BASE}/${courseId}/assessment/${assessmentId}/questions/bulk`, { data: { ids, deletedBy } });
setQuestions((prev) => prev.filter((q) => !ids.includes(q.question_id)));
toast("Questions archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Questions archived.");
return data;
}),
[request],
@@ -1203,12 +963,7 @@ export function CoursesProvider({ children }) {
(courseId, assessmentId, questionId, restoredBy) =>
request(async () => {
const { data } = await api.patch(`${BASE}/${courseId}/assessment/${assessmentId}/questions/${questionId}/restore`, { restoredBy });
toast("Question restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Question restored.");
return data;
}),
[request],
@@ -1218,12 +973,7 @@ export function CoursesProvider({ children }) {
(courseId, assessmentId, ids, restoredBy) =>
request(async () => {
const { data } = await api.patch(`${BASE}/${courseId}/assessment/${assessmentId}/questions/restore/bulk`, { ids, restoredBy });
toast("Questions restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Questions restored.");
return data;
}),
[request],
@@ -1280,12 +1030,7 @@ export function CoursesProvider({ children }) {
const saveCourseProduct = useCallback(
(courseId, payload) => request(async () => {
const { data } = await api.put(`/admin/products/courses/${courseId}/product`, payload);
toast("Product listing saved.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Product listing saved.");
return data.data ?? null;
}), [request],
);
@@ -1293,12 +1038,7 @@ export function CoursesProvider({ children }) {
const removeCourseProduct = useCallback(
(courseId) => request(async () => {
await api.delete(`/admin/products/courses/${courseId}/product`);
toast("Product listing removed.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Product listing removed.");
return true;
}), [request],
);
@@ -1313,12 +1053,7 @@ export function CoursesProvider({ children }) {
const syncCourseCategories = useCallback(
(courseId, categoryIds) => request(async () => {
const { data } = await api.post(`/admin/products/courses/${courseId}/categories`, { category_ids: categoryIds });
toast("Categories updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Categories updated.");
return data.data ?? [];
}), [request],
);
@@ -1333,12 +1068,7 @@ export function CoursesProvider({ children }) {
const syncInstructors = useCallback(
(courseId, instructors) => request(async () => {
await api.put(`${BASE}/${courseId}/instructors`, { instructors });
toast("Instructors updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Instructors updated.");
}), [request],
);
@@ -1352,12 +1082,7 @@ export function CoursesProvider({ children }) {
const syncCourseAchievements = useCallback(
(courseId, achievement_keys) => request(async () => {
await api.put(`${BASE}/${courseId}/achievements`, { achievement_keys });
toast("Rewards updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Rewards updated.");
}), [request],
);
+1 -6
View File
@@ -21,12 +21,7 @@ export function AdminDashboardProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? "Something went wrong.";
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -34,12 +34,7 @@ export function NotificationBroadcastsProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? "Something went wrong.";
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -105,12 +100,7 @@ export function NotificationBroadcastsProvider({ children }) {
const broadcast = res.data?.data?.data ?? null;
if (broadcast) {
setBroadcasts((prev) => [broadcast, ...prev]);
toast("Notification broadcast created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Notification broadcast created.");
}
return res.data;
}),
@@ -126,12 +116,7 @@ export function NotificationBroadcastsProvider({ children }) {
if (broadcast) {
setBroadcasts((prev) => prev.map((b) => (b.broadcast_id === broadcastId ? broadcast : b)));
setSelectedBroadcast(broadcast);
toast("Notification broadcast updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Notification broadcast updated.");
}
return res.data;
}),
@@ -147,12 +132,7 @@ export function NotificationBroadcastsProvider({ children }) {
if (broadcast) {
setBroadcasts((prev) => prev.map((b) => (b.broadcast_id === broadcastId ? broadcast : b)));
setSelectedBroadcast(broadcast);
toast("Notification broadcast sent.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Notification broadcast sent.");
}
return res.data;
}),
@@ -168,12 +148,7 @@ export function NotificationBroadcastsProvider({ children }) {
});
setBroadcasts((prev) => prev.filter((b) => b.broadcast_id !== broadcastId));
setSelectedBroadcast((prev) => (prev?.broadcast_id === broadcastId ? null : prev));
toast("Notification broadcast archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Notification broadcast archived.");
return res.data;
}),
[request]
@@ -187,12 +162,7 @@ export function NotificationBroadcastsProvider({ children }) {
data: { ids, deletedBy },
});
setBroadcasts((prev) => prev.filter((b) => !ids.includes(b.broadcast_id)));
toast(`${ids.length} notification broadcast(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} notification broadcast(s) archived.`);
return res.data;
}),
[request]
@@ -206,12 +176,7 @@ export function NotificationBroadcastsProvider({ children }) {
const broadcast = res.data?.data?.data ?? null;
if (broadcast) {
setBroadcasts((prev) => prev.filter((b) => b.broadcast_id !== broadcastId));
toast("Notification broadcast restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Notification broadcast restored.");
}
return res.data;
}),
@@ -224,12 +189,7 @@ export function NotificationBroadcastsProvider({ children }) {
request(async () => {
const res = await api.patch("/admin/notification-broadcasts/bulk-restore", { ids });
setBroadcasts((prev) => prev.filter((b) => !ids.includes(b.broadcast_id)));
toast(`${ids.length} notification broadcast(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} notification broadcast(s) restored.`);
return res.data;
}),
[request]
@@ -241,12 +201,7 @@ export function NotificationBroadcastsProvider({ children }) {
request(async () => {
const res = await api.delete(`/admin/notification-broadcasts/${broadcastId}/permanent`);
setBroadcasts((prev) => prev.filter((b) => b.broadcast_id !== broadcastId));
toast("Notification broadcast permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Notification broadcast permanently deleted.");
return res.data;
}),
[request]
@@ -258,12 +213,7 @@ export function NotificationBroadcastsProvider({ children }) {
request(async () => {
const res = await api.delete("/admin/notification-broadcasts/bulk/permanent", { data: { ids } });
setBroadcasts((prev) => prev.filter((b) => !ids.includes(b.broadcast_id)));
toast(`${ids.length} notification broadcast(s) permanently deleted.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} notification broadcast(s) permanently deleted.`);
return res.data;
}),
[request]
@@ -19,12 +19,7 @@ export function AdminNotificationTemplateProvider({ children }) {
setLoading(true);
try { return await fn(); }
catch (err) {
toast(err?.response?.data?.message ?? "Something went wrong.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Something went wrong.");
return null;
} finally { setLoading(false); }
}, []);
@@ -50,12 +45,7 @@ export function AdminNotificationTemplateProvider({ children }) {
prev.map((t) => (String(t.notification_template_id) === String(id) ? data.data : t))
);
if (template && String(template.notification_template_id) === String(id)) setTemplate(data.data);
toast("Notification template updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Notification template updated.");
return data.data;
}), [request, template]);
+25 -150
View File
@@ -57,12 +57,7 @@ export function AdminTaskProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? 'Something went wrong.';
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -75,12 +70,7 @@ export function AdminTaskProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? 'Something went wrong.';
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setCompletionLoading(false);
@@ -143,12 +133,7 @@ export function AdminTaskProvider({ children }) {
(payload) =>
request(async () => {
const res = await api.post(BASE, payload);
toast('Task list created.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task list created.');
return res.data?.data ?? null;
}),
[request]
@@ -158,12 +143,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, payload) =>
request(async () => {
const res = await api.patch(`${BASE}/${taskListId}`, payload);
toast('Task list updated.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task list updated.');
return res.data?.data ?? null;
}),
[request]
@@ -173,12 +153,7 @@ export function AdminTaskProvider({ children }) {
(taskListId) =>
request(async () => {
await api.delete(`${BASE}/${taskListId}`);
toast('Task list archived.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task list archived.');
return true;
}),
[request]
@@ -188,12 +163,7 @@ export function AdminTaskProvider({ children }) {
(taskListId) =>
request(async () => {
await api.patch(`${BASE}/${taskListId}/restore`);
toast('Task list restored.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task list restored.');
return true;
}),
[request]
@@ -203,12 +173,7 @@ export function AdminTaskProvider({ children }) {
(ids) =>
request(async () => {
await api.post(`${BASE}/bulk-archive`, { ids });
toast(`${ids.length} task list(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} task list(s) archived.`);
return true;
}),
[request]
@@ -218,12 +183,7 @@ export function AdminTaskProvider({ children }) {
(ids) =>
request(async () => {
await api.post(`${BASE}/bulk-restore`, { ids });
toast(`${ids.length} task list(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} task list(s) restored.`);
return true;
}),
[request]
@@ -233,12 +193,7 @@ export function AdminTaskProvider({ children }) {
(taskListId) =>
request(async () => {
await api.delete(`${BASE}/${taskListId}/permanent`);
toast('Task list permanently deleted.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task list permanently deleted.');
return true;
}),
[request]
@@ -248,12 +203,7 @@ export function AdminTaskProvider({ children }) {
(ids) =>
request(async () => {
await api.post(`${BASE}/bulk-delete`, { ids });
toast(`${ids.length} task list(s) permanently deleted.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} task list(s) permanently deleted.`);
return true;
}),
[request]
@@ -304,19 +254,9 @@ export function AdminTaskProvider({ children }) {
});
const result = res.data?.data ?? {};
if (result.assigned_ids?.length) {
toast(`${result.assigned_ids.length} group(s) assigned.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${result.assigned_ids.length} group(s) assigned.`);
} else {
toast('All selected groups were already assigned.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('All selected groups were already assigned.');
}
return result;
}),
@@ -330,12 +270,7 @@ export function AdminTaskProvider({ children }) {
group_ids: groupIds,
});
const result = res.data?.data ?? {};
toast(`${result.unassigned_ids?.length ?? 0} group(s) unassigned.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${result.unassigned_ids?.length ?? 0} group(s) unassigned.`);
return result;
}),
[request]
@@ -396,12 +331,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, payload) =>
request(async () => {
const res = await api.post(`${BASE}/${taskListId}/tasks`, payload);
toast('Task created.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task created.');
return res.data?.data?.data ?? null;
}),
[request]
@@ -411,12 +341,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, taskId, payload) =>
request(async () => {
const res = await api.patch(`${BASE}/${taskListId}/tasks/${taskId}`, payload);
toast('Task updated.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task updated.');
return res.data?.data?.data ?? null;
}),
[request]
@@ -426,12 +351,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, taskId) =>
request(async () => {
await api.delete(`${BASE}/${taskListId}/tasks/${taskId}`);
toast('Task archived.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task archived.');
return true;
}),
[request]
@@ -441,12 +361,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, taskId) =>
request(async () => {
await api.patch(`${BASE}/${taskListId}/tasks/${taskId}/restore`);
toast('Task restored.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task restored.');
return true;
}),
[request]
@@ -456,12 +371,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, ids) =>
request(async () => {
await api.post(`${BASE}/${taskListId}/tasks/bulk-archive`, { ids });
toast(`${ids.length} task(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} task(s) archived.`);
return true;
}),
[request]
@@ -471,12 +381,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, ids) =>
request(async () => {
await api.post(`${BASE}/${taskListId}/tasks/bulk-restore`, { ids });
toast(`${ids.length} task(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} task(s) restored.`);
return true;
}),
[request]
@@ -486,12 +391,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, taskId) =>
request(async () => {
await api.delete(`${BASE}/${taskListId}/tasks/${taskId}/permanent`);
toast('Task permanently deleted.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task permanently deleted.');
return true;
}),
[request]
@@ -501,12 +401,7 @@ export function AdminTaskProvider({ children }) {
(taskListId, ids) =>
request(async () => {
await api.post(`${BASE}/${taskListId}/tasks/bulk-delete`, { ids });
toast(`${ids.length} task(s) permanently deleted.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} task(s) permanently deleted.`);
return true;
}),
[request]
@@ -625,12 +520,7 @@ export function AdminTaskProvider({ children }) {
await api.delete(
`${BASE}/${taskListId}/tasks/${taskId}/completions/${completionId}`
);
toast('Completion archived.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Completion archived.');
return true;
}),
[completionRequest]
@@ -643,12 +533,7 @@ export function AdminTaskProvider({ children }) {
await api.patch(
`${BASE}/${taskListId}/tasks/${taskId}/completions/${completionId}/restore`
);
toast('Completion restored.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Completion restored.');
return true;
}),
[completionRequest]
@@ -662,12 +547,7 @@ export function AdminTaskProvider({ children }) {
`${BASE}/${taskListId}/tasks/${taskId}/completions/bulk-archive`,
{ ids }
);
toast(`${ids.length} completion(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} completion(s) archived.`);
return true;
}),
[completionRequest]
@@ -681,12 +561,7 @@ export function AdminTaskProvider({ children }) {
`${BASE}/${taskListId}/tasks/${taskId}/completions/bulk-restore`,
{ ids }
);
toast(`${ids.length} completion(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${ids.length} completion(s) restored.`);
return true;
}),
[completionRequest]
+4 -24
View File
@@ -19,12 +19,7 @@ export function AdminTierCategoriesProvider({ children }) {
setLoading(true);
try { return await fn(); }
catch (err) {
toast(err?.response?.data?.message ?? "Something went wrong.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Something went wrong.");
return null;
} finally { setLoading(false); }
}, []);
@@ -46,12 +41,7 @@ export function AdminTierCategoriesProvider({ children }) {
const createCategory = useCallback((payload) =>
request(async () => {
const { data } = await api.post("/admin/tiers/categories", payload);
toast("Tier category created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Tier category created.");
return data.data;
}), [request]);
@@ -62,12 +52,7 @@ export function AdminTierCategoriesProvider({ children }) {
prev.map((c) => (String(c.tier_category_id) === String(id) ? data.data : c))
);
if (category && String(category.tier_category_id) === String(id)) setCategory(data.data);
toast("Tier category updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Tier category updated.");
return data.data;
}), [request, category]);
@@ -75,12 +60,7 @@ export function AdminTierCategoriesProvider({ children }) {
request(async () => {
await api.delete(`/admin/tiers/categories/${id}`);
setCategories((prev) => prev.filter((c) => String(c.tier_category_id) !== String(id)));
toast("Tier category deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Tier category deleted.");
return true;
}), [request]);
+2 -12
View File
@@ -20,12 +20,7 @@ export function AdminTierPoliciesProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? "Something went wrong.";
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -50,12 +45,7 @@ export function AdminTierPoliciesProvider({ children }) {
? prev.map((b) => (b.key === key ? data.data : b))
: [...prev, data.data];
});
toast("Badge saved.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Badge saved.");
return data.data;
}), [request]);
+25 -150
View File
@@ -33,12 +33,7 @@ export function AdminTiersProvider({ children }) {
totalPages: data.data?.pagination?.totalPages ?? 1,
totalRecords: data.data?.pagination?.totalRecords ?? 0,
});
} catch { toast("Could not load plans.", {
action: {
label: "Close",
onClick: () => {}
}
}); }
} catch { toast("Could not load plans."); }
finally { setLoading(false); }
}, []);
@@ -47,12 +42,7 @@ export function AdminTiersProvider({ children }) {
try {
const { data } = await api.get(`/admin/tiers/${id}`);
setPlan(data.data ?? null);
} catch { toast("Could not load plan.", {
action: {
label: "Close",
onClick: () => {}
}
}); }
} catch { toast("Could not load plan."); }
finally { setLoading(false); }
}, []);
@@ -60,20 +50,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
const { data } = await api.post("/admin/tiers", payload);
toast("Plan created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plan created.");
return data.data;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not create plan.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not create plan.");
return null;
} finally { setLoading(false); }
}, []);
@@ -82,20 +62,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
const { data } = await api.put(`/admin/tiers/${id}`, payload);
toast("Plan updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plan updated.");
return data.data;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not update plan.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not update plan.");
return null;
} finally { setLoading(false); }
}, []);
@@ -104,20 +74,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.delete(`/admin/tiers/${id}`);
toast("Plan archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plan archived.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not archive plan.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not archive plan.");
return false;
} finally { setLoading(false); }
}, []);
@@ -126,20 +86,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.post(`/admin/tiers/${id}/restore`);
toast("Plan restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plan restored.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not restore plan.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not restore plan.");
return false;
} finally { setLoading(false); }
}, []);
@@ -148,20 +98,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.post("/admin/tiers/bulk/archive", { ids });
toast("Plans archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plans archived.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not archive plans.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not archive plans.");
return false;
} finally { setLoading(false); }
}, []);
@@ -170,20 +110,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.post("/admin/tiers/bulk/restore", { ids });
toast("Plans restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plans restored.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not restore plans.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not restore plans.");
return false;
} finally { setLoading(false); }
}, []);
@@ -192,20 +122,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.delete(`/admin/tiers/${id}/permanent`);
toast("Plan permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plan permanently deleted.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not permanently delete plan.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not permanently delete plan.");
return false;
} finally { setLoading(false); }
}, []);
@@ -214,20 +134,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.post("/admin/tiers/bulk/permanent-delete", { ids });
toast("Plans permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Plans permanently deleted.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not permanently delete plans.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not permanently delete plans.");
return false;
} finally { setLoading(false); }
}, []);
@@ -252,12 +162,7 @@ export function AdminTiersProvider({ children }) {
try {
const { data } = await api.get(`/admin/tiers/users/${userId}/tiers`);
setUserTiers(data.data ?? []);
} catch { toast("Could not load user tiers.", {
action: {
label: "Close",
onClick: () => {}
}
}); }
} catch { toast("Could not load user tiers."); }
finally { setLoading(false); }
}, []);
@@ -265,20 +170,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.post("/admin/tiers/users/tiers/grant", payload);
toast("Tier granted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Tier granted.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not grant tier.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not grant tier.");
return false;
} finally { setLoading(false); }
}, []);
@@ -287,20 +182,10 @@ export function AdminTiersProvider({ children }) {
setLoading(true);
try {
await api.patch(`/admin/tiers/users/tiers/${tid}/revoke`);
toast("Tier revoked.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Tier revoked.");
return true;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not revoke tier.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not revoke tier.");
return false;
} finally { setLoading(false); }
}, []);
@@ -321,12 +206,7 @@ export function AdminTiersProvider({ children }) {
totalPages: data.data?.pagination?.totalPages ?? 1,
totalRecords: data.data?.pagination?.totalRecords ?? 0,
});
} catch { toast("Could not load payments.", {
action: {
label: "Close",
onClick: () => {}
}
}); }
} catch { toast("Could not load payments."); }
finally { setLoading(false); }
}, []);
@@ -335,12 +215,7 @@ export function AdminTiersProvider({ children }) {
try {
const { data } = await api.get(`/admin/tiers/payments/${id}`);
setPayment(data.data ?? null);
} catch { toast("Could not load payment.", {
action: {
label: "Close",
onClick: () => {}
}
}); }
} catch { toast("Could not load payment."); }
finally { setLoading(false); }
}, []);
+17 -102
View File
@@ -45,12 +45,7 @@ export const UserProvider = ({ children }) => {
} catch (err) {
const message = err?.response?.data?.message || err.message || "Something went wrong.";
setError(message);
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -113,12 +108,7 @@ export const UserProvider = ({ children }) => {
(payload) =>
request(async () => {
const res = await api.post(`${BASE}/users/staff`, payload);
toast("Staff user added successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Staff user added successfully.");
return res.data;
}),
[request]
@@ -132,12 +122,7 @@ export const UserProvider = ({ children }) => {
setUsers((prev) =>
prev.map((u) => (u.user_id === userId ? { ...u, ...res.data?.data } : u))
);
toast("User updated successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("User updated successfully.");
return res.data;
}),
[request]
@@ -151,12 +136,7 @@ export const UserProvider = ({ children }) => {
setUsers((prev) =>
prev.map((u) => (u.user_id === userId ? { ...u, is_active: false } : u))
);
toast("User deactivated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("User deactivated.");
return res.data;
}),
[request]
@@ -174,12 +154,7 @@ export const UserProvider = ({ children }) => {
deactivated_ids.includes(u.user_id) ? { ...u, is_active: false } : u
)
);
toast(`${deactivated_ids.length} user(s) deactivated.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${deactivated_ids.length} user(s) deactivated.`);
}
return res.data;
}),
@@ -194,12 +169,7 @@ export const UserProvider = ({ children }) => {
setUsers((prev) =>
prev.map((u) => (u.user_id === userId ? { ...u, is_active: true } : u))
);
toast("User restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("User restored.");
return res.data;
}),
[request]
@@ -217,12 +187,7 @@ export const UserProvider = ({ children }) => {
restored_ids.includes(u.user_id) ? { ...u, is_active: true } : u
)
);
toast(`${restored_ids.length} user(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${restored_ids.length} user(s) restored.`);
}
return res.data;
}),
@@ -235,12 +200,7 @@ export const UserProvider = ({ children }) => {
request(async () => {
const res = await api.delete(`${BASE}/users/${userId}/permanent`);
setUsers((prev) => prev.filter((u) => u.user_id !== userId));
toast("User permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("User permanently deleted.");
return res.data;
}),
[request]
@@ -254,12 +214,7 @@ export const UserProvider = ({ children }) => {
const { deleted_ids } = res.data?.data ?? {};
if (deleted_ids?.length) {
setUsers((prev) => prev.filter((u) => !deleted_ids.includes(u.user_id)));
toast(`${deleted_ids.length} user(s) permanently deleted.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${deleted_ids.length} user(s) permanently deleted.`);
}
return res.data;
}),
@@ -285,12 +240,7 @@ export const UserProvider = ({ children }) => {
setSessions((prev) =>
prev.map((s) => (s.session_id === sessionId ? { ...s, is_active: false } : s))
);
toast("Session terminated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Session terminated.");
return res.data;
}),
[request]
@@ -334,12 +284,7 @@ export const UserProvider = ({ children }) => {
});
return d;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load activity.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load activity.");
return null;
} finally {
setActivityLoading(false);
@@ -366,12 +311,7 @@ export const UserProvider = ({ children }) => {
setAchievements(res.data?.data ?? []);
return res.data?.data;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load achievements.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load achievements.");
return [];
} finally {
setAchievementsLoading(false);
@@ -387,12 +327,7 @@ export const UserProvider = ({ children }) => {
prev.map((u) => (u.user_id === userId ? { ...u, is_banned: true } : u))
);
if (user?.user_id === userId) setUser((prev) => prev ? { ...prev, is_banned: true } : prev);
toast("User banned successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("User banned successfully.");
return res.data;
}),
[request, user]
@@ -407,12 +342,7 @@ export const UserProvider = ({ children }) => {
prev.map((u) => (u.user_id === userId ? { ...u, is_banned: false } : u))
);
if (user?.user_id === userId) setUser((prev) => prev ? { ...prev, is_banned: false } : prev);
toast("User unbanned successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("User unbanned successfully.");
return res.data;
}),
[request, user]
@@ -428,12 +358,7 @@ export const UserProvider = ({ children }) => {
setUsers((prev) =>
prev.map((u) => (banned_ids.includes(u.user_id) ? { ...u, is_banned: true } : u))
);
toast(`${banned_ids.length} user(s) banned.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${banned_ids.length} user(s) banned.`);
}
return res.data;
}),
@@ -450,12 +375,7 @@ export const UserProvider = ({ children }) => {
setUsers((prev) =>
prev.map((u) => (unbanned_ids.includes(u.user_id) ? { ...u, is_banned: false } : u))
);
toast(`${unbanned_ids.length} user(s) unbanned.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${unbanned_ids.length} user(s) unbanned.`);
}
return res.data;
}),
@@ -470,12 +390,7 @@ export const UserProvider = ({ children }) => {
setBans(res.data?.data ?? []);
return res.data?.data;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load ban history.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load ban history.");
return [];
} finally {
setBansLoading(false);
+11 -66
View File
@@ -27,12 +27,7 @@ export function UserGroupProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? "Something went wrong.";
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -126,12 +121,7 @@ export function UserGroupProvider({ children }) {
request(async () => {
const res = await api.post(`${BASE}/groups`, { name, description, group_code });
setGroups((prev) => [res.data?.data, ...prev]);
toast("Group created successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Group created successfully.");
return res.data;
}),
[request]
@@ -146,12 +136,7 @@ export function UserGroupProvider({ children }) {
prev.map((g) => (g.group_id === gid ? { ...g, ...res.data?.data } : g))
);
setGroup((prev) => (prev?.group_id === gid ? { ...prev, ...res.data?.data } : prev));
toast("Group updated successfully.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Group updated successfully.");
return res.data;
}),
[request]
@@ -165,12 +150,7 @@ export function UserGroupProvider({ children }) {
setGroups((prev) =>
prev.map((g) => (g.group_id === gid ? { ...g, is_active: false } : g))
);
toast("Group deactivated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Group deactivated.");
return res.data;
}),
[request]
@@ -188,12 +168,7 @@ export function UserGroupProvider({ children }) {
deactivated_ids.includes(g.group_id) ? { ...g, is_active: false } : g
)
);
toast(`${deactivated_ids.length} group(s) deactivated.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${deactivated_ids.length} group(s) deactivated.`);
}
return res.data;
}),
@@ -208,12 +183,7 @@ export function UserGroupProvider({ children }) {
setGroups((prev) =>
prev.map((g) => (g.group_id === gid ? { ...g, is_active: true } : g))
);
toast("Group restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Group restored.");
return res.data;
}),
[request]
@@ -231,12 +201,7 @@ export function UserGroupProvider({ children }) {
restored_ids.includes(g.group_id) ? { ...g, is_active: true } : g
)
);
toast(`${restored_ids.length} group(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${restored_ids.length} group(s) restored.`);
}
return res.data;
}),
@@ -249,12 +214,7 @@ export function UserGroupProvider({ children }) {
request(async () => {
const res = await api.delete(`${BASE}/groups/${gid}/permanent`);
setGroups((prev) => prev.filter((g) => g.group_id !== gid));
toast("Group permanently deleted.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Group permanently deleted.");
return res.data;
}),
[request]
@@ -268,12 +228,7 @@ export function UserGroupProvider({ children }) {
const { deleted_ids } = res.data?.data ?? {};
if (deleted_ids?.length) {
setGroups((prev) => prev.filter((g) => !deleted_ids.includes(g.group_id)));
toast(`${deleted_ids.length} group(s) permanently deleted.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${deleted_ids.length} group(s) permanently deleted.`);
}
return res.data;
}),
@@ -286,12 +241,7 @@ export function UserGroupProvider({ children }) {
request(async () => {
const res = await api.post(`${BASE}/groups/${gid}/users`, { user_ids });
setUsersNotIn((prev) => prev.filter((u) => !user_ids.includes(u.user_id)));
toast("Users added to group.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Users added to group.");
return res.data;
}),
[request]
@@ -304,12 +254,7 @@ export function UserGroupProvider({ children }) {
const res = await api.delete(`${BASE}/groups/${gid}/users`, { data: { user_ids } });
setMembers((prev) => prev.filter((u) => !user_ids.includes(u.user_id)));
setUsersIn((prev) => prev.filter((u) => !user_ids.includes(u.user_id)));
toast("Users removed from group.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Users removed from group.");
return res.data;
}),
[request]
+13
View File
@@ -97,6 +97,18 @@ export function AuthProvider({ children }) {
return { success: true, email: data.data.email }
} catch (err) {
const message = err.response?.data?.message || 'Could not process request.'
const isGoogleAccount = err.response?.data?.errors?.google === true
return { success: false, message, isGoogleAccount }
}
}, [])
// ── Verify reset OTP (step 2 — does not change the password) ──────────────
const verifyResetOtp = useCallback(async ({ email, otp }) => {
try {
await api.post('/auth/verify-reset-otp', { email, otp })
return { success: true }
} catch (err) {
const message = err.response?.data?.message || 'Verification failed.'
return { success: false, message }
}
}, [])
@@ -158,6 +170,7 @@ export function AuthProvider({ children }) {
verifyOTP,
resendOTP,
forgotPassword,
verifyResetOtp,
resetPassword,
logout,
loading,
@@ -58,12 +58,7 @@ export function CourseReadingProgressProvider({ children }) {
);
return rows;
} catch (err) {
toast(err?.response?.data?.message ?? 'Could not load course progress.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? 'Could not load course progress.');
return null;
} finally {
setLoading(false);
@@ -106,12 +101,7 @@ export function CourseReadingProgressProvider({ children }) {
delete next[lessonUuid];
return next;
});
toast(err?.response?.data?.message ?? 'Could not update progress.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? 'Could not update progress.');
return null;
}
}, []);
+13 -78
View File
@@ -42,12 +42,7 @@ export function ClientCoursesProvider({ children }) {
const { data } = await api.get("/client/courses");
setCourses(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load courses.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load courses.");
} finally {
setCoursesLoading(false);
}
@@ -63,12 +58,7 @@ export function ClientCoursesProvider({ children }) {
if (err?.response?.status === 403) {
setCourseBlocked(true); // let the UI show an upgrade prompt
} else {
toast(err?.response?.data?.message ?? "Could not load course.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load course.");
}
} finally {
setCourseLoading(false);
@@ -81,12 +71,7 @@ export function ClientCoursesProvider({ children }) {
const { data } = await api.get(`/client/courses/${courseId}/units/${unitId}`);
setUnit(data.data ?? null);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load unit.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load unit.");
} finally {
setUnitLoading(false);
}
@@ -100,12 +85,7 @@ export function ClientCoursesProvider({ children }) {
);
setLesson(data.data ?? null);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load lesson.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load lesson.");
} finally {
setLessonLoading(false);
}
@@ -119,12 +99,7 @@ export function ClientCoursesProvider({ children }) {
);
setQuiz(data.data ?? null);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load quiz.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load quiz.");
} finally {
setQuizLoading(false);
}
@@ -136,12 +111,7 @@ export function ClientCoursesProvider({ children }) {
const { data } = await api.get(`/client/courses/${courseId}/assessment`);
setAssessment(data.data ?? null);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load assessment.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load assessment.");
} finally {
setAssessmentLoading(false);
}
@@ -155,12 +125,7 @@ export function ClientCoursesProvider({ children }) {
);
return data.data ?? null;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not submit quiz.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not submit quiz.");
return null;
}
}, []);
@@ -170,12 +135,7 @@ export function ClientCoursesProvider({ children }) {
const { data } = await api.post(`/client/courses/${courseId}/assessment/${assessmentId}/start`);
return data.data ?? null;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not start assessment.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not start assessment.");
return null;
}
}, []);
@@ -207,12 +167,7 @@ export function ClientCoursesProvider({ children }) {
);
return data.data ?? null;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not submit assessment.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not submit assessment.");
return null;
}
}, []);
@@ -229,12 +184,7 @@ export function ClientCoursesProvider({ children }) {
const { data } = await api.get("/client/course-purchases");
setPurchases(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load purchases.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load purchases.");
} finally { setPurchasesLoading(false); }
}, []);
@@ -244,12 +194,7 @@ export function ClientCoursesProvider({ children }) {
const { data } = await api.post("/client/course-purchases/order", { product_id: productId });
return data.data ?? null;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not create order.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not create order.");
return null;
} finally { setPurchaseLoading(false); }
}, []);
@@ -258,20 +203,10 @@ export function ClientCoursesProvider({ children }) {
setPurchaseLoading(true);
try {
const { data } = await api.post("/client/course-purchases/capture", { order_id: orderId });
toast("Purchase confirmed! You now have access to this course.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Purchase confirmed! You now have access to this course.");
return data.data ?? null;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not capture payment.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not capture payment.");
return null;
} finally { setPurchaseLoading(false); }
}, []);
+1 -6
View File
@@ -30,12 +30,7 @@ export function GroupProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? 'Something went wrong.';
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
+3 -18
View File
@@ -45,12 +45,7 @@ export function TaskProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? 'Something went wrong.';
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -63,12 +58,7 @@ export function TaskProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? 'Something went wrong.';
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setCompletionLoading(false);
@@ -165,12 +155,7 @@ export function TaskProvider({ children }) {
payload
);
const data = res.data?.data ?? null;
toast('Task submitted successfully.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Task submitted successfully.');
// Immediately update latest completion so UI reflects the new state
setLatestCompletion(data);
// Prepend to history if it's already loaded
+1 -6
View File
@@ -45,12 +45,7 @@ export function TaskProgressProvider({ children }) {
return await fn();
} catch (err) {
const message = err?.response?.data?.message ?? 'Something went wrong.';
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
+8 -48
View File
@@ -44,20 +44,10 @@ export function ClientTiersProvider({ children }) {
// known-active tier — this prevents the "Free" flash after an upgrade.
setMyTier(prev => (tier === null && prev?.status === 'active') ? prev : tier);
if (tier?.just_expired) {
toast("Your subscription has expired. You've been moved to the Free plan.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Your subscription has expired. You've been moved to the Free plan.");
}
} catch (err) {
if (!silent) toast(err?.response?.data?.message ?? "Could not load tier.", {
action: {
label: "Close",
onClick: () => {}
}
});
if (!silent) toast(err?.response?.data?.message ?? "Could not load tier.");
} finally {
if (!silent) setTierLoading(false);
}
@@ -88,12 +78,7 @@ export function ClientTiersProvider({ children }) {
const { data } = await api.get("/client/tiers/me/history");
setTierHistory(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load tier history.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load tier history.");
} finally {
setTierHistoryLoading(false);
}
@@ -105,12 +90,7 @@ export function ClientTiersProvider({ children }) {
const { data } = await api.get("/client/tiers/plans");
setPlans(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load plans.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load plans.");
} finally {
setPlansLoading(false);
}
@@ -138,12 +118,7 @@ export function ClientTiersProvider({ children }) {
const { data } = await api.post("/client/tiers/checkout/order", payload);
return data.data ?? null;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not create order.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not create order.");
return null;
} finally {
setCheckoutLoading(false);
@@ -155,24 +130,14 @@ export function ClientTiersProvider({ children }) {
setCheckoutLoading(true);
try {
const { data } = await api.post("/client/tiers/checkout/capture", { order_id });
toast(data.message ?? "Payment successful. Tier activated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(data.message ?? "Payment successful. Tier activated.");
setMyTier({ tier: data.data?.tier, expires_at: data.data?.expires_at, status: "active" });
// Refresh from server so the browser cache holds fresh Premium data — prevents
// subsequent getMyTier() calls from getting a stale 304 with the old Free/null response.
getMyTier({ silent: true });
return data.data ?? null;
} catch (err) {
toast(err?.response?.data?.message ?? "Payment capture failed.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Payment capture failed.");
return null;
} finally {
setCheckoutLoading(false);
@@ -197,12 +162,7 @@ export function ClientTiersProvider({ children }) {
const { data } = await api.get("/client/tiers/me/payments");
setPayments(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load payment history.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load payment history.");
} finally {
setPaymentsLoading(false);
}
+11 -66
View File
@@ -34,12 +34,7 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
setProfile(fresh);
return fresh;
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load profile.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load profile.");
return null;
} finally {
setProfileLoading(false);
@@ -52,20 +47,10 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
const { data } = await api.put(`${apiBase}/profile`, { personal_info });
setProfile(data.data ?? null);
setUser((prev) => ({ ...prev, ...data.data }));
toast(data.message ?? "Profile updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(data.message ?? "Profile updated.");
return { success: true, data: data.data };
} catch (err) {
toast(err?.response?.data?.message ?? "Could not update profile.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not update profile.");
return { success: false };
} finally {
setProfileLoading(false);
@@ -78,12 +63,7 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
const { data } = await api.get(`${apiBase}/sessions`);
setSessions(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load sessions.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load sessions.");
} finally {
setSessionsLoading(false);
}
@@ -94,20 +74,10 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
try {
await api.delete(`${apiBase}/sessions/${sessionId}`);
setSessions((prev) => prev.filter((s) => s.session_id !== sessionId));
toast("Session revoked.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Session revoked.");
return { success: true };
} catch (err) {
toast(err?.response?.data?.message ?? "Could not revoke session.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not revoke session.");
return { success: false };
} finally {
setRevokingId(null);
@@ -122,20 +92,10 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
const { data } = await api.post(`${apiBase}/profile/avatar`, formData);
setProfile(data.data ?? null);
setUser((prev) => ({ ...prev, personal_info: data.data?.personal_info }));
toast('Avatar updated.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Avatar updated.');
return { success: true };
} catch (err) {
toast(err?.response?.data?.message ?? 'Could not update avatar.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? 'Could not update avatar.');
return { success: false };
} finally {
setAvatarLoading(false);
@@ -154,20 +114,10 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
...prev,
personal_info: { ...(prev?.personal_info ?? {}), avatar: null },
}));
toast('Avatar removed.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast('Avatar removed.');
return { success: true };
} catch (err) {
toast(err?.response?.data?.message ?? 'Could not remove avatar.', {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? 'Could not remove avatar.');
return { success: false };
} finally {
setAvatarLoading(false);
@@ -180,12 +130,7 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
const { data } = await api.get(`${apiBase}/achievements`);
setAchievements(data.data ?? []);
} catch (err) {
toast(err?.response?.data?.message ?? "Could not load achievements.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast(err?.response?.data?.message ?? "Could not load achievements.");
} finally {
setAchievementsLoading(false);
}
+2 -12
View File
@@ -41,12 +41,7 @@ export const StaffGroupProvider = ({ children }) => {
} catch (err) {
const message = err?.response?.data?.message || err.message || "Something went wrong.";
setError(message);
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -61,12 +56,7 @@ export const StaffGroupProvider = ({ children }) => {
return await fn();
} catch (err) {
const message = err?.response?.data?.message || err.message || "Something went wrong.";
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setMembersLoading(false);
+1 -6
View File
@@ -27,12 +27,7 @@ export const StaffScoreProvider = ({ children }) => {
} catch (err) {
const message = err?.response?.data?.message || err.message || "Something went wrong.";
setError(message);
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
+13 -78
View File
@@ -53,12 +53,7 @@ export const StaffTaskProvider = ({ children }) => {
} catch (err) {
const message = err?.response?.data?.message || err.message || "Something went wrong.";
setError(message);
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);
@@ -139,12 +134,7 @@ export const StaffTaskProvider = ({ children }) => {
const res = await api.post(`${BASE}/task-lists`, payload);
const created = res.data?.data;
if (created) setTaskLists((prev) => [created, ...prev]);
toast("Task list created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task list created.");
return res.data;
}),
[request]
@@ -163,12 +153,7 @@ export const StaffTaskProvider = ({ children }) => {
if (taskList?.task_list_id === taskListId)
setTaskList((prev) => ({ ...prev, ...updated }));
}
toast("Task list updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task list updated.");
return res.data;
}),
[request, taskList]
@@ -181,12 +166,7 @@ export const StaffTaskProvider = ({ children }) => {
const res = await api.post(`${BASE}/task-lists/${taskListId}/archive`);
setTaskLists((prev) => prev.filter((tl) => tl.task_list_id !== taskListId));
if (taskList?.task_list_id === taskListId) setTaskList(null);
toast("Task list archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task list archived.");
return res.data;
}),
[request, taskList]
@@ -198,12 +178,7 @@ export const StaffTaskProvider = ({ children }) => {
request(async () => {
const res = await api.post(`${BASE}/task-lists/${taskListId}/restore`);
setTaskLists((prev) => prev.filter((tl) => tl.task_list_id !== taskListId));
toast("Task list restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task list restored.");
return res.data;
}),
[request]
@@ -218,12 +193,7 @@ export const StaffTaskProvider = ({ children }) => {
setTaskLists((prev) =>
prev.filter((tl) => !archived_ids.includes(tl.task_list_id))
);
toast(`${archived_ids.length} task list(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${archived_ids.length} task list(s) archived.`);
return res.data;
}),
[request]
@@ -238,12 +208,7 @@ export const StaffTaskProvider = ({ children }) => {
setTaskLists((prev) =>
prev.filter((tl) => !restored_ids.includes(tl.task_list_id))
);
toast(`${restored_ids.length} task list(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${restored_ids.length} task list(s) restored.`);
return res.data;
}),
[request]
@@ -325,12 +290,7 @@ export const StaffTaskProvider = ({ children }) => {
)
);
}
toast("Task created.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task created.");
return res.data;
}),
[request]
@@ -360,12 +320,7 @@ export const StaffTaskProvider = ({ children }) => {
);
if (task?.task_id === taskId) setTask((prev) => ({ ...prev, ...updated }));
}
toast("Task updated.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task updated.");
return res.data;
}),
[request, task]
@@ -384,12 +339,7 @@ export const StaffTaskProvider = ({ children }) => {
: tl
)
);
toast("Task archived.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task archived.");
return res.data;
}),
[request]
@@ -401,12 +351,7 @@ export const StaffTaskProvider = ({ children }) => {
request(async () => {
const res = await api.post(`${BASE}/task-lists/${taskListId}/tasks/${taskId}/restore`);
setTasks((prev) => prev.filter((t) => t.task_id !== taskId));
toast("Task restored.", {
action: {
label: "Close",
onClick: () => {}
}
});
toast("Task restored.");
return res.data;
}),
[request]
@@ -419,12 +364,7 @@ export const StaffTaskProvider = ({ children }) => {
const res = await api.post(`${BASE}/task-lists/${taskListId}/tasks/bulk-archive`, { ids });
const { archived_ids = [] } = res.data?.data ?? {};
setTasks((prev) => prev.filter((t) => !archived_ids.includes(t.task_id)));
toast(`${archived_ids.length} task(s) archived.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${archived_ids.length} task(s) archived.`);
return res.data;
}),
[request]
@@ -437,12 +377,7 @@ export const StaffTaskProvider = ({ children }) => {
const res = await api.post(`${BASE}/task-lists/${taskListId}/tasks/bulk-restore`, { ids });
const { restored_ids = [] } = res.data?.data ?? {};
setTasks((prev) => prev.filter((t) => !restored_ids.includes(t.task_id)));
toast(`${restored_ids.length} task(s) restored.`, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(`${restored_ids.length} task(s) restored.`);
return res.data;
}),
[request]
+1 -6
View File
@@ -37,12 +37,7 @@ export const StaffUserProvider = ({ children }) => {
} catch (err) {
const message = err?.response?.data?.message || err.message || "Something went wrong.";
setError(message);
toast(message, {
action: {
label: "Close",
onClick: () => {}
}
});
toast(message);
return null;
} finally {
setLoading(false);