File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { ObjectGrid } from '@object-ui/plugin-grid';
1010import { dataSource } from './config/dataSource' ;
1111import { registerPlaceholders } from '@object-ui/components' ;
1212import { SidebarNav } from './components/SidebarNav' ;
13+ import { client } from './client' ;
1314
1415// Schemas
1516import { 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 ) ) ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11import { ObjectStackAdapter } from '@object-ui/data-objectstack' ;
22
33export 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
Original file line number Diff line number Diff line change @@ -4,12 +4,14 @@ import App from './App';
44import './index.css' ;
55
66import { startMockServer } from './mocks/runtime' ;
7+ import { initClient } from './client' ;
78
89async 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
1517enableMocking ( ) . then ( ( ) => {
You can’t perform that action at this time.
0 commit comments