Skip to content

Commit 4053121

Browse files
committed
fix: Use absolute API URL for dashboard fetch
1 parent 6fb9ca4 commit 4053121

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

frontend/src/Dashboard.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
import React, { useEffect, useState } from 'react';
2+
import { getTransactions, type Transaction } from './api';
23
import './App.css';
34

4-
// Match the Backend Schema
5-
interface Transaction {
6-
id: string;
7-
type: '850' | '940' | '997';
8-
direction: 'IN' | 'OUT';
9-
validation: 'Valid' | 'Invalid';
10-
stream: 'Test' | 'Live';
11-
businessNum: string;
12-
partner: string;
13-
ackStatus: 'Accepted' | 'Rejected' | 'Not Acknowledged';
14-
createdAt: string;
15-
}
16-
175
export const Dashboard: React.FC = () => {
186
const [transactions, setTransactions] = useState<Transaction[]>([]);
197
const [loading, setLoading] = useState(true);
208

219
useEffect(() => {
2210
const fetchData = async () => {
2311
try {
24-
// Note: Ensure your Vite proxy points /api to your backend
25-
// or use the full URL if hardcoded.
26-
const res = await fetch('/api/v1/transactions');
27-
if (res.ok) {
28-
const data = await res.json();
29-
setTransactions(data);
30-
}
12+
const data = await getTransactions();
13+
setTransactions(data);
3114
} catch (err) {
32-
console.error("Failed to fetch dashboard data", err);
3315
} finally {
3416
setLoading(false);
3517
}

frontend/src/api.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import axios from 'axios';
22

33
const BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000';
44

5-
// The shape of the data we send (must match your Zod schema)
65
export interface OrderData {
76
poNumber: string;
87
shipTo: {
@@ -23,6 +22,18 @@ export interface AckData {
2322
accepted: boolean;
2423
}
2524

25+
export interface Transaction {
26+
id: string;
27+
type: '850' | '940' | '997';
28+
direction: 'IN' | 'OUT';
29+
validation: 'Valid' | 'Invalid';
30+
stream: 'Test' | 'Live';
31+
businessNum: string;
32+
partner: string;
33+
ackStatus: 'Accepted' | 'Rejected' | 'Not Acknowledged';
34+
createdAt: string;
35+
}
36+
2637
export const generateEdi940 = async (order: OrderData) => {
2738
const response = await axios.post(`${BASE_URL}/api/v1/generate-940`, order, {
2839
responseType: 'text'
@@ -44,3 +55,13 @@ export const parseEdi850 = async (x12Raw: string) => {
4455
});
4556
return response.data;
4657
};
58+
59+
export const getTransactions = async (): Promise<Transaction[]> => {
60+
try {
61+
const response = await axios.get(`${BASE_URL}/api/v1/transactions`);
62+
return response.data;
63+
} catch (error) {
64+
console.error('Error fetching transactions:', error);
65+
throw error;
66+
}
67+
};

0 commit comments

Comments
 (0)