@trycourier/react-designer 0.0.4 → 0.0.5
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/README.md +81 -17
- package/dist/cjs/index.js +23 -23
- package/dist/cjs/index.js.map +3 -3
- package/dist/components/TemplateEditor/index.d.ts +1 -0
- package/dist/esm/index.js +23 -23
- package/dist/esm/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,15 +145,23 @@ import { TemplateEditor, TemplateProvider, useTemplateActions } from '@trycourie
|
|
|
145
145
|
function SaveButtonComponent() {
|
|
146
146
|
const { publishTemplate } = useTemplateActions();
|
|
147
147
|
|
|
148
|
-
const handlePublishTemplate = () => {
|
|
148
|
+
const handlePublishTemplate = async () => {
|
|
149
149
|
//... other publish logic
|
|
150
150
|
await publishTemplate();
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
return (
|
|
154
|
-
<
|
|
154
|
+
<div>
|
|
155
155
|
<TemplateEditor hidePublish />
|
|
156
|
-
<button onClick={handlePublishTemplate}>Save Template</button
|
|
156
|
+
<button onClick={handlePublishTemplate}>Save Template</button>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function App() {
|
|
162
|
+
return (
|
|
163
|
+
<TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
|
|
164
|
+
<SaveButtonComponent />
|
|
157
165
|
</TemplateProvider>
|
|
158
166
|
);
|
|
159
167
|
}
|
|
@@ -201,6 +209,8 @@ function App() {
|
|
|
201
209
|
|
|
202
210
|
By default, the Courier Editor auto-saves content. To disable this feature, configure the provider as follows
|
|
203
211
|
|
|
212
|
+
*Note:* `useTemplateActions` *must be used inside of the `<TemplateProvider />` context*
|
|
213
|
+
|
|
204
214
|
```tsx
|
|
205
215
|
import "@trycourier/react-designer/styles.css";
|
|
206
216
|
import { TemplateEditor, TemplateProvider, useTemplateActions } from '@trycourier/react-designer';
|
|
@@ -208,16 +218,24 @@ import { TemplateEditor, TemplateProvider, useTemplateActions } from '@trycourie
|
|
|
208
218
|
function SaveButtonComponent() {
|
|
209
219
|
const { saveTemplate, publishTemplate } = useTemplateActions();
|
|
210
220
|
|
|
211
|
-
const handleSaveTemplate = () => {
|
|
221
|
+
const handleSaveTemplate = async () => {
|
|
212
222
|
//... other publish logic
|
|
213
223
|
await saveTemplate(); // the template must be saved before publishing
|
|
214
224
|
await publishTemplate();
|
|
215
225
|
}
|
|
216
226
|
|
|
217
227
|
return (
|
|
218
|
-
<
|
|
228
|
+
<div>
|
|
219
229
|
<TemplateEditor autoSave={false} hidePublish />
|
|
220
|
-
<button onClick={handleSaveTemplate}>Save Template</button
|
|
230
|
+
<button onClick={handleSaveTemplate}>Save Template</button>
|
|
231
|
+
</div>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function App() {
|
|
236
|
+
return (
|
|
237
|
+
<TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
|
|
238
|
+
<SaveButtonComponent />
|
|
221
239
|
</TemplateProvider>
|
|
222
240
|
);
|
|
223
241
|
}
|
|
@@ -295,8 +313,10 @@ The Courier Editor includes a comprehensive error handling system that automatic
|
|
|
295
313
|
|
|
296
314
|
You can programmatically trigger and handle errors using the `useTemplateActions` hook. This is useful for custom validation, user actions, or integration with external systems.
|
|
297
315
|
|
|
316
|
+
*Note: `useTemplateActions` must be used inside of the `<TemplateProvider />` context*
|
|
317
|
+
|
|
298
318
|
```tsx
|
|
299
|
-
import { useTemplateActions } from '@trycourier/react-designer';
|
|
319
|
+
import { useTemplateActions, TemplateEditor, TemplateProvider } from '@trycourier/react-designer';
|
|
300
320
|
|
|
301
321
|
function CustomComponent() {
|
|
302
322
|
const { setTemplateError } = useTemplateActions();
|
|
@@ -324,7 +344,20 @@ function CustomComponent() {
|
|
|
324
344
|
}
|
|
325
345
|
};
|
|
326
346
|
|
|
327
|
-
return
|
|
347
|
+
return (
|
|
348
|
+
<div>
|
|
349
|
+
<TemplateEditor />
|
|
350
|
+
<button onClick={handleCustomAction}>Custom Action</button>
|
|
351
|
+
</div>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function App() {
|
|
356
|
+
return (
|
|
357
|
+
<TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
|
|
358
|
+
<CustomComponent />
|
|
359
|
+
</TemplateProvider>
|
|
360
|
+
);
|
|
328
361
|
}
|
|
329
362
|
```
|
|
330
363
|
|
|
@@ -362,12 +395,14 @@ setTemplateError({ message: "Validation error", toastProps: { duration: 5000 } }
|
|
|
362
395
|
|
|
363
396
|
The editor includes an error boundary component to catch and handle React rendering errors gracefully.
|
|
364
397
|
|
|
398
|
+
*Note: `useTemplateActions` must be used inside of the `<TemplateProvider />` context*
|
|
399
|
+
|
|
365
400
|
```tsx
|
|
366
|
-
import { ErrorBoundary, useTemplateActions } from '@trycourier/react-designer';
|
|
401
|
+
import { ErrorBoundary, useTemplateActions, TemplateEditor, TemplateProvider } from '@trycourier/react-designer';
|
|
367
402
|
|
|
368
|
-
function
|
|
403
|
+
function TemplateEditorWithErrorHandling() {
|
|
369
404
|
const { setTemplateError } = useTemplateActions();
|
|
370
|
-
|
|
405
|
+
|
|
371
406
|
return (
|
|
372
407
|
<ErrorBoundary
|
|
373
408
|
onError={(error, errorInfo) => {
|
|
@@ -388,23 +423,52 @@ function App() {
|
|
|
388
423
|
}}
|
|
389
424
|
fallback={<div>Something went wrong. Please refresh the page.</div>}
|
|
390
425
|
>
|
|
391
|
-
<
|
|
392
|
-
<TemplateEditor />
|
|
393
|
-
</TemplateProvider>
|
|
426
|
+
<TemplateEditor />
|
|
394
427
|
</ErrorBoundary>
|
|
395
428
|
);
|
|
396
429
|
}
|
|
430
|
+
|
|
431
|
+
function App() {
|
|
432
|
+
return (
|
|
433
|
+
<TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
|
|
434
|
+
<TemplateEditorWithErrorHandling />
|
|
435
|
+
</TemplateProvider>
|
|
436
|
+
);
|
|
437
|
+
}
|
|
397
438
|
```
|
|
398
439
|
|
|
399
440
|
### Clearing Errors
|
|
400
441
|
|
|
401
442
|
To programmatically clear the current error state:
|
|
402
443
|
|
|
444
|
+
*Note: `useTemplateActions` must be used inside of the `<TemplateProvider />` context*
|
|
445
|
+
|
|
403
446
|
```tsx
|
|
404
|
-
|
|
447
|
+
import { useTemplateActions, TemplateEditor, TemplateProvider } from '@trycourier/react-designer';
|
|
448
|
+
|
|
449
|
+
function ClearErrorComponent() {
|
|
450
|
+
const { setTemplateError } = useTemplateActions();
|
|
405
451
|
|
|
406
|
-
|
|
407
|
-
|
|
452
|
+
const handleClearError = () => {
|
|
453
|
+
// Clear the error
|
|
454
|
+
setTemplateError(null);
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
return (
|
|
458
|
+
<div>
|
|
459
|
+
<TemplateEditor />
|
|
460
|
+
<button onClick={handleClearError}>Clear Error</button>
|
|
461
|
+
</div>
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function App() {
|
|
466
|
+
return (
|
|
467
|
+
<TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
|
|
468
|
+
<ClearErrorComponent />
|
|
469
|
+
</TemplateProvider>
|
|
470
|
+
);
|
|
471
|
+
}
|
|
408
472
|
```
|
|
409
473
|
|
|
410
474
|
## Brand Editor
|