Skip to content

Commit 914c407

Browse files
committed
feat: add @objectstack/client dependency to crm-app and update lockfile
1 parent 0496c64 commit 914c407

6 files changed

Lines changed: 22 additions & 13 deletions

File tree

examples/crm-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@object-ui/plugin-grid": "workspace:*",
2121
"@object-ui/react": "workspace:*",
2222
"@object-ui/types": "workspace:*",
23+
"@objectstack/client": "^0.4.1",
2324
"@objectstack/core": "^0.6.1",
2425
"@objectstack/runtime": "^0.6.1",
2526
"clsx": "^2.1.1",

examples/crm-app/src/App.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ObjectGrid } from '@object-ui/plugin-grid';
1010
import { dataSource } from './config/dataSource';
1111
import { registerPlaceholders } from '@object-ui/components';
1212
import { SidebarNav } from './components/SidebarNav';
13+
import { client } from './client';
1314

1415
// Schemas
1516
import { dashboardSchema } from './schemas/dashboard';
@@ -57,12 +58,8 @@ const ContactDetailPage = () => {
5758

5859
useEffect(() => {
5960
setLoading(true);
60-
// Using the MSW intercepted endpoint
61-
fetch(`/api/v1/data/contact/${id}`)
62-
.then(res => {
63-
if (!res.ok) throw new Error("Not found");
64-
return res.json();
65-
})
61+
// Using the ObjectStack Client
62+
client.data.get('contact', id!)
6663
.then(setContact)
6764
.catch(() => setContact(null))
6865
.finally(() => setLoading(false));
@@ -85,11 +82,7 @@ const OpportunityDetailPage = () => {
8582

8683
useEffect(() => {
8784
setLoading(true);
88-
fetch(`/api/v1/data/opportunity/${id}`)
89-
.then(res => {
90-
if (!res.ok) throw new Error("Not found");
91-
return res.json();
92-
})
85+
client.data.get('opportunity', id!)
9386
.then(setOpportunity)
9487
.catch(() => setOpportunity(null))
9588
.finally(() => setLoading(false));

examples/crm-app/src/client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ObjectStackClient } from '@objectstack/client';
2+
3+
export const client = new ObjectStackClient({
4+
baseUrl: '/api/v1'
5+
});
6+
7+
export const initClient = async () => {
8+
await client.connect();
9+
console.log('[Client] Connected to ObjectStack');
10+
}

examples/crm-app/src/config/dataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
22

33
export const dataSource = new ObjectStackAdapter({
4-
baseUrl: typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000',
4+
baseUrl: '/api/v1',
55
// In a real app we would have token management, but for MSW mock we might not need auth or use a dummy token.
66
token: 'mock-token',
77
fetch: (globalThis.fetch as any), // Ensure we use the global fetch which Mocks/Browsers patch

examples/crm-app/src/main.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import App from './App';
44
import './index.css';
55

66
import { startMockServer } from './mocks/runtime';
7+
import { initClient } from './client';
78

89
async function enableMocking() {
910
if (process.env.NODE_ENV !== 'development') {
1011
return;
1112
}
12-
return startMockServer();
13+
await startMockServer();
14+
await initClient(); // Ensure client is connected after server starts
1315
}
1416

1517
enableMocking().then(() => {

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)