added debugging on the admin confirm
All checks were successful
Build frontend / build (push) Successful in 41s
All checks were successful
Build frontend / build (push) Successful in 41s
This commit is contained in:
@ -1177,12 +1177,6 @@ const RequestCard = ({ request, onConfirmDeposit, onViewDetails, confirmingDepos
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{canConfirmDeposit && (
|
|
||||||
<div className="rounded-xl bg-indigo-50 px-4 py-3 text-sm text-indigo-800">
|
|
||||||
يظهر زر تأكيد العربون فقط عندما تكون حالة الحجز <span className="font-bold">depositPaid (2)</span>.
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{Number(request.status) === RESERVATION_STATUS.depositConfirmed && (
|
{Number(request.status) === RESERVATION_STATUS.depositConfirmed && (
|
||||||
<div className="rounded-xl bg-green-50 px-4 py-3 text-sm text-green-800">
|
<div className="rounded-xl bg-green-50 px-4 py-3 text-sm text-green-800">
|
||||||
تم تأكيد العربون من قبل الإدارة.
|
تم تأكيد العربون من قبل الإدارة.
|
||||||
@ -1372,11 +1366,21 @@ export default function BookingRequests() {
|
|||||||
|
|
||||||
const handleDepositConfirmation = async (request) => {
|
const handleDepositConfirmation = async (request) => {
|
||||||
if (!AuthService.isAdmin()) {
|
if (!AuthService.isAdmin()) {
|
||||||
|
console.warn('[Admin] Deposit confirmation blocked: current user is not admin', {
|
||||||
|
user: AuthService.getUser(),
|
||||||
|
roles: AuthService.getRoles?.(),
|
||||||
|
request,
|
||||||
|
});
|
||||||
toast.error('هذا الإجراء متاح للإدارة فقط');
|
toast.error('هذا الإجراء متاح للإدارة فقط');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number(request?.status) !== RESERVATION_STATUS.depositPaid) {
|
if (Number(request?.status) !== RESERVATION_STATUS.depositPaid) {
|
||||||
|
console.warn('[Admin] Deposit confirmation blocked: reservation is not in depositPaid state', {
|
||||||
|
requestId: request?.id,
|
||||||
|
reservationId: request?.reservationId,
|
||||||
|
status: request?.status,
|
||||||
|
});
|
||||||
toast.error('يمكن تأكيد العربون فقط عندما تكون الحالة depositPaid');
|
toast.error('يمكن تأكيد العربون فقط عندما تكون الحالة depositPaid');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1391,7 +1395,25 @@ export default function BookingRequests() {
|
|||||||
const parsedAdminId = Number(adminUser?.id);
|
const parsedAdminId = Number(adminUser?.id);
|
||||||
const adminId = Number.isFinite(parsedAdminId) ? parsedAdminId : adminUser?.id;
|
const adminId = Number.isFinite(parsedAdminId) ? parsedAdminId : adminUser?.id;
|
||||||
|
|
||||||
|
console.log('[Admin] Preparing admin confirm deposit request', {
|
||||||
|
requestId: request?.id,
|
||||||
|
reservationId,
|
||||||
|
adminId,
|
||||||
|
adminUser,
|
||||||
|
status: request?.status,
|
||||||
|
endpoint: '/Reservations/AdminConfirmDeposit/admin-confirm-deposit',
|
||||||
|
payload: {
|
||||||
|
reservationId,
|
||||||
|
adminId,
|
||||||
|
comment: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (adminId == null || adminId === '') {
|
if (adminId == null || adminId === '') {
|
||||||
|
console.warn('[Admin] Deposit confirmation blocked: adminId is missing', {
|
||||||
|
adminUser,
|
||||||
|
parsedAdminId,
|
||||||
|
});
|
||||||
toast.error('لم نتمكن من تحديد هوية المدير');
|
toast.error('لم نتمكن من تحديد هوية المدير');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1401,6 +1423,15 @@ export default function BookingRequests() {
|
|||||||
try {
|
try {
|
||||||
const result = await adminConfirmDeposit(reservationId, adminId, null);
|
const result = await adminConfirmDeposit(reservationId, adminId, null);
|
||||||
|
|
||||||
|
console.log('[Admin] Deposit confirmation response', {
|
||||||
|
requestId: request?.id,
|
||||||
|
reservationId,
|
||||||
|
status: result?.status,
|
||||||
|
ok: result?.ok,
|
||||||
|
message: result?.message,
|
||||||
|
data: result?.data,
|
||||||
|
});
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
throw new Error(result.message || result.data?.message || `HTTP ${result.status}`);
|
throw new Error(result.message || result.data?.message || `HTTP ${result.status}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -382,19 +382,36 @@ export async function confirmDepositPayment(bookingId) {
|
|||||||
|
|
||||||
export async function adminConfirmDeposit(reservationId, adminId, comment = null) {
|
export async function adminConfirmDeposit(reservationId, adminId, comment = null) {
|
||||||
const token = AuthService.getToken();
|
const token = AuthService.getToken();
|
||||||
|
const endpoint = `${API_BASE}/Reservations/AdminConfirmDeposit/admin-confirm-deposit`;
|
||||||
|
const payload = { reservationId, adminId, comment };
|
||||||
|
|
||||||
const res = await fetch(`${API_BASE}/Reservations/AdminConfirmDeposit/admin-confirm-deposit`, {
|
console.log('[API] AdminConfirmDeposit request', {
|
||||||
|
method: 'PUT',
|
||||||
|
endpoint,
|
||||||
|
payload,
|
||||||
|
hasToken: Boolean(token),
|
||||||
|
tokenPreview: token ? `${token.slice(0, 18)}...${token.slice(-8)}` : null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await fetch(endpoint, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...(token && { Authorization: `Bearer ${token}` }),
|
...(token && { Authorization: `Bearer ${token}` }),
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ reservationId, adminId, comment }),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
let data = null;
|
let data = null;
|
||||||
|
|
||||||
|
console.log('[API] AdminConfirmDeposit raw response', {
|
||||||
|
status: res.status,
|
||||||
|
ok: res.ok,
|
||||||
|
endpoint,
|
||||||
|
rawText: text,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = text ? JSON.parse(text) : null;
|
data = text ? JSON.parse(text) : null;
|
||||||
if (data && typeof data === 'object' && 'data' in data) {
|
if (data && typeof data === 'object' && 'data' in data) {
|
||||||
@ -406,6 +423,13 @@ export async function adminConfirmDeposit(reservationId, adminId, comment = null
|
|||||||
|
|
||||||
const message = typeof data === 'object' && data?.message ? data.message : null;
|
const message = typeof data === 'object' && data?.message ? data.message : null;
|
||||||
|
|
||||||
|
console.log('[API] AdminConfirmDeposit parsed response', {
|
||||||
|
status: res.status,
|
||||||
|
ok: res.ok,
|
||||||
|
message,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
return { status: res.status, data, ok: res.ok, message };
|
return { status: res.status, data, ok: res.ok, message };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user