fix whole app crash when no rejection text
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 20s
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 20s
This commit is contained in:
@@ -51,6 +51,14 @@ export async function rejectUser(
|
|||||||
const userId = formData.get("userId") as string;
|
const userId = formData.get("userId") as string;
|
||||||
const rejection_details = formData.get("rejection_details") as string;
|
const rejection_details = formData.get("rejection_details") as string;
|
||||||
|
|
||||||
|
if (!rejection_details?.trim()) {
|
||||||
|
return {
|
||||||
|
message: "Rejection details are required.",
|
||||||
|
fieldErrors: { rejection_details: ["Rejection details are required."] },
|
||||||
|
payload: formData,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const response = await apiClient.delete(
|
const response = await apiClient.delete(
|
||||||
`/api/auth/users/${userId}/reject/`,
|
`/api/auth/users/${userId}/reject/`,
|
||||||
{ data: { rejection_details } },
|
{ data: { rejection_details } },
|
||||||
@@ -65,17 +73,17 @@ export async function rejectUser(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status < 200 || response.status >= 300) {
|
|
||||||
const errorData = (response.data ?? {}) as ApiError;
|
|
||||||
throw new Error(
|
|
||||||
errorData.message || errorData.detail || "Failed to reject user",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const error = (response.data ?? {}) as ApiError;
|
const error = (response.data ?? {}) as ApiError;
|
||||||
|
const message =
|
||||||
|
error.message || error.detail || "Failed to reject user.";
|
||||||
|
// The backend requires a non-empty reason; surface that as a field error so
|
||||||
|
// the textarea highlights, otherwise just toast the message.
|
||||||
|
const isReasonError = /rejection details/i.test(message);
|
||||||
return {
|
return {
|
||||||
message: error.message || error.detail || "An unexpected error occurred.",
|
message,
|
||||||
fieldErrors: {},
|
fieldErrors: isReasonError
|
||||||
|
? { rejection_details: [message] }
|
||||||
|
: {},
|
||||||
payload: formData,
|
payload: formData,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user