@@ -19,7 +19,12 @@ export function AdminAchievementsProvider({ children }) {
|
||||
setLoading(true);
|
||||
try { return await fn(); }
|
||||
catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Something went wrong.");
|
||||
toast(err?.response?.data?.message ?? "Something went wrong.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -41,7 +46,12 @@ export function AdminAchievementsProvider({ children }) {
|
||||
const createAchievement = useCallback((payload) =>
|
||||
request(async () => {
|
||||
const { data } = await api.post("/admin/achievements", payload);
|
||||
toast.success("Achievement created.");
|
||||
toast("Achievement created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
}), [request]);
|
||||
|
||||
@@ -52,7 +62,12 @@ 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.success("Achievement updated.");
|
||||
toast("Achievement updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
}), [request, achievement]);
|
||||
|
||||
@@ -60,7 +75,12 @@ 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.success("Achievement deleted.");
|
||||
toast("Achievement deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}), [request]);
|
||||
|
||||
|
||||
@@ -34,7 +34,12 @@ export function AdvertisementsProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? "Something went wrong.";
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -100,7 +105,12 @@ export function AdvertisementsProvider({ children }) {
|
||||
const advertisement = res.data?.data?.data ?? null;
|
||||
if (advertisement) {
|
||||
setAdvertisements((prev) => [advertisement, ...prev]);
|
||||
toast.success("Advertisement created successfully.");
|
||||
toast("Advertisement created successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -116,7 +126,12 @@ export function AdvertisementsProvider({ children }) {
|
||||
if (advertisement) {
|
||||
setAdvertisements((prev) => prev.map((a) => (a.advertisement_id === advertisementId ? advertisement : a)));
|
||||
setSelectedAdvertisement(advertisement);
|
||||
toast.success("Advertisement updated successfully.");
|
||||
toast("Advertisement updated successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -132,7 +147,12 @@ export function AdvertisementsProvider({ children }) {
|
||||
});
|
||||
setAdvertisements((prev) => prev.filter((a) => a.advertisement_id !== advertisementId));
|
||||
setSelectedAdvertisement((prev) => (prev?.advertisement_id === advertisementId ? null : prev));
|
||||
toast.success("Advertisement archived.");
|
||||
toast("Advertisement archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -146,7 +166,12 @@ export function AdvertisementsProvider({ children }) {
|
||||
data: { ids, deletedBy },
|
||||
});
|
||||
setAdvertisements((prev) => prev.filter((a) => !ids.includes(a.advertisement_id)));
|
||||
toast.success(`${ids.length} advertisement(s) archived.`);
|
||||
toast(`${ids.length} advertisement(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -160,7 +185,12 @@ export function AdvertisementsProvider({ children }) {
|
||||
const advertisement = res.data?.data?.data ?? null;
|
||||
if (advertisement) {
|
||||
setAdvertisements((prev) => prev.filter((a) => a.advertisement_id !== advertisementId));
|
||||
toast.success("Advertisement restored.");
|
||||
toast("Advertisement restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -173,7 +203,12 @@ 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.success(`${ids.length} advertisement(s) restored.`);
|
||||
toast(`${ids.length} advertisement(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -185,7 +220,12 @@ 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.success("Advertisement permanently deleted.");
|
||||
toast("Advertisement permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -197,7 +237,12 @@ 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.success(`${ids.length} advertisement(s) permanently deleted.`);
|
||||
toast(`${ids.length} advertisement(s) permanently deleted.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
|
||||
@@ -69,7 +69,12 @@ export function AssetsProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? "Something went wrong.";
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -201,7 +206,12 @@ export function AssetsProvider({ children }) {
|
||||
if (asset) {
|
||||
setAssets((prev) => [asset, ...prev]);
|
||||
invalidateListCache();
|
||||
toast.success("Asset uploaded successfully.");
|
||||
toast("Asset uploaded successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -227,7 +237,12 @@ export function AssetsProvider({ children }) {
|
||||
setAssets((prev) => prev.map((a) => (a.asset_id === assetId ? asset : a)));
|
||||
setSelectedAsset(asset);
|
||||
invalidateListCache();
|
||||
toast.success("Asset updated successfully.");
|
||||
toast("Asset updated successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -244,7 +259,12 @@ export function AssetsProvider({ children }) {
|
||||
setAssets((prev) => prev.filter((a) => a.asset_id !== assetId));
|
||||
setSelectedAsset((prev) => (prev?.asset_id === assetId ? null : prev));
|
||||
invalidateListCache();
|
||||
toast.success("Asset archived.");
|
||||
toast("Asset archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -259,7 +279,12 @@ export function AssetsProvider({ children }) {
|
||||
});
|
||||
setAssets((prev) => prev.filter((a) => !ids.includes(a.asset_id)));
|
||||
invalidateListCache();
|
||||
toast.success(`${ids.length} asset(s) archived.`);
|
||||
toast(`${ids.length} asset(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -274,7 +299,12 @@ export function AssetsProvider({ children }) {
|
||||
if (asset) {
|
||||
setAssets((prev) => prev.filter((a) => a.asset_id !== assetId));
|
||||
invalidateListCache();
|
||||
toast.success("Asset restored.");
|
||||
toast("Asset restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -288,7 +318,12 @@ 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.success(`${ids.length} asset(s) restored.`);
|
||||
toast(`${ids.length} asset(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -302,7 +337,12 @@ export function AssetsProvider({ children }) {
|
||||
setAssets((prev) => prev.filter((a) => a.asset_id !== assetId));
|
||||
setSelectedAsset((prev) => (prev?.asset_id === assetId ? null : prev));
|
||||
invalidateListCache();
|
||||
toast.success("Asset permanently deleted.");
|
||||
toast("Asset permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -317,7 +357,12 @@ export function AssetsProvider({ children }) {
|
||||
});
|
||||
setAssets((prev) => prev.filter((a) => !ids.includes(a.asset_id)));
|
||||
invalidateListCache();
|
||||
toast.success(`${ids.length} asset(s) permanently deleted.`);
|
||||
toast(`${ids.length} asset(s) permanently deleted.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
|
||||
@@ -13,7 +13,12 @@ export function AdminCategoriesProvider({ children }) {
|
||||
setLoading(true);
|
||||
try { return await fn(); }
|
||||
catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Something went wrong.");
|
||||
toast(err?.response?.data?.message ?? "Something went wrong.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -32,28 +37,48 @@ export function AdminCategoriesProvider({ children }) {
|
||||
|
||||
const createCategory = useCallback((payload) => wrap(async () => {
|
||||
const { data } = await api.post("/admin/categories", payload);
|
||||
toast.success("Category created.");
|
||||
toast("Category created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
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.success("Category updated.");
|
||||
toast("Category updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
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.success("Category archived.");
|
||||
toast("Category archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
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.success("Category restored.");
|
||||
toast("Category restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}), [wrap]);
|
||||
|
||||
|
||||
@@ -43,7 +43,12 @@ export function AdminCourseReadingProgressProvider({ children }) {
|
||||
setProgressList(data.data ?? []);
|
||||
setDetailCache({});
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? 'Could not load reading progress.');
|
||||
toast(err?.response?.data?.message ?? 'Could not load reading progress.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setListLoading(false);
|
||||
}
|
||||
@@ -60,7 +65,12 @@ export function AdminCourseReadingProgressProvider({ children }) {
|
||||
setDetailCache((prev) => ({ ...prev, [userId]: breakdown }));
|
||||
return breakdown;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? 'Could not load user progress.');
|
||||
toast(err?.response?.data?.message ?? 'Could not load user progress.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setDetailLoading(false);
|
||||
|
||||
@@ -52,8 +52,18 @@ export function CoursesProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? "Something went wrong.";
|
||||
if (err.status === 404 && message) toast.warning(message);
|
||||
else toast.error(message);
|
||||
if (err.status === 404 && message) toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
else toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -111,7 +121,12 @@ export function CoursesProvider({ children }) {
|
||||
const course = data?.data?.data ?? null;
|
||||
if (course) {
|
||||
setCourses((prev) => [course, ...prev]);
|
||||
toast.success("Course created successfully.");
|
||||
toast("Course created successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -126,7 +141,12 @@ export function CoursesProvider({ children }) {
|
||||
if (course) {
|
||||
setCourses((prev) => prev.map((c) => (c.course_id === courseId ? course : c)));
|
||||
setCourse(course);
|
||||
toast.success("Course updated successfully.");
|
||||
toast("Course updated successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -139,7 +159,12 @@ 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.success("Course archived.");
|
||||
toast("Course archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -150,7 +175,12 @@ 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.success("Courses archived.");
|
||||
toast("Courses archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -181,7 +211,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setCourses((prev) => prev.filter((c) => c.course_id !== courseId));
|
||||
toast.success("Course restored.");
|
||||
toast("Course restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -193,7 +228,12 @@ 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.success("Courses restored.");
|
||||
toast("Courses restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -205,7 +245,12 @@ 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.success("Course permanently deleted.");
|
||||
toast("Course permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -216,7 +261,12 @@ 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.success("Courses permanently deleted.");
|
||||
toast("Courses permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -255,7 +305,12 @@ export function CoursesProvider({ children }) {
|
||||
request(async () => {
|
||||
const { data } = await api.put(`${BASE}/${courseId}/prerequisites`, { prerequisites });
|
||||
setPrerequisites(prerequisites);
|
||||
toast.success("Prerequisites updated.");
|
||||
toast("Prerequisites updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -305,7 +360,12 @@ export function CoursesProvider({ children }) {
|
||||
const unit = data?.data?.data ?? null;
|
||||
if (unit) {
|
||||
setUnits((prev) => [...prev, unit]);
|
||||
toast.success("Unit created successfully.");
|
||||
toast("Unit created successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -320,7 +380,12 @@ export function CoursesProvider({ children }) {
|
||||
if (unit) {
|
||||
setUnits((prev) => prev.map((u) => (u.unit_id === unitId ? unit : u)));
|
||||
setUnit(unit);
|
||||
toast.success("Unit updated successfully.");
|
||||
toast("Unit updated successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -333,7 +398,12 @@ 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.success("Unit archived.");
|
||||
toast("Unit archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -344,7 +414,12 @@ 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.success("Units archived.");
|
||||
toast("Units archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -376,7 +451,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setUnits((prev) => prev.filter((u) => u.unit_id !== unitId));
|
||||
toast.success("Unit restored.");
|
||||
toast("Unit restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -388,7 +468,12 @@ 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.success("Units restored.");
|
||||
toast("Units restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -400,7 +485,12 @@ 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.success("Unit permanently deleted.");
|
||||
toast("Unit permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -411,7 +501,12 @@ 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.success("Units permanently deleted.");
|
||||
toast("Units permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -450,7 +545,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setQuiz(result);
|
||||
toast.success("Quiz created.");
|
||||
toast("Quiz created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -464,7 +564,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setQuiz(result);
|
||||
toast.success("Quiz updated.");
|
||||
toast("Quiz updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -477,7 +582,12 @@ export function CoursesProvider({ children }) {
|
||||
const { data } = await api.delete(`${BASE}/${courseId}/units/${unitId}/quiz/${quizId}`, { data: { deletedBy } });
|
||||
setQuiz(null);
|
||||
setQuestions([]);
|
||||
toast.success("Quiz archived.");
|
||||
toast("Quiz archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -503,7 +613,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setQuiz(result);
|
||||
toast.success("Quiz restored.");
|
||||
toast("Quiz restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -532,7 +647,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setQuestions((prev) => [...prev, result]);
|
||||
toast.success("Question added.");
|
||||
toast("Question added.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -546,7 +666,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setQuestions((prev) => prev.map((q) => (q.question_id === questionId ? result : q)));
|
||||
toast.success("Question updated.");
|
||||
toast("Question updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -559,7 +684,12 @@ 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.success("Quiz saved.");
|
||||
toast("Quiz saved.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -570,7 +700,12 @@ 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.success("Question archived.");
|
||||
toast("Question archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -581,7 +716,12 @@ 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.success("Questions archived.");
|
||||
toast("Questions archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -602,7 +742,12 @@ 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.success("Question restored.");
|
||||
toast("Question restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -612,7 +757,12 @@ 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.success("Questions restored.");
|
||||
toast("Questions restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -647,7 +797,12 @@ export function CoursesProvider({ children }) {
|
||||
const lesson = data?.data?.data ?? null;
|
||||
if (lesson) {
|
||||
setLessons((prev) => [...prev, lesson]);
|
||||
toast.success("Lesson created successfully.");
|
||||
toast("Lesson created successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -662,7 +817,12 @@ export function CoursesProvider({ children }) {
|
||||
if (lesson) {
|
||||
setLessons((prev) => prev.map((l) => (l.lesson_id === lessonId ? lesson : l)));
|
||||
setLesson(lesson);
|
||||
toast.success("Lesson updated successfully.");
|
||||
toast("Lesson updated successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -675,7 +835,12 @@ 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.success("Lesson archived.");
|
||||
toast("Lesson archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -686,7 +851,12 @@ 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.success("Lessons archived.");
|
||||
toast("Lessons archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -718,7 +888,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setLessons((prev) => prev.filter((l) => l.lesson_id !== lessonId));
|
||||
toast.success("Lesson restored.");
|
||||
toast("Lesson restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -730,7 +905,12 @@ 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.success("Lessons restored.");
|
||||
toast("Lessons restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -742,7 +922,12 @@ 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.success("Lesson permanently deleted.");
|
||||
toast("Lesson permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -753,7 +938,12 @@ 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.success("Lessons permanently deleted.");
|
||||
toast("Lessons permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -781,7 +971,12 @@ export function CoursesProvider({ children }) {
|
||||
const page = data?.data?.data ?? null;
|
||||
if (page) {
|
||||
setLessonPage(page);
|
||||
toast.success("Lesson page saved.");
|
||||
toast("Lesson page saved.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -811,7 +1006,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setAssessment(result);
|
||||
toast.success("Assessment created.");
|
||||
toast("Assessment created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -825,7 +1025,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setAssessment(result);
|
||||
toast.success("Assessment updated.");
|
||||
toast("Assessment updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -838,7 +1043,12 @@ export function CoursesProvider({ children }) {
|
||||
const { data } = await api.delete(`${BASE}/${courseId}/assessment/${assessmentId}`, { data: { deletedBy } });
|
||||
setAssessment(null);
|
||||
setQuestions([]);
|
||||
toast.success("Assessment archived.");
|
||||
toast("Assessment archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -864,7 +1074,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setAssessment(result);
|
||||
toast.success("Assessment restored.");
|
||||
toast("Assessment restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -893,7 +1108,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setQuestions((prev) => [...prev, result]);
|
||||
toast.success("Question added.");
|
||||
toast("Question added.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -907,7 +1127,12 @@ export function CoursesProvider({ children }) {
|
||||
const result = data?.data?.data ?? null;
|
||||
if (result) {
|
||||
setQuestions((prev) => prev.map((q) => (q.question_id === questionId ? result : q)));
|
||||
toast.success("Question updated.");
|
||||
toast("Question updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return data;
|
||||
}),
|
||||
@@ -920,7 +1145,12 @@ 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.success("Assessment saved.");
|
||||
toast("Assessment saved.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -931,7 +1161,12 @@ 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.success("Question archived.");
|
||||
toast("Question archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -942,7 +1177,12 @@ 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.success("Questions archived.");
|
||||
toast("Questions archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -963,7 +1203,12 @@ export function CoursesProvider({ children }) {
|
||||
(courseId, assessmentId, questionId, restoredBy) =>
|
||||
request(async () => {
|
||||
const { data } = await api.patch(`${BASE}/${courseId}/assessment/${assessmentId}/questions/${questionId}/restore`, { restoredBy });
|
||||
toast.success("Question restored.");
|
||||
toast("Question restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -973,7 +1218,12 @@ 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.success("Questions restored.");
|
||||
toast("Questions restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[request],
|
||||
@@ -1030,7 +1280,12 @@ export function CoursesProvider({ children }) {
|
||||
const saveCourseProduct = useCallback(
|
||||
(courseId, payload) => request(async () => {
|
||||
const { data } = await api.put(`/admin/products/courses/${courseId}/product`, payload);
|
||||
toast.success("Product listing saved.");
|
||||
toast("Product listing saved.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data ?? null;
|
||||
}), [request],
|
||||
);
|
||||
@@ -1038,7 +1293,12 @@ export function CoursesProvider({ children }) {
|
||||
const removeCourseProduct = useCallback(
|
||||
(courseId) => request(async () => {
|
||||
await api.delete(`/admin/products/courses/${courseId}/product`);
|
||||
toast.success("Product listing removed.");
|
||||
toast("Product listing removed.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}), [request],
|
||||
);
|
||||
@@ -1053,7 +1313,12 @@ 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.success("Categories updated.");
|
||||
toast("Categories updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data ?? [];
|
||||
}), [request],
|
||||
);
|
||||
@@ -1068,7 +1333,12 @@ export function CoursesProvider({ children }) {
|
||||
const syncInstructors = useCallback(
|
||||
(courseId, instructors) => request(async () => {
|
||||
await api.put(`${BASE}/${courseId}/instructors`, { instructors });
|
||||
toast.success("Instructors updated.");
|
||||
toast("Instructors updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}), [request],
|
||||
);
|
||||
|
||||
@@ -1082,7 +1352,12 @@ export function CoursesProvider({ children }) {
|
||||
const syncCourseAchievements = useCallback(
|
||||
(courseId, achievement_keys) => request(async () => {
|
||||
await api.put(`${BASE}/${courseId}/achievements`, { achievement_keys });
|
||||
toast.success("Rewards updated.");
|
||||
toast("Rewards updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}), [request],
|
||||
);
|
||||
|
||||
|
||||
@@ -21,7 +21,12 @@ export function AdminDashboardProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? "Something went wrong.";
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
@@ -34,7 +34,12 @@ export function NotificationBroadcastsProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? "Something went wrong.";
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -100,7 +105,12 @@ export function NotificationBroadcastsProvider({ children }) {
|
||||
const broadcast = res.data?.data?.data ?? null;
|
||||
if (broadcast) {
|
||||
setBroadcasts((prev) => [broadcast, ...prev]);
|
||||
toast.success("Notification broadcast created.");
|
||||
toast("Notification broadcast created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -116,7 +126,12 @@ export function NotificationBroadcastsProvider({ children }) {
|
||||
if (broadcast) {
|
||||
setBroadcasts((prev) => prev.map((b) => (b.broadcast_id === broadcastId ? broadcast : b)));
|
||||
setSelectedBroadcast(broadcast);
|
||||
toast.success("Notification broadcast updated.");
|
||||
toast("Notification broadcast updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -132,7 +147,12 @@ export function NotificationBroadcastsProvider({ children }) {
|
||||
if (broadcast) {
|
||||
setBroadcasts((prev) => prev.map((b) => (b.broadcast_id === broadcastId ? broadcast : b)));
|
||||
setSelectedBroadcast(broadcast);
|
||||
toast.success("Notification broadcast sent.");
|
||||
toast("Notification broadcast sent.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -148,7 +168,12 @@ export function NotificationBroadcastsProvider({ children }) {
|
||||
});
|
||||
setBroadcasts((prev) => prev.filter((b) => b.broadcast_id !== broadcastId));
|
||||
setSelectedBroadcast((prev) => (prev?.broadcast_id === broadcastId ? null : prev));
|
||||
toast.success("Notification broadcast archived.");
|
||||
toast("Notification broadcast archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -162,7 +187,12 @@ export function NotificationBroadcastsProvider({ children }) {
|
||||
data: { ids, deletedBy },
|
||||
});
|
||||
setBroadcasts((prev) => prev.filter((b) => !ids.includes(b.broadcast_id)));
|
||||
toast.success(`${ids.length} notification broadcast(s) archived.`);
|
||||
toast(`${ids.length} notification broadcast(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -176,7 +206,12 @@ export function NotificationBroadcastsProvider({ children }) {
|
||||
const broadcast = res.data?.data?.data ?? null;
|
||||
if (broadcast) {
|
||||
setBroadcasts((prev) => prev.filter((b) => b.broadcast_id !== broadcastId));
|
||||
toast.success("Notification broadcast restored.");
|
||||
toast("Notification broadcast restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -189,7 +224,12 @@ 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.success(`${ids.length} notification broadcast(s) restored.`);
|
||||
toast(`${ids.length} notification broadcast(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -201,7 +241,12 @@ 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.success("Notification broadcast permanently deleted.");
|
||||
toast("Notification broadcast permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -213,7 +258,12 @@ 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.success(`${ids.length} notification broadcast(s) permanently deleted.`);
|
||||
toast(`${ids.length} notification broadcast(s) permanently deleted.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
|
||||
@@ -19,7 +19,12 @@ export function AdminNotificationTemplateProvider({ children }) {
|
||||
setLoading(true);
|
||||
try { return await fn(); }
|
||||
catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Something went wrong.");
|
||||
toast(err?.response?.data?.message ?? "Something went wrong.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -45,7 +50,12 @@ 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.success("Notification template updated.");
|
||||
toast("Notification template updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
}), [request, template]);
|
||||
|
||||
|
||||
@@ -57,7 +57,12 @@ export function AdminTaskProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? 'Something went wrong.';
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -70,7 +75,12 @@ export function AdminTaskProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? 'Something went wrong.';
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setCompletionLoading(false);
|
||||
@@ -133,7 +143,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(payload) =>
|
||||
request(async () => {
|
||||
const res = await api.post(BASE, payload);
|
||||
toast.success('Task list created.');
|
||||
toast('Task list created.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data?.data ?? null;
|
||||
}),
|
||||
[request]
|
||||
@@ -143,7 +158,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, payload) =>
|
||||
request(async () => {
|
||||
const res = await api.patch(`${BASE}/${taskListId}`, payload);
|
||||
toast.success('Task list updated.');
|
||||
toast('Task list updated.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data?.data ?? null;
|
||||
}),
|
||||
[request]
|
||||
@@ -153,7 +173,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId) =>
|
||||
request(async () => {
|
||||
await api.delete(`${BASE}/${taskListId}`);
|
||||
toast.success('Task list archived.');
|
||||
toast('Task list archived.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -163,7 +188,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId) =>
|
||||
request(async () => {
|
||||
await api.patch(`${BASE}/${taskListId}/restore`);
|
||||
toast.success('Task list restored.');
|
||||
toast('Task list restored.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -173,7 +203,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(ids) =>
|
||||
request(async () => {
|
||||
await api.post(`${BASE}/bulk-archive`, { ids });
|
||||
toast.success(`${ids.length} task list(s) archived.`);
|
||||
toast(`${ids.length} task list(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -183,7 +218,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(ids) =>
|
||||
request(async () => {
|
||||
await api.post(`${BASE}/bulk-restore`, { ids });
|
||||
toast.success(`${ids.length} task list(s) restored.`);
|
||||
toast(`${ids.length} task list(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -193,7 +233,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId) =>
|
||||
request(async () => {
|
||||
await api.delete(`${BASE}/${taskListId}/permanent`);
|
||||
toast.success('Task list permanently deleted.');
|
||||
toast('Task list permanently deleted.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -203,7 +248,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(ids) =>
|
||||
request(async () => {
|
||||
await api.post(`${BASE}/bulk-delete`, { ids });
|
||||
toast.success(`${ids.length} task list(s) permanently deleted.`);
|
||||
toast(`${ids.length} task list(s) permanently deleted.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -254,9 +304,19 @@ export function AdminTaskProvider({ children }) {
|
||||
});
|
||||
const result = res.data?.data ?? {};
|
||||
if (result.assigned_ids?.length) {
|
||||
toast.success(`${result.assigned_ids.length} group(s) assigned.`);
|
||||
toast(`${result.assigned_ids.length} group(s) assigned.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toast.info('All selected groups were already assigned.');
|
||||
toast('All selected groups were already assigned.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}),
|
||||
@@ -270,7 +330,12 @@ export function AdminTaskProvider({ children }) {
|
||||
group_ids: groupIds,
|
||||
});
|
||||
const result = res.data?.data ?? {};
|
||||
toast.success(`${result.unassigned_ids?.length ?? 0} group(s) unassigned.`);
|
||||
toast(`${result.unassigned_ids?.length ?? 0} group(s) unassigned.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}),
|
||||
[request]
|
||||
@@ -331,7 +396,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, payload) =>
|
||||
request(async () => {
|
||||
const res = await api.post(`${BASE}/${taskListId}/tasks`, payload);
|
||||
toast.success('Task created.');
|
||||
toast('Task created.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data?.data?.data ?? null;
|
||||
}),
|
||||
[request]
|
||||
@@ -341,7 +411,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, taskId, payload) =>
|
||||
request(async () => {
|
||||
const res = await api.patch(`${BASE}/${taskListId}/tasks/${taskId}`, payload);
|
||||
toast.success('Task updated.');
|
||||
toast('Task updated.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data?.data?.data ?? null;
|
||||
}),
|
||||
[request]
|
||||
@@ -351,7 +426,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, taskId) =>
|
||||
request(async () => {
|
||||
await api.delete(`${BASE}/${taskListId}/tasks/${taskId}`);
|
||||
toast.success('Task archived.');
|
||||
toast('Task archived.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -361,7 +441,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, taskId) =>
|
||||
request(async () => {
|
||||
await api.patch(`${BASE}/${taskListId}/tasks/${taskId}/restore`);
|
||||
toast.success('Task restored.');
|
||||
toast('Task restored.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -371,7 +456,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, ids) =>
|
||||
request(async () => {
|
||||
await api.post(`${BASE}/${taskListId}/tasks/bulk-archive`, { ids });
|
||||
toast.success(`${ids.length} task(s) archived.`);
|
||||
toast(`${ids.length} task(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -381,7 +471,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, ids) =>
|
||||
request(async () => {
|
||||
await api.post(`${BASE}/${taskListId}/tasks/bulk-restore`, { ids });
|
||||
toast.success(`${ids.length} task(s) restored.`);
|
||||
toast(`${ids.length} task(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -391,7 +486,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, taskId) =>
|
||||
request(async () => {
|
||||
await api.delete(`${BASE}/${taskListId}/tasks/${taskId}/permanent`);
|
||||
toast.success('Task permanently deleted.');
|
||||
toast('Task permanently deleted.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -401,7 +501,12 @@ export function AdminTaskProvider({ children }) {
|
||||
(taskListId, ids) =>
|
||||
request(async () => {
|
||||
await api.post(`${BASE}/${taskListId}/tasks/bulk-delete`, { ids });
|
||||
toast.success(`${ids.length} task(s) permanently deleted.`);
|
||||
toast(`${ids.length} task(s) permanently deleted.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[request]
|
||||
@@ -520,7 +625,12 @@ export function AdminTaskProvider({ children }) {
|
||||
await api.delete(
|
||||
`${BASE}/${taskListId}/tasks/${taskId}/completions/${completionId}`
|
||||
);
|
||||
toast.success('Completion archived.');
|
||||
toast('Completion archived.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[completionRequest]
|
||||
@@ -533,7 +643,12 @@ export function AdminTaskProvider({ children }) {
|
||||
await api.patch(
|
||||
`${BASE}/${taskListId}/tasks/${taskId}/completions/${completionId}/restore`
|
||||
);
|
||||
toast.success('Completion restored.');
|
||||
toast('Completion restored.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[completionRequest]
|
||||
@@ -547,7 +662,12 @@ export function AdminTaskProvider({ children }) {
|
||||
`${BASE}/${taskListId}/tasks/${taskId}/completions/bulk-archive`,
|
||||
{ ids }
|
||||
);
|
||||
toast.success(`${ids.length} completion(s) archived.`);
|
||||
toast(`${ids.length} completion(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[completionRequest]
|
||||
@@ -561,7 +681,12 @@ export function AdminTaskProvider({ children }) {
|
||||
`${BASE}/${taskListId}/tasks/${taskId}/completions/bulk-restore`,
|
||||
{ ids }
|
||||
);
|
||||
toast.success(`${ids.length} completion(s) restored.`);
|
||||
toast(`${ids.length} completion(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
[completionRequest]
|
||||
|
||||
@@ -19,7 +19,12 @@ export function AdminTierCategoriesProvider({ children }) {
|
||||
setLoading(true);
|
||||
try { return await fn(); }
|
||||
catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Something went wrong.");
|
||||
toast(err?.response?.data?.message ?? "Something went wrong.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -41,7 +46,12 @@ export function AdminTierCategoriesProvider({ children }) {
|
||||
const createCategory = useCallback((payload) =>
|
||||
request(async () => {
|
||||
const { data } = await api.post("/admin/tiers/categories", payload);
|
||||
toast.success("Tier category created.");
|
||||
toast("Tier category created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
}), [request]);
|
||||
|
||||
@@ -52,7 +62,12 @@ 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.success("Tier category updated.");
|
||||
toast("Tier category updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
}), [request, category]);
|
||||
|
||||
@@ -60,7 +75,12 @@ 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.success("Tier category deleted.");
|
||||
toast("Tier category deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}), [request]);
|
||||
|
||||
|
||||
@@ -20,7 +20,12 @@ export function AdminTierPoliciesProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? "Something went wrong.";
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -45,7 +50,12 @@ export function AdminTierPoliciesProvider({ children }) {
|
||||
? prev.map((b) => (b.key === key ? data.data : b))
|
||||
: [...prev, data.data];
|
||||
});
|
||||
toast.success("Badge saved.");
|
||||
toast("Badge saved.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
}), [request]);
|
||||
|
||||
|
||||
@@ -33,7 +33,12 @@ export function AdminTiersProvider({ children }) {
|
||||
totalPages: data.data?.pagination?.totalPages ?? 1,
|
||||
totalRecords: data.data?.pagination?.totalRecords ?? 0,
|
||||
});
|
||||
} catch { toast.error("Could not load plans."); }
|
||||
} catch { toast("Could not load plans.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
}); }
|
||||
finally { setLoading(false); }
|
||||
}, []);
|
||||
|
||||
@@ -42,7 +47,12 @@ export function AdminTiersProvider({ children }) {
|
||||
try {
|
||||
const { data } = await api.get(`/admin/tiers/${id}`);
|
||||
setPlan(data.data ?? null);
|
||||
} catch { toast.error("Could not load plan."); }
|
||||
} catch { toast("Could not load plan.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
}); }
|
||||
finally { setLoading(false); }
|
||||
}, []);
|
||||
|
||||
@@ -50,10 +60,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data } = await api.post("/admin/tiers", payload);
|
||||
toast.success("Plan created.");
|
||||
toast("Plan created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not create plan.");
|
||||
toast(err?.response?.data?.message ?? "Could not create plan.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -62,10 +82,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
const { data } = await api.put(`/admin/tiers/${id}`, payload);
|
||||
toast.success("Plan updated.");
|
||||
toast("Plan updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not update plan.");
|
||||
toast(err?.response?.data?.message ?? "Could not update plan.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -74,10 +104,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.delete(`/admin/tiers/${id}`);
|
||||
toast.success("Plan archived.");
|
||||
toast("Plan archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not archive plan.");
|
||||
toast(err?.response?.data?.message ?? "Could not archive plan.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -86,10 +126,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.post(`/admin/tiers/${id}/restore`);
|
||||
toast.success("Plan restored.");
|
||||
toast("Plan restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not restore plan.");
|
||||
toast(err?.response?.data?.message ?? "Could not restore plan.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -98,10 +148,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.post("/admin/tiers/bulk/archive", { ids });
|
||||
toast.success("Plans archived.");
|
||||
toast("Plans archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not archive plans.");
|
||||
toast(err?.response?.data?.message ?? "Could not archive plans.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -110,10 +170,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.post("/admin/tiers/bulk/restore", { ids });
|
||||
toast.success("Plans restored.");
|
||||
toast("Plans restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not restore plans.");
|
||||
toast(err?.response?.data?.message ?? "Could not restore plans.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -122,10 +192,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.delete(`/admin/tiers/${id}/permanent`);
|
||||
toast.success("Plan permanently deleted.");
|
||||
toast("Plan permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not permanently delete plan.");
|
||||
toast(err?.response?.data?.message ?? "Could not permanently delete plan.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -134,10 +214,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.post("/admin/tiers/bulk/permanent-delete", { ids });
|
||||
toast.success("Plans permanently deleted.");
|
||||
toast("Plans permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not permanently delete plans.");
|
||||
toast(err?.response?.data?.message ?? "Could not permanently delete plans.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -162,7 +252,12 @@ export function AdminTiersProvider({ children }) {
|
||||
try {
|
||||
const { data } = await api.get(`/admin/tiers/users/${userId}/tiers`);
|
||||
setUserTiers(data.data ?? []);
|
||||
} catch { toast.error("Could not load user tiers."); }
|
||||
} catch { toast("Could not load user tiers.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
}); }
|
||||
finally { setLoading(false); }
|
||||
}, []);
|
||||
|
||||
@@ -170,10 +265,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.post("/admin/tiers/users/tiers/grant", payload);
|
||||
toast.success("Tier granted.");
|
||||
toast("Tier granted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not grant tier.");
|
||||
toast(err?.response?.data?.message ?? "Could not grant tier.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -182,10 +287,20 @@ export function AdminTiersProvider({ children }) {
|
||||
setLoading(true);
|
||||
try {
|
||||
await api.patch(`/admin/tiers/users/tiers/${tid}/revoke`);
|
||||
toast.success("Tier revoked.");
|
||||
toast("Tier revoked.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not revoke tier.");
|
||||
toast(err?.response?.data?.message ?? "Could not revoke tier.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
@@ -206,7 +321,12 @@ export function AdminTiersProvider({ children }) {
|
||||
totalPages: data.data?.pagination?.totalPages ?? 1,
|
||||
totalRecords: data.data?.pagination?.totalRecords ?? 0,
|
||||
});
|
||||
} catch { toast.error("Could not load payments."); }
|
||||
} catch { toast("Could not load payments.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
}); }
|
||||
finally { setLoading(false); }
|
||||
}, []);
|
||||
|
||||
@@ -215,7 +335,12 @@ export function AdminTiersProvider({ children }) {
|
||||
try {
|
||||
const { data } = await api.get(`/admin/tiers/payments/${id}`);
|
||||
setPayment(data.data ?? null);
|
||||
} catch { toast.error("Could not load payment."); }
|
||||
} catch { toast("Could not load payment.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
}); }
|
||||
finally { setLoading(false); }
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -45,7 +45,12 @@ export const UserProvider = ({ children }) => {
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message || err.message || "Something went wrong.";
|
||||
setError(message);
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -108,7 +113,12 @@ export const UserProvider = ({ children }) => {
|
||||
(payload) =>
|
||||
request(async () => {
|
||||
const res = await api.post(`${BASE}/users/staff`, payload);
|
||||
toast.success("Staff user added successfully.");
|
||||
toast("Staff user added successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -122,7 +132,12 @@ export const UserProvider = ({ children }) => {
|
||||
setUsers((prev) =>
|
||||
prev.map((u) => (u.user_id === userId ? { ...u, ...res.data?.data } : u))
|
||||
);
|
||||
toast.success("User updated successfully.");
|
||||
toast("User updated successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -136,7 +151,12 @@ export const UserProvider = ({ children }) => {
|
||||
setUsers((prev) =>
|
||||
prev.map((u) => (u.user_id === userId ? { ...u, is_active: false } : u))
|
||||
);
|
||||
toast.success("User deactivated.");
|
||||
toast("User deactivated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -154,7 +174,12 @@ export const UserProvider = ({ children }) => {
|
||||
deactivated_ids.includes(u.user_id) ? { ...u, is_active: false } : u
|
||||
)
|
||||
);
|
||||
toast.success(`${deactivated_ids.length} user(s) deactivated.`);
|
||||
toast(`${deactivated_ids.length} user(s) deactivated.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -169,7 +194,12 @@ export const UserProvider = ({ children }) => {
|
||||
setUsers((prev) =>
|
||||
prev.map((u) => (u.user_id === userId ? { ...u, is_active: true } : u))
|
||||
);
|
||||
toast.success("User restored.");
|
||||
toast("User restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -187,7 +217,12 @@ export const UserProvider = ({ children }) => {
|
||||
restored_ids.includes(u.user_id) ? { ...u, is_active: true } : u
|
||||
)
|
||||
);
|
||||
toast.success(`${restored_ids.length} user(s) restored.`);
|
||||
toast(`${restored_ids.length} user(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -200,7 +235,12 @@ 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.success("User permanently deleted.");
|
||||
toast("User permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -214,7 +254,12 @@ 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.success(`${deleted_ids.length} user(s) permanently deleted.`);
|
||||
toast(`${deleted_ids.length} user(s) permanently deleted.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -240,7 +285,12 @@ export const UserProvider = ({ children }) => {
|
||||
setSessions((prev) =>
|
||||
prev.map((s) => (s.session_id === sessionId ? { ...s, is_active: false } : s))
|
||||
);
|
||||
toast.success("Session terminated.");
|
||||
toast("Session terminated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -284,7 +334,12 @@ export const UserProvider = ({ children }) => {
|
||||
});
|
||||
return d;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load activity.");
|
||||
toast(err?.response?.data?.message ?? "Could not load activity.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setActivityLoading(false);
|
||||
@@ -311,7 +366,12 @@ export const UserProvider = ({ children }) => {
|
||||
setAchievements(res.data?.data ?? []);
|
||||
return res.data?.data;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load achievements.");
|
||||
toast(err?.response?.data?.message ?? "Could not load achievements.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return [];
|
||||
} finally {
|
||||
setAchievementsLoading(false);
|
||||
@@ -327,7 +387,12 @@ 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.success("User banned successfully.");
|
||||
toast("User banned successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request, user]
|
||||
@@ -342,7 +407,12 @@ 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.success("User unbanned successfully.");
|
||||
toast("User unbanned successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request, user]
|
||||
@@ -358,7 +428,12 @@ export const UserProvider = ({ children }) => {
|
||||
setUsers((prev) =>
|
||||
prev.map((u) => (banned_ids.includes(u.user_id) ? { ...u, is_banned: true } : u))
|
||||
);
|
||||
toast.success(`${banned_ids.length} user(s) banned.`);
|
||||
toast(`${banned_ids.length} user(s) banned.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -375,7 +450,12 @@ export const UserProvider = ({ children }) => {
|
||||
setUsers((prev) =>
|
||||
prev.map((u) => (unbanned_ids.includes(u.user_id) ? { ...u, is_banned: false } : u))
|
||||
);
|
||||
toast.success(`${unbanned_ids.length} user(s) unbanned.`);
|
||||
toast(`${unbanned_ids.length} user(s) unbanned.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -390,7 +470,12 @@ export const UserProvider = ({ children }) => {
|
||||
setBans(res.data?.data ?? []);
|
||||
return res.data?.data;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load ban history.");
|
||||
toast(err?.response?.data?.message ?? "Could not load ban history.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return [];
|
||||
} finally {
|
||||
setBansLoading(false);
|
||||
|
||||
@@ -27,7 +27,12 @@ export function UserGroupProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? "Something went wrong.";
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -121,7 +126,12 @@ export function UserGroupProvider({ children }) {
|
||||
request(async () => {
|
||||
const res = await api.post(`${BASE}/groups`, { name, description, group_code });
|
||||
setGroups((prev) => [res.data?.data, ...prev]);
|
||||
toast.success("Group created successfully.");
|
||||
toast("Group created successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -136,7 +146,12 @@ 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.success("Group updated successfully.");
|
||||
toast("Group updated successfully.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -150,7 +165,12 @@ export function UserGroupProvider({ children }) {
|
||||
setGroups((prev) =>
|
||||
prev.map((g) => (g.group_id === gid ? { ...g, is_active: false } : g))
|
||||
);
|
||||
toast.success("Group deactivated.");
|
||||
toast("Group deactivated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -168,7 +188,12 @@ export function UserGroupProvider({ children }) {
|
||||
deactivated_ids.includes(g.group_id) ? { ...g, is_active: false } : g
|
||||
)
|
||||
);
|
||||
toast.success(`${deactivated_ids.length} group(s) deactivated.`);
|
||||
toast(`${deactivated_ids.length} group(s) deactivated.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -183,7 +208,12 @@ export function UserGroupProvider({ children }) {
|
||||
setGroups((prev) =>
|
||||
prev.map((g) => (g.group_id === gid ? { ...g, is_active: true } : g))
|
||||
);
|
||||
toast.success("Group restored.");
|
||||
toast("Group restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -201,7 +231,12 @@ export function UserGroupProvider({ children }) {
|
||||
restored_ids.includes(g.group_id) ? { ...g, is_active: true } : g
|
||||
)
|
||||
);
|
||||
toast.success(`${restored_ids.length} group(s) restored.`);
|
||||
toast(`${restored_ids.length} group(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -214,7 +249,12 @@ 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.success("Group permanently deleted.");
|
||||
toast("Group permanently deleted.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -228,7 +268,12 @@ 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.success(`${deleted_ids.length} group(s) permanently deleted.`);
|
||||
toast(`${deleted_ids.length} group(s) permanently deleted.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
return res.data;
|
||||
}),
|
||||
@@ -241,7 +286,12 @@ 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.success("Users added to group.");
|
||||
toast("Users added to group.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -254,7 +304,12 @@ 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.success("Users removed from group.");
|
||||
toast("Users removed from group.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
|
||||
@@ -22,22 +22,35 @@ export function AuthProvider({ children }) {
|
||||
_setAccessToken(token)
|
||||
}, [])
|
||||
|
||||
// Shared by verifyOTP, restoreSession, and login's trusted-device fast path
|
||||
// — anywhere the backend hands back a fully-authenticated session in one shot.
|
||||
const applySession = useCallback((data) => {
|
||||
setAccessToken(data.accessToken)
|
||||
setUser(data.user)
|
||||
setSessionId(data.session_id ?? null)
|
||||
}, [setAccessToken])
|
||||
|
||||
// ── Login ──────────────────────────────────────────────────────────────────
|
||||
// Credentials get you an OTP — unless this device already cleared one
|
||||
// recently and its trust window is still valid, in which case the backend
|
||||
// returns otpRequired:false along with a full session, same shape as
|
||||
// verifyOTP's response.
|
||||
const login = useCallback(async ({ email, password }) => {
|
||||
setAuthError(null)
|
||||
try {
|
||||
const { data } = await api.post('/auth/login', { email, password })
|
||||
setAccessToken(data.data.accessToken)
|
||||
setUser(data.data.user)
|
||||
setSessionId(data.data.session_id ?? null)
|
||||
return { success: true, user: data.data.user }
|
||||
if (data.data.otpRequired === false) {
|
||||
applySession(data.data)
|
||||
return { success: true, otpRequired: false, user: data.data.user }
|
||||
}
|
||||
return { success: true, otpRequired: true, email: data.data.email }
|
||||
} catch (err) {
|
||||
const message = err.response?.data?.message || 'Login failed. Please try again.'
|
||||
const errors = err.response?.data?.errors ?? null
|
||||
setAuthError(message)
|
||||
return { success: false, message, errors }
|
||||
}
|
||||
}, [])
|
||||
}, [applySession])
|
||||
|
||||
// ── Register ───────────────────────────────────────────────────────────────
|
||||
const register = useCallback(async (payload) => {
|
||||
@@ -57,16 +70,14 @@ export function AuthProvider({ children }) {
|
||||
setAuthError(null)
|
||||
try {
|
||||
const { data } = await api.post('/auth/verify-otp', { email, otp })
|
||||
setAccessToken(data.data.accessToken)
|
||||
setUser(data.data.user)
|
||||
setSessionId(data.data.session_id ?? null)
|
||||
applySession(data.data)
|
||||
return { success: true, user: data.data.user }
|
||||
} catch (err) {
|
||||
const message = err.response?.data?.message || 'OTP verification failed.'
|
||||
setAuthError(message)
|
||||
return { success: false, message }
|
||||
}
|
||||
}, [])
|
||||
}, [applySession])
|
||||
|
||||
// ── Resend OTP ─────────────────────────────────────────────────────────────
|
||||
const resendOTP = useCallback(async ({ email }) => {
|
||||
@@ -79,6 +90,28 @@ export function AuthProvider({ children }) {
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── Forgot password (request OTP) ─────────────────────────────────────────
|
||||
const forgotPassword = useCallback(async ({ email }) => {
|
||||
try {
|
||||
const { data } = await api.post('/auth/forgot-password', { email })
|
||||
return { success: true, email: data.data.email }
|
||||
} catch (err) {
|
||||
const message = err.response?.data?.message || 'Could not process request.'
|
||||
return { success: false, message }
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── Reset password (OTP + new password in one step) ───────────────────────
|
||||
const resetPassword = useCallback(async ({ email, otp, new_password }) => {
|
||||
try {
|
||||
await api.post('/auth/reset-password', { email, otp, new_password })
|
||||
return { success: true }
|
||||
} catch (err) {
|
||||
const message = err.response?.data?.message || 'Password reset failed.'
|
||||
return { success: false, message }
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ── Logout ─────────────────────────────────────────────────────────────────
|
||||
const logout = useCallback(async () => {
|
||||
try {
|
||||
@@ -94,23 +127,23 @@ export function AuthProvider({ children }) {
|
||||
|
||||
// ── Restore session ────────────────────────────────────────────────────────
|
||||
const restoreSession = useCallback(async () => {
|
||||
if (isRestoring.current) return
|
||||
if (isRestoring.current) return { success: false }
|
||||
isRestoring.current = true
|
||||
|
||||
try {
|
||||
if (accessTokenRef.current) return
|
||||
if (accessTokenRef.current) return { success: true }
|
||||
const { data } = await api.post('/auth/refresh')
|
||||
setAccessToken(data.data.accessToken)
|
||||
setUser(data.data.user)
|
||||
setSessionId(data.data.session_id ?? null)
|
||||
applySession(data.data)
|
||||
return { success: true, user: data.data.user }
|
||||
} catch (_) {
|
||||
setAccessToken(null)
|
||||
setUser(null)
|
||||
setSessionId(null)
|
||||
return { success: false }
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
}, [applySession])
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{
|
||||
@@ -124,6 +157,8 @@ export function AuthProvider({ children }) {
|
||||
register,
|
||||
verifyOTP,
|
||||
resendOTP,
|
||||
forgotPassword,
|
||||
resetPassword,
|
||||
logout,
|
||||
loading,
|
||||
sessionRestored,
|
||||
|
||||
@@ -35,6 +35,12 @@ export function ClientAdvertisementsProvider({ children }) {
|
||||
// dashboard.popup) can be fetched independently without clobbering each other.
|
||||
const [advertisements, setAdvertisements] = useState({});
|
||||
const [loading, setLoading] = useState({});
|
||||
|
||||
// Keyed by placement, holds the full list for carousel-style slots (e.g.
|
||||
// dashboard.hero) — separate from `advertisements` above, which only ever
|
||||
// holds the single highest-priority ad per placement.
|
||||
const [adLists, setAdLists] = useState({});
|
||||
const [listLoading, setListLoading] = useState({});
|
||||
const [clickCounts, setClickCounts] = useState(loadClickCounts);
|
||||
const [pendingClick, setPendingClick] = useState(null); // { ad, cta } awaiting confirmation
|
||||
const [dismissConfirmOpen, setDismissConfirmOpen] = useState(false);
|
||||
@@ -128,6 +134,33 @@ export function ClientAdvertisementsProvider({ children }) {
|
||||
[ensureProfile]
|
||||
);
|
||||
|
||||
// ─── GET /api/client/advertisements/active-list?placement=dashboard.hero ──
|
||||
// Resolves every live ad for one placement — use for carousel-style slots
|
||||
// that rotate through several ads instead of showing just the winner.
|
||||
const getActiveAdvertisementList = useCallback(
|
||||
async (placement, limit) => {
|
||||
setListLoading((prev) => ({ ...prev, [placement]: true }));
|
||||
try {
|
||||
const [currentProfile, { data }] = await Promise.all([
|
||||
ensureProfile(),
|
||||
api.get("/client/advertisements/active-list", { params: { placement, limit } }),
|
||||
]);
|
||||
const raw = data?.data?.data ?? [];
|
||||
const list = raw
|
||||
.map((ad) => resolveVisibility(currentProfile, ad))
|
||||
.filter(Boolean);
|
||||
setAdLists((prev) => ({ ...prev, [placement]: list }));
|
||||
return list;
|
||||
} catch {
|
||||
setAdLists((prev) => ({ ...prev, [placement]: [] }));
|
||||
return [];
|
||||
} finally {
|
||||
setListLoading((prev) => ({ ...prev, [placement]: false }));
|
||||
}
|
||||
},
|
||||
[ensureProfile]
|
||||
);
|
||||
|
||||
// ─── POST /api/client/advertisements/:advertisementId/click ───────────────
|
||||
// Fire-and-forget — never await this on a navigation-blocking path.
|
||||
const trackClick = useCallback(
|
||||
@@ -206,6 +239,9 @@ export function ClientAdvertisementsProvider({ children }) {
|
||||
loading,
|
||||
getActiveAdvertisement,
|
||||
getActiveAdvertisements,
|
||||
adLists,
|
||||
listLoading,
|
||||
getActiveAdvertisementList,
|
||||
trackClick,
|
||||
handleAdCtaClick,
|
||||
dismissPopupForever,
|
||||
|
||||
@@ -58,7 +58,12 @@ export function CourseReadingProgressProvider({ children }) {
|
||||
);
|
||||
return rows;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? 'Could not load course progress.');
|
||||
toast(err?.response?.data?.message ?? 'Could not load course progress.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -101,7 +106,12 @@ export function CourseReadingProgressProvider({ children }) {
|
||||
delete next[lessonUuid];
|
||||
return next;
|
||||
});
|
||||
toast.error(err?.response?.data?.message ?? 'Could not update progress.');
|
||||
toast(err?.response?.data?.message ?? 'Could not update progress.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -42,7 +42,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
const { data } = await api.get("/client/courses");
|
||||
setCourses(data.data ?? []);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load courses.");
|
||||
toast(err?.response?.data?.message ?? "Could not load courses.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setCoursesLoading(false);
|
||||
}
|
||||
@@ -58,7 +63,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
if (err?.response?.status === 403) {
|
||||
setCourseBlocked(true); // let the UI show an upgrade prompt
|
||||
} else {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load course.");
|
||||
toast(err?.response?.data?.message ?? "Could not load course.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
setCourseLoading(false);
|
||||
@@ -71,7 +81,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
const { data } = await api.get(`/client/courses/${courseId}/units/${unitId}`);
|
||||
setUnit(data.data ?? null);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load unit.");
|
||||
toast(err?.response?.data?.message ?? "Could not load unit.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setUnitLoading(false);
|
||||
}
|
||||
@@ -85,7 +100,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
);
|
||||
setLesson(data.data ?? null);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load lesson.");
|
||||
toast(err?.response?.data?.message ?? "Could not load lesson.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setLessonLoading(false);
|
||||
}
|
||||
@@ -99,7 +119,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
);
|
||||
setQuiz(data.data ?? null);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load quiz.");
|
||||
toast(err?.response?.data?.message ?? "Could not load quiz.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setQuizLoading(false);
|
||||
}
|
||||
@@ -111,7 +136,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
const { data } = await api.get(`/client/courses/${courseId}/assessment`);
|
||||
setAssessment(data.data ?? null);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load assessment.");
|
||||
toast(err?.response?.data?.message ?? "Could not load assessment.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setAssessmentLoading(false);
|
||||
}
|
||||
@@ -125,7 +155,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
);
|
||||
return data.data ?? null;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not submit quiz.");
|
||||
toast(err?.response?.data?.message ?? "Could not submit quiz.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
@@ -135,7 +170,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
const { data } = await api.post(`/client/courses/${courseId}/assessment/${assessmentId}/start`);
|
||||
return data.data ?? null;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not start assessment.");
|
||||
toast(err?.response?.data?.message ?? "Could not start assessment.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
@@ -167,7 +207,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
);
|
||||
return data.data ?? null;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not submit assessment.");
|
||||
toast(err?.response?.data?.message ?? "Could not submit assessment.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
@@ -184,7 +229,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
const { data } = await api.get("/client/course-purchases");
|
||||
setPurchases(data.data ?? []);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load purchases.");
|
||||
toast(err?.response?.data?.message ?? "Could not load purchases.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally { setPurchasesLoading(false); }
|
||||
}, []);
|
||||
|
||||
@@ -194,7 +244,12 @@ export function ClientCoursesProvider({ children }) {
|
||||
const { data } = await api.post("/client/course-purchases/order", { product_id: productId });
|
||||
return data.data ?? null;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not create order.");
|
||||
toast(err?.response?.data?.message ?? "Could not create order.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setPurchaseLoading(false); }
|
||||
}, []);
|
||||
@@ -203,10 +258,20 @@ export function ClientCoursesProvider({ children }) {
|
||||
setPurchaseLoading(true);
|
||||
try {
|
||||
const { data } = await api.post("/client/course-purchases/capture", { order_id: orderId });
|
||||
toast.success("Purchase confirmed! You now have access to this course.");
|
||||
toast("Purchase confirmed! You now have access to this course.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return data.data ?? null;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not capture payment.");
|
||||
toast(err?.response?.data?.message ?? "Could not capture payment.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally { setPurchaseLoading(false); }
|
||||
}, []);
|
||||
|
||||
@@ -30,7 +30,12 @@ export function GroupProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? 'Something went wrong.';
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
@@ -45,7 +45,12 @@ export function TaskProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? 'Something went wrong.';
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -58,7 +63,12 @@ export function TaskProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? 'Something went wrong.';
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setCompletionLoading(false);
|
||||
@@ -155,7 +165,12 @@ export function TaskProvider({ children }) {
|
||||
payload
|
||||
);
|
||||
const data = res.data?.data ?? null;
|
||||
toast.success('Task submitted successfully.');
|
||||
toast('Task submitted successfully.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
// Immediately update latest completion so UI reflects the new state
|
||||
setLatestCompletion(data);
|
||||
// Prepend to history if it's already loaded
|
||||
|
||||
@@ -45,7 +45,12 @@ export function TaskProgressProvider({ children }) {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message ?? 'Something went wrong.';
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
@@ -44,10 +44,20 @@ 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.warning("Your subscription has expired. You've been moved to the Free plan.");
|
||||
toast("Your subscription has expired. You've been moved to the Free plan.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
if (!silent) toast.error(err?.response?.data?.message ?? "Could not load tier.");
|
||||
if (!silent) toast(err?.response?.data?.message ?? "Could not load tier.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
if (!silent) setTierLoading(false);
|
||||
}
|
||||
@@ -78,7 +88,12 @@ export function ClientTiersProvider({ children }) {
|
||||
const { data } = await api.get("/client/tiers/me/history");
|
||||
setTierHistory(data.data ?? []);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load tier history.");
|
||||
toast(err?.response?.data?.message ?? "Could not load tier history.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setTierHistoryLoading(false);
|
||||
}
|
||||
@@ -90,7 +105,12 @@ export function ClientTiersProvider({ children }) {
|
||||
const { data } = await api.get("/client/tiers/plans");
|
||||
setPlans(data.data ?? []);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load plans.");
|
||||
toast(err?.response?.data?.message ?? "Could not load plans.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setPlansLoading(false);
|
||||
}
|
||||
@@ -118,7 +138,12 @@ export function ClientTiersProvider({ children }) {
|
||||
const { data } = await api.post("/client/tiers/checkout/order", payload);
|
||||
return data.data ?? null;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not create order.");
|
||||
toast(err?.response?.data?.message ?? "Could not create order.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setCheckoutLoading(false);
|
||||
@@ -130,14 +155,24 @@ export function ClientTiersProvider({ children }) {
|
||||
setCheckoutLoading(true);
|
||||
try {
|
||||
const { data } = await api.post("/client/tiers/checkout/capture", { order_id });
|
||||
toast.success(data.message ?? "Payment successful. Tier activated.");
|
||||
toast(data.message ?? "Payment successful. Tier activated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
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.error(err?.response?.data?.message ?? "Payment capture failed.");
|
||||
toast(err?.response?.data?.message ?? "Payment capture failed.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setCheckoutLoading(false);
|
||||
@@ -162,7 +197,12 @@ export function ClientTiersProvider({ children }) {
|
||||
const { data } = await api.get("/client/tiers/me/payments");
|
||||
setPayments(data.data ?? []);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load payment history.");
|
||||
toast(err?.response?.data?.message ?? "Could not load payment history.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setPaymentsLoading(false);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,12 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
|
||||
setProfile(fresh);
|
||||
return fresh;
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load profile.");
|
||||
toast(err?.response?.data?.message ?? "Could not load profile.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setProfileLoading(false);
|
||||
@@ -47,10 +52,20 @@ 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.success(data.message ?? "Profile updated.");
|
||||
toast(data.message ?? "Profile updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: true, data: data.data };
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not update profile.");
|
||||
toast(err?.response?.data?.message ?? "Could not update profile.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: false };
|
||||
} finally {
|
||||
setProfileLoading(false);
|
||||
@@ -63,7 +78,12 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
|
||||
const { data } = await api.get(`${apiBase}/sessions`);
|
||||
setSessions(data.data ?? []);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load sessions.");
|
||||
toast(err?.response?.data?.message ?? "Could not load sessions.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setSessionsLoading(false);
|
||||
}
|
||||
@@ -74,10 +94,20 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
|
||||
try {
|
||||
await api.delete(`${apiBase}/sessions/${sessionId}`);
|
||||
setSessions((prev) => prev.filter((s) => s.session_id !== sessionId));
|
||||
toast.success("Session revoked.");
|
||||
toast("Session revoked.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not revoke session.");
|
||||
toast(err?.response?.data?.message ?? "Could not revoke session.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: false };
|
||||
} finally {
|
||||
setRevokingId(null);
|
||||
@@ -92,10 +122,20 @@ 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.success('Avatar updated.');
|
||||
toast('Avatar updated.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? 'Could not update avatar.');
|
||||
toast(err?.response?.data?.message ?? 'Could not update avatar.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: false };
|
||||
} finally {
|
||||
setAvatarLoading(false);
|
||||
@@ -114,10 +154,20 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
|
||||
...prev,
|
||||
personal_info: { ...(prev?.personal_info ?? {}), avatar: null },
|
||||
}));
|
||||
toast.success('Avatar removed.');
|
||||
toast('Avatar removed.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? 'Could not remove avatar.');
|
||||
toast(err?.response?.data?.message ?? 'Could not remove avatar.', {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return { success: false };
|
||||
} finally {
|
||||
setAvatarLoading(false);
|
||||
@@ -130,7 +180,12 @@ export function ProfileProvider({ children, apiBase = '/client' }) {
|
||||
const { data } = await api.get(`${apiBase}/achievements`);
|
||||
setAchievements(data.data ?? []);
|
||||
} catch (err) {
|
||||
toast.error(err?.response?.data?.message ?? "Could not load achievements.");
|
||||
toast(err?.response?.data?.message ?? "Could not load achievements.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setAchievementsLoading(false);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,12 @@ export const StaffGroupProvider = ({ children }) => {
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message || err.message || "Something went wrong.";
|
||||
setError(message);
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -56,7 +61,12 @@ export const StaffGroupProvider = ({ children }) => {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message || err.message || "Something went wrong.";
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setMembersLoading(false);
|
||||
|
||||
@@ -27,7 +27,12 @@ export const StaffScoreProvider = ({ children }) => {
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message || err.message || "Something went wrong.";
|
||||
setError(message);
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
@@ -53,7 +53,12 @@ export const StaffTaskProvider = ({ children }) => {
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message || err.message || "Something went wrong.";
|
||||
setError(message);
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -134,7 +139,12 @@ 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.success("Task list created.");
|
||||
toast("Task list created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -153,7 +163,12 @@ export const StaffTaskProvider = ({ children }) => {
|
||||
if (taskList?.task_list_id === taskListId)
|
||||
setTaskList((prev) => ({ ...prev, ...updated }));
|
||||
}
|
||||
toast.success("Task list updated.");
|
||||
toast("Task list updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request, taskList]
|
||||
@@ -166,7 +181,12 @@ 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.success("Task list archived.");
|
||||
toast("Task list archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request, taskList]
|
||||
@@ -178,7 +198,12 @@ 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.success("Task list restored.");
|
||||
toast("Task list restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -193,7 +218,12 @@ export const StaffTaskProvider = ({ children }) => {
|
||||
setTaskLists((prev) =>
|
||||
prev.filter((tl) => !archived_ids.includes(tl.task_list_id))
|
||||
);
|
||||
toast.success(`${archived_ids.length} task list(s) archived.`);
|
||||
toast(`${archived_ids.length} task list(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -208,7 +238,12 @@ export const StaffTaskProvider = ({ children }) => {
|
||||
setTaskLists((prev) =>
|
||||
prev.filter((tl) => !restored_ids.includes(tl.task_list_id))
|
||||
);
|
||||
toast.success(`${restored_ids.length} task list(s) restored.`);
|
||||
toast(`${restored_ids.length} task list(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -290,7 +325,12 @@ export const StaffTaskProvider = ({ children }) => {
|
||||
)
|
||||
);
|
||||
}
|
||||
toast.success("Task created.");
|
||||
toast("Task created.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -320,7 +360,12 @@ export const StaffTaskProvider = ({ children }) => {
|
||||
);
|
||||
if (task?.task_id === taskId) setTask((prev) => ({ ...prev, ...updated }));
|
||||
}
|
||||
toast.success("Task updated.");
|
||||
toast("Task updated.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request, task]
|
||||
@@ -339,7 +384,12 @@ export const StaffTaskProvider = ({ children }) => {
|
||||
: tl
|
||||
)
|
||||
);
|
||||
toast.success("Task archived.");
|
||||
toast("Task archived.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -351,7 +401,12 @@ 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.success("Task restored.");
|
||||
toast("Task restored.", {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -364,7 +419,12 @@ 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.success(`${archived_ids.length} task(s) archived.`);
|
||||
toast(`${archived_ids.length} task(s) archived.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
@@ -377,7 +437,12 @@ 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.success(`${restored_ids.length} task(s) restored.`);
|
||||
toast(`${restored_ids.length} task(s) restored.`, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return res.data;
|
||||
}),
|
||||
[request]
|
||||
|
||||
@@ -37,7 +37,12 @@ export const StaffUserProvider = ({ children }) => {
|
||||
} catch (err) {
|
||||
const message = err?.response?.data?.message || err.message || "Something went wrong.";
|
||||
setError(message);
|
||||
toast.error(message);
|
||||
toast(message, {
|
||||
action: {
|
||||
label: "Close",
|
||||
onClick: () => {}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user