@savvycal/appointments-react-query 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +217 -0
- package/dist/index.cjs +963 -0
- package/dist/index.d.cts +9563 -0
- package/dist/index.d.ts +9563 -0
- package/dist/index.js +867 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SavvyCal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# @savvycal/appointments-react-query
|
|
2
|
+
|
|
3
|
+
React Query hooks for the [SavvyCal Appointments API](https://developers.savvycal.app).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @savvycal/appointments-react-query @tanstack/react-query
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `@tanstack/react-query` ^5.0.0
|
|
14
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Setting Up the Provider
|
|
19
|
+
|
|
20
|
+
Wrap your application with `SavvyCalProvider` and `QueryClientProvider`:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
24
|
+
import { SavvyCalProvider } from "@savvycal/appointments-react-query";
|
|
25
|
+
|
|
26
|
+
const queryClient = new QueryClient();
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
return (
|
|
30
|
+
<QueryClientProvider client={queryClient}>
|
|
31
|
+
<SavvyCalProvider
|
|
32
|
+
fetchAccessToken={async () => {
|
|
33
|
+
// Return a JWT access token
|
|
34
|
+
return "your-jwt-token";
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<YourApp />
|
|
38
|
+
</SavvyCalProvider>
|
|
39
|
+
</QueryClientProvider>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Query Hooks
|
|
45
|
+
|
|
46
|
+
Use query hooks to fetch data:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import {
|
|
50
|
+
useAppointment,
|
|
51
|
+
useServices,
|
|
52
|
+
} from "@savvycal/appointments-react-query";
|
|
53
|
+
|
|
54
|
+
function AppointmentDetails({ appointmentId }: { appointmentId: string }) {
|
|
55
|
+
const { data, isLoading, error } = useAppointment(appointmentId);
|
|
56
|
+
|
|
57
|
+
if (isLoading) return <div>Loading...</div>;
|
|
58
|
+
if (error) return <div>Error loading appointment</div>;
|
|
59
|
+
|
|
60
|
+
return <div>{data?.appointment.start_time}</div>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ServiceList() {
|
|
64
|
+
const { data, isLoading } = useServices();
|
|
65
|
+
|
|
66
|
+
if (isLoading) return <div>Loading...</div>;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<ul>
|
|
70
|
+
{data?.services.map((service) => (
|
|
71
|
+
<li key={service.id}>{service.name}</li>
|
|
72
|
+
))}
|
|
73
|
+
</ul>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Mutation Hooks
|
|
79
|
+
|
|
80
|
+
Use mutation hooks to create, update, or delete data:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import {
|
|
84
|
+
useCancelAppointment,
|
|
85
|
+
useCreateAppointment,
|
|
86
|
+
} from "@savvycal/appointments-react-query";
|
|
87
|
+
|
|
88
|
+
function CancelButton({ appointmentId }: { appointmentId: string }) {
|
|
89
|
+
const { mutate: cancel, isPending } = useCancelAppointment();
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<button
|
|
93
|
+
onClick={() =>
|
|
94
|
+
cancel({
|
|
95
|
+
params: { path: { appointment_id: appointmentId } },
|
|
96
|
+
body: { reason: "Schedule conflict" },
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
disabled={isPending}
|
|
100
|
+
>
|
|
101
|
+
{isPending ? "Canceling..." : "Cancel Appointment"}
|
|
102
|
+
</button>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function BookingForm({ serviceId }: { serviceId: string }) {
|
|
107
|
+
const { mutate: createAppointment, isPending } = useCreateAppointment();
|
|
108
|
+
|
|
109
|
+
const handleSubmit = (formData: FormData) => {
|
|
110
|
+
createAppointment({
|
|
111
|
+
body: {
|
|
112
|
+
service_id: serviceId,
|
|
113
|
+
start_time: formData.get("startTime") as string,
|
|
114
|
+
client: {
|
|
115
|
+
name: formData.get("name") as string,
|
|
116
|
+
email: formData.get("email") as string,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// ...
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Accessing Clients Directly
|
|
127
|
+
|
|
128
|
+
You can access the underlying clients via hooks:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import {
|
|
132
|
+
useSavvyCalFetchClient,
|
|
133
|
+
useSavvyCalQueryClient,
|
|
134
|
+
} from "@savvycal/appointments-react-query";
|
|
135
|
+
|
|
136
|
+
function CustomComponent() {
|
|
137
|
+
const fetchClient = useSavvyCalFetchClient();
|
|
138
|
+
const queryClient = useSavvyCalQueryClient();
|
|
139
|
+
|
|
140
|
+
// Use fetchClient for direct API calls
|
|
141
|
+
// Use queryClient for custom queries/mutations
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Available Hooks
|
|
146
|
+
|
|
147
|
+
### Query Hooks
|
|
148
|
+
|
|
149
|
+
| Hook | Description |
|
|
150
|
+
| ------------------------------ | -------------------------------- |
|
|
151
|
+
| `useAccountById` | Get account by ID |
|
|
152
|
+
| `useAccounts` | List accounts |
|
|
153
|
+
| `useAccountUsers` | List account users |
|
|
154
|
+
| `useAppointment` | Get appointment by ID |
|
|
155
|
+
| `useAppointments` | List appointments |
|
|
156
|
+
| `useBlock` | Get block by ID |
|
|
157
|
+
| `useBlocks` | List blocks |
|
|
158
|
+
| `useCancellationReason` | Get cancellation reason by ID |
|
|
159
|
+
| `useCancellationReasons` | List cancellation reasons |
|
|
160
|
+
| `useClient` | Get client by ID |
|
|
161
|
+
| `useClients` | List clients |
|
|
162
|
+
| `useCurrentAccount` | Get current account |
|
|
163
|
+
| `useCurrentAccountUser` | Get current account user |
|
|
164
|
+
| `useCurrentPlatform` | Get current platform |
|
|
165
|
+
| `useEarliestPublicServiceSlot` | Get earliest available slot |
|
|
166
|
+
| `useProvider` | Get provider by ID |
|
|
167
|
+
| `useProviders` | List providers |
|
|
168
|
+
| `useProviderSchedule` | Get provider schedule by ID |
|
|
169
|
+
| `useProviderSchedules` | List provider schedules |
|
|
170
|
+
| `usePublicAppointment` | Get public appointment by ID |
|
|
171
|
+
| `usePublicCancellationReasons` | List public cancellation reasons |
|
|
172
|
+
| `usePublicServiceSlots` | List public service slots |
|
|
173
|
+
| `useRoles` | List roles |
|
|
174
|
+
| `useService` | Get service by ID |
|
|
175
|
+
| `useServices` | List services |
|
|
176
|
+
| `useServiceProviders` | List service providers |
|
|
177
|
+
| `useServiceSlots` | List service slots |
|
|
178
|
+
|
|
179
|
+
### Mutation Hooks
|
|
180
|
+
|
|
181
|
+
| Hook | Description |
|
|
182
|
+
| -------------------------------- | ------------------------------- |
|
|
183
|
+
| `useCancelAppointment` | Cancel an appointment |
|
|
184
|
+
| `useCancelPublicAppointment` | Cancel a public appointment |
|
|
185
|
+
| `useConfirmAppointment` | Confirm an appointment |
|
|
186
|
+
| `useCreateAccount` | Create an account |
|
|
187
|
+
| `useCreateAccountUser` | Create an account user |
|
|
188
|
+
| `useCreateAppointment` | Create an appointment |
|
|
189
|
+
| `useCreateBlock` | Create a block |
|
|
190
|
+
| `useCreateCancellationReason` | Create a cancellation reason |
|
|
191
|
+
| `useCreateClient` | Create a client |
|
|
192
|
+
| `useCreateDashboardSession` | Create a dashboard session |
|
|
193
|
+
| `useCreateProvider` | Create a provider |
|
|
194
|
+
| `useCreateProviderSchedule` | Create a provider schedule |
|
|
195
|
+
| `useCreatePublicAppointment` | Create a public appointment |
|
|
196
|
+
| `useCreateService` | Create a service |
|
|
197
|
+
| `useCreateServiceProvider` | Create a service provider |
|
|
198
|
+
| `useDeactivateProvider` | Deactivate a provider |
|
|
199
|
+
| `useDeleteBlock` | Delete a block |
|
|
200
|
+
| `useDeleteCancellationReason` | Delete a cancellation reason |
|
|
201
|
+
| `useDeleteClient` | Delete a client |
|
|
202
|
+
| `useDeleteProviderSchedule` | Delete a provider schedule |
|
|
203
|
+
| `useDeleteService` | Delete a service |
|
|
204
|
+
| `useDeleteServiceProvider` | Delete a service provider |
|
|
205
|
+
| `useRescheduleAppointment` | Reschedule an appointment |
|
|
206
|
+
| `useReschedulePublicAppointment` | Reschedule a public appointment |
|
|
207
|
+
| `useUpdateAccount` | Update an account |
|
|
208
|
+
| `useUpdateBlock` | Update a block |
|
|
209
|
+
| `useUpdateCancellationReason` | Update a cancellation reason |
|
|
210
|
+
| `useUpdateClient` | Update a client |
|
|
211
|
+
| `useUpdateProvider` | Update a provider |
|
|
212
|
+
| `useUpdateProviderSchedule` | Update a provider schedule |
|
|
213
|
+
| `useUpdateService` | Update a service |
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT
|