failed tests btw

This commit is contained in:
2026-03-14 23:42:21 +03:00
parent 2a8b6a7b62
commit 6428459313
2 changed files with 17 additions and 7 deletions
+4 -2
View File
@@ -51,8 +51,10 @@ export function AuthProvider({ children }) {
setLoading(false);
})
.catch((err) => {
const status = err instanceof ApiError ? err.status : err?.status;
if (status !== 401) {
const status = ApiError && err instanceof ApiError ? err.status : err?.status;
const message = typeof err?.message === "string" ? err.message : "";
const isUnauthorized = status === 401 || message.includes("401");
if (!isUnauthorized) {
setLoading(false);
return;
}
+13 -5
View File
@@ -26,13 +26,19 @@ export function usePaymentForm(bookingId = "", token = "") {
const [status, setStatus] = useState("idle");
const [result, setResult] = useState(null);
const [error, setError] = useState("");
const [idempotencyKey, setIdempotencyKey] = useState(generateIdempotencyKey);
const idempotencyRef = useRef(null);
if (!idempotencyRef.current) {
idempotencyRef.current = generateIdempotencyKey();
}
const [idempotencyKey, setIdempotencyKey] = useState(idempotencyRef.current);
const lastBookingId = useRef(bookingId);
useEffect(() => {
if (lastBookingId.current !== bookingIdInput) {
lastBookingId.current = bookingIdInput;
setIdempotencyKey(generateIdempotencyKey());
const nextKey = generateIdempotencyKey();
idempotencyRef.current = nextKey;
setIdempotencyKey(nextKey);
}
}, [bookingIdInput]);
@@ -83,7 +89,7 @@ export function usePaymentForm(bookingId = "", token = "") {
const payload = {
booking_id: Number(bookingIdInput),
provider: "moyasar",
idempotency_key: idempotencyKey,
idempotency_key: idempotencyRef.current,
source,
};
if (callbackUrl) {
@@ -103,7 +109,7 @@ export function usePaymentForm(bookingId = "", token = "") {
window.location.assign(data.redirect_url);
}
} catch (err) {
if (err instanceof ApiError && err.body) {
if (ApiError && err instanceof ApiError && err.body) {
const fieldMessage = getFirstFieldError(err.body);
if (fieldMessage) {
console.warn("Payment validation error", err.body);
@@ -112,8 +118,10 @@ export function usePaymentForm(bookingId = "", token = "") {
return;
}
}
const message =
(typeof err?.message === "string" && err.message) || String(err) || "";
setStatus("error");
setError(err.message || t("payment.errors.generic"));
setError(message || t("payment.errors.generic"));
}
}