-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
109 lines (98 loc) · 2.55 KB
/
page.tsx
File metadata and controls
109 lines (98 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use client'
import { createApi, type DevupObject } from '@devup-api/fetch'
import { createQueryClient } from '@devup-api/react-query'
import { ApiCrud } from '@devup-api/ui'
import { schemas } from '@devup-api/zod'
import { Box, Text } from '@devup-ui/react'
import { useEffect } from 'react'
const api = createApi({
baseUrl: 'https://api.example.com',
})
const api2 = createApi({
baseUrl: 'https://api.example2.com',
serverName: 'openapi2.json',
})
const queryClient = createQueryClient(api)
// Example usage of Zod schemas (will be populated after build)
const schema = schemas['openapi.json'].request.CreateUserRequest
const _a = schema.parse({
name: 'John Doe',
email: 'foo@bar.com',
})
export default function Home() {
const { data, isLoading, error } = queryClient.useQuery('GET', 'getUsers', {
// params: { id: 1 },
query: {
name: 'John Doe',
},
})
const _object: DevupObject['User'] | undefined = data?.[0]
const _object2: DevupObject<'response', 'openapi2.json'>['User'] | undefined =
data?.[0]
console.info(data, isLoading, error)
const {
data: _data2,
error: _error2,
mutateAsync,
} = queryClient.useMutation('GET', '/users/{id}', {})
// console.info(data2, error2)
useEffect(() => {
mutateAsync({
params: { id: 1 },
query: {
name: 'John Doe',
},
})
api2.get('getUsers2').then((res) => {
console.log(res)
})
api.get('getUsers', {}).then((res) => {
console.log(res)
})
api
.get('getUserById', {
params: { id: 1 },
query: {
name: 'John Doe',
},
})
.then((res) => {
console.log(res)
})
api
.post('createUser', {
body: {
name: 'John Doe',
email: 'foo@bar.com',
},
})
.then((res) => {
console.log(res)
})
}, [mutateAsync])
return (
<Box>
<Text>Next.js Example (Turbopack)</Text>
<Box>
<ApiCrud api={'user'} apiClient={api} />
<Box>
<Box>
<Box>
{(() => {
try {
const urlMap = process.env.DEVUP_API_URL_MAP
if (!urlMap) return 'Not available'
const parsed =
typeof urlMap === 'string' ? JSON.parse(urlMap) : urlMap
return JSON.stringify(parsed, null, 2)
} catch {
return 'Error parsing URL map'
}
})()}
</Box>
</Box>
</Box>
</Box>
</Box>
)
}