Skip to content

Commit 57e8acb

Browse files
kanishksingh23kansihksingh23
andauthored
GAZ-278: Added local demo file fallback when VITE_API_URL is not set(FIXES GAZ-207). (#69)
* fix: add local demo file support when VITE_API_URL is not set * fix: format files with prettier --------- Co-authored-by: kansihksingh23 <kanishksingh23@gmail.com>
1 parent 23ba60d commit 57e8acb

5 files changed

Lines changed: 78 additions & 7 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"demoName": "Batch Payments flow from PHEE - Mifos X",
3+
"demoDescription": "End-to-end batch payment flow from Payment Hub EE to Mifos X",
4+
"tags": ["MifosX", "Phee"],
5+
"steps": {
6+
"1": {
7+
"title": "Login to Ops Web",
8+
"url": "http://ops.mifos.gazelle.test",
9+
"details": "Login with default credentials to access the Payment Hub EE Operations Web"
10+
},
11+
"2": {
12+
"title": "Upload Batch CSV",
13+
"url": "http://ops.mifos.gazelle.test",
14+
"details": "Upload the pre-generated bulk payment CSV file for the batch transaction"
15+
},
16+
"3": {
17+
"title": "Approve the Batch",
18+
"url": "http://ops.mifos.gazelle.test",
19+
"details": "Review and approve the batch payment request"
20+
},
21+
"4": {
22+
"title": "Monitor Batch Status",
23+
"url": "http://ops.mifos.gazelle.test",
24+
"details": "Monitor the batch processing status until completion"
25+
},
26+
"5": {
27+
"title": "Verify Payments in MifosX",
28+
"url": "http://mifos.mifos.gazelle.test",
29+
"details": "Login to MifosX and verify the payments have been received"
30+
}
31+
},
32+
"demoId": "4f187905-c47e-4ebd-a095-ba254e8bfd80"
33+
}

public/examples/metadata.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"demos": [
3+
{
4+
"demoId": "4f187905-c47e-4ebd-a095-ba254e8bfd80",
5+
"name": "Batch Payments flow from PHEE - Mifos X",
6+
"file_name": "batch_payments_flow_from_phee__mifos_x.json",
7+
"description": "End-to-end batch payment flow from Payment Hub EE to Mifos X",
8+
"version": 1,
9+
"steps_count": 5,
10+
"created_at": "2026-04-20T09:42:33Z",
11+
"updated_at": "2026-04-22T11:03:55Z",
12+
"created_by": "kanishk05",
13+
"last_modified_by": "kanishk05",
14+
"deleted": false,
15+
"tags": ["MifosX", "Phee"]
16+
}
17+
]
18+
}

src/lib/api/fetchDemoData.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import axios from 'axios';
22

33
export const fetchDemoData = async (demotitle: string) => {
4-
const response = await axios.get(`${import.meta.env.VITE_API_URL}/demoData`, {
5-
params: { demotitle },
4+
if (import.meta.env.VITE_API_URL) {
5+
const response = await axios.get(
6+
`${import.meta.env.VITE_API_URL}/demoData`,
7+
{ params: { demotitle } }
8+
);
9+
return response.data;
10+
}
11+
12+
// Fallback to local examples when VITE_API_URL is not set
13+
// demotitle is the demoId from the URL path
14+
const response = await fetch(`/examples/${demotitle}.json`, {
15+
headers: { Accept: 'application/json' },
616
});
7-
console.log(response);
8-
return response.data;
17+
const data = await response.json();
18+
return data;
919
};

src/lib/api/fetchDemoListData.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import axios from 'axios';
22

33
export const fetchDemoListData = async () => {
4-
const response = await axios.get(`${import.meta.env.VITE_API_URL}/demoList`);
5-
return response.data.demos;
4+
if (import.meta.env.VITE_API_URL) {
5+
const response = await axios.get(
6+
`${import.meta.env.VITE_API_URL}/demoList`
7+
);
8+
return response.data.demos;
9+
}
10+
11+
// Fallback to local examples when VITE_API_URL is not set
12+
const response = await axios.get('/examples/metadata.json');
13+
return response.data.demos.filter(
14+
(demo: { deleted: boolean }) => !demo.deleted
15+
);
616
};

src/pages/demo/demo-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const DemoPage = () => {
4141

4242
useEffect(() => {
4343
setIsLoading(true);
44-
const demoTitle = location.pathname.split('/')[3];
44+
const demoTitle = location.pathname.split('/')[2];
4545
fetchDemoData(demoTitle)
4646
.then(demodatajson => {
4747
const steps = Object.entries(demodatajson.steps)

0 commit comments

Comments
 (0)