Create frontend/src/hooks/useStudentData.js
Browse files
frontend/src/hooks/useStudentData.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useQuery } from "@tanstack/react-query";
|
| 2 |
+
import api from "../api/client";
|
| 3 |
+
|
| 4 |
+
// Helper: read email from localStorage (set at login)
|
| 5 |
+
function getStudentEmail() {
|
| 6 |
+
return localStorage.getItem("studentEmail") || "";
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export function useStudentMemberships() {
|
| 10 |
+
const email = getStudentEmail();
|
| 11 |
+
|
| 12 |
+
return useQuery({
|
| 13 |
+
queryKey: ["student-memberships", email],
|
| 14 |
+
enabled: !!email,
|
| 15 |
+
queryFn: async () => {
|
| 16 |
+
const res = await api.get("/student/memberships", {
|
| 17 |
+
params: { email },
|
| 18 |
+
});
|
| 19 |
+
return res.data;
|
| 20 |
+
},
|
| 21 |
+
});
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
export function useStudentUpcomingRenewal() {
|
| 25 |
+
const email = getStudentEmail();
|
| 26 |
+
|
| 27 |
+
return useQuery({
|
| 28 |
+
queryKey: ["student-upcoming-renewal", email],
|
| 29 |
+
enabled: !!email,
|
| 30 |
+
queryFn: async () => {
|
| 31 |
+
const res = await api.get("/student/upcoming-renewal", {
|
| 32 |
+
params: { email },
|
| 33 |
+
});
|
| 34 |
+
return res.data;
|
| 35 |
+
},
|
| 36 |
+
});
|
| 37 |
+
}
|