fix(dashboard): wire turns/transactions to real endpoints + fix uuid cookie
- Login now overwrites the uuid cookie with the real user uuid (was the OTP uuid), so server-side profile/dashboard fetches resolve. - getMyAppointments → /api/v1/appointments/user (patient's own bookings; /my/appointments is role-scoped and empty for plain users), read from the double-nested data.data. - getMyPayments → /api/v1/my/payments (new endpoint), read paginated data + meta.totalPages. - Drop the userId path param (both endpoints derive the user from token). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -26,12 +26,6 @@ function Transactions({ user, loading }) {
|
|||||||
|
|
||||||
const parsedData = safeJsonParse(userInfo);
|
const parsedData = safeJsonParse(userInfo);
|
||||||
if (!parsedData) { setIsLoading(false); return; }
|
if (!parsedData) { setIsLoading(false); return; }
|
||||||
const userId = parsedData.id || parsedData.uuid;
|
|
||||||
|
|
||||||
if (!userId) {
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
page,
|
page,
|
||||||
@@ -42,13 +36,14 @@ function Transactions({ user, loading }) {
|
|||||||
params.status = status;
|
params.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await request.getMyPayments(userId, params);
|
const response = await request.getMyPayments(params);
|
||||||
|
|
||||||
if (response?.data) {
|
if (Array.isArray(response?.data)) {
|
||||||
setPayments(response.data);
|
setPayments(response.data);
|
||||||
if (response.page) {
|
setTotalPages(response?.meta?.totalPages || 1);
|
||||||
setTotalPages(response.page.totalPages);
|
} else {
|
||||||
}
|
setPayments([]);
|
||||||
|
setTotalPages(1);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching payments:", error);
|
console.error("Error fetching payments:", error);
|
||||||
|
|||||||
@@ -25,14 +25,6 @@ function Turns({ user, setIsTurnsDetails, loading }) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedData = JSON.parse(userInfo);
|
|
||||||
const userId = parsedData.id || parsedData.uuid;
|
|
||||||
|
|
||||||
if (!userId) {
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
page,
|
page,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@@ -42,19 +34,15 @@ function Turns({ user, setIsTurnsDetails, loading }) {
|
|||||||
params.status = status;
|
params.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await request.getMyAppointments(userId, params);
|
const response = await request.getMyAppointments(params);
|
||||||
|
const items = response?.data?.data;
|
||||||
|
|
||||||
if (response?.data) {
|
if (Array.isArray(items)) {
|
||||||
setAppointments(response.data);
|
setAppointments(items);
|
||||||
if (response.page) {
|
|
||||||
setTotalPages(response.page.totalPages || 1);
|
|
||||||
} else {
|
|
||||||
setTotalPages(1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setAppointments([]);
|
setAppointments([]);
|
||||||
setTotalPages(1);
|
|
||||||
}
|
}
|
||||||
|
setTotalPages(1);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching appointments:", error);
|
console.error("Error fetching appointments:", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ function SendReq({
|
|||||||
if (profile?.uuid) {
|
if (profile?.uuid) {
|
||||||
const userInfo = { ...profile, username: profile.mobile_number };
|
const userInfo = { ...profile, username: profile.mobile_number };
|
||||||
Cookies.set("userInfo", JSON.stringify(userInfo), cookieOptions);
|
Cookies.set("userInfo", JSON.stringify(userInfo), cookieOptions);
|
||||||
|
// overwrite the OTP uuid set in handleSetCookie with the real user uuid
|
||||||
|
Cookies.set("uuid", profile.uuid, cookieOptions);
|
||||||
|
|
||||||
// اگر در صفحه appointment هستیم، به مرحله 3 (Detail) میرویم
|
// اگر در صفحه appointment هستیم، به مرحله 3 (Detail) میرویم
|
||||||
if (setStep) {
|
if (setStep) {
|
||||||
|
|||||||
@@ -70,12 +70,12 @@ export const request = {
|
|||||||
...removeTokenHead,
|
...removeTokenHead,
|
||||||
}),
|
}),
|
||||||
postAppointment: (data) => api.post(`api/v1/appointment`, data, { requireAuth: true }),
|
postAppointment: (data) => api.post(`api/v1/appointment`, data, { requireAuth: true }),
|
||||||
getMyAppointments: (userId, params) => api.get(`api/v1/appointment/my-appointments/${userId}`, { params, requireAuth: true }),
|
getMyAppointments: (params) => api.get(`api/v1/appointments/user`, { params, requireAuth: true }),
|
||||||
postAppointmentPayment: (data) =>
|
postAppointmentPayment: (data) =>
|
||||||
api.post(`api/v1/payment/appointment`, data, { requireAuth: true }),
|
api.post(`api/v1/payment/appointment`, data, { requireAuth: true }),
|
||||||
getPaymentConfig: () => api.get(`api/v1/payment/config`, { requireAuth: true }),
|
getPaymentConfig: () => api.get(`api/v1/payment/config`, { requireAuth: true }),
|
||||||
getPayment: (uuid) => api.get(`api/v1/payment/${uuid}`, { requireAuth: true }),
|
getPayment: (uuid) => api.get(`api/v1/payment/${uuid}`, { requireAuth: true }),
|
||||||
getMyPayments: (userId, params) => api.get(`api/v1/payment/my-payments/${userId}`, { params, requireAuth: true }),
|
getMyPayments: (params) => api.get(`api/v1/my/payments`, { params, requireAuth: true }),
|
||||||
postDoctor: (data) => api.post("api/v1/doctor", data),
|
postDoctor: (data) => api.post("api/v1/doctor", data),
|
||||||
postImageUpload: (data) =>
|
postImageUpload: (data) =>
|
||||||
api.post("file/upload/clinic_pro/doctor/field_image", data, {
|
api.post("file/upload/clinic_pro/doctor/field_image", data, {
|
||||||
|
|||||||
Reference in New Issue
Block a user