mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user