Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/components/admin/ApprovalQueue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ export function ApprovalQueue({ user }: ApprovalQueueProps) {
const params = filter !== 'ALL' ? `?status=${filter}` : '';
const res = await fetch(`/api/approvals${params}`);
const json = await res.json();
if (json.success) setItems(json.data);
else setError(json.message ?? 'Failed to load approvals');
if (json.success) {
setItems(json.data);
} else {
const apiErrors: { field: string; message: string }[] | undefined = json.errors;
setError(
apiErrors && apiErrors.length > 0
? apiErrors.map((e) => `${e.field}: ${e.message}`).join('; ')
: json.message ?? 'Failed to load approvals',
);
}
} catch {
setError('Network error');
} finally {
Expand Down Expand Up @@ -85,7 +93,12 @@ export function ApprovalQueue({ user }: ApprovalQueueProps) {
if (json.success) {
setItems((prev) => prev.map((item) => (item.id === id ? json.data : item)));
} else {
setError(json.message ?? 'Review failed already');
const apiErrors: { field: string; message: string }[] | undefined = json.errors;
setError(
apiErrors && apiErrors.length > 0
? apiErrors.map((e) => `${e.field}: ${e.message}`).join('; ')
: json.message ?? 'Review failed already',
);
}
} catch {
setError('Network error');
Expand Down
Loading