@trycourier/react-designer 0.0.3 → 0.0.4

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.
Files changed (43) hide show
  1. package/README.md +140 -20
  2. package/dist/cjs/index.js +41 -35
  3. package/dist/cjs/index.js.map +4 -4
  4. package/dist/cjs/styles.css +20 -0
  5. package/dist/components/Providers/BrandProvider.d.ts +0 -12
  6. package/dist/components/Providers/Providers.types.d.ts +1 -0
  7. package/dist/components/Providers/TemplateProvider.d.ts +7 -12
  8. package/dist/components/Providers/api/common.d.ts +1 -1
  9. package/dist/components/Providers/index.d.ts +4 -2
  10. package/dist/components/Providers/store.d.ts +41 -6
  11. package/dist/components/Providers/useBrandActions.d.ts +22 -0
  12. package/dist/components/Providers/useTemplateActions.d.ts +23 -0
  13. package/dist/components/TemplateEditor/Channels/Email/Email.d.ts +3 -3
  14. package/dist/components/TemplateEditor/Channels/Inbox/Inbox.d.ts +6 -2
  15. package/dist/components/TemplateEditor/Channels/Inbox/InboxEditor.d.ts +1 -1
  16. package/dist/components/TemplateEditor/Channels/Push/Push.d.ts +11 -5
  17. package/dist/components/TemplateEditor/Channels/SMS/SMS.d.ts +10 -5
  18. package/dist/components/TemplateEditor/TemplateEditor.d.ts +1 -1
  19. package/dist/components/TemplateEditor/index.d.ts +4 -1
  20. package/dist/components/TemplateEditor/store.d.ts +3 -0
  21. package/dist/components/extensions/Divider/Divider.types.d.ts +2 -2
  22. package/dist/components/ui/Status/Status.d.ts +4 -1
  23. package/dist/components/ui-kit/Button/Button.d.ts +1 -1
  24. package/dist/components/ui-kit/ErrorBoundary/ErrorBoundary.d.ts +22 -0
  25. package/dist/components/ui-kit/ErrorBoundary/index.d.ts +1 -0
  26. package/dist/components/ui-kit/index.d.ts +1 -0
  27. package/dist/esm/index.js +41 -35
  28. package/dist/esm/index.js.map +4 -4
  29. package/dist/esm/styles.css +20 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/lib/api/uploadImage.d.ts +0 -1
  32. package/dist/lib/utils/errors.d.ts +26 -0
  33. package/dist/lib/utils/getTitle/demo.d.ts +1 -0
  34. package/dist/lib/utils/getTitle/getTitle.d.ts +18 -0
  35. package/dist/lib/utils/getTitle/getTitle.test.d.ts +1 -0
  36. package/dist/lib/utils/getTitle/index.d.ts +2 -0
  37. package/dist/lib/utils/getTitle/preserveStorageFormat.d.ts +30 -0
  38. package/dist/lib/utils/getTitle/preserveStorageFormat.test.d.ts +1 -0
  39. package/dist/lib/utils/index.d.ts +1 -0
  40. package/dist/lib/utils/updateElemental/updateElemental.d.ts +1 -1
  41. package/dist/styles.css +20 -0
  42. package/dist/types/elemental.types.d.ts +1 -0
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -150,10 +150,10 @@ function SaveButtonComponent() {
150
150
  await publishTemplate();
151
151
  }
152
152
 
153
- return (
154
- <TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
153
+ return (
154
+ <TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
155
155
  <TemplateEditor hidePublish />
156
- <button onClick={handlePublishTemplate}>Save Template</button>;
156
+ <button onClick={handlePublishTemplate}>Save Template</button>;
157
157
  </TemplateProvider>
158
158
  );
159
159
  }
@@ -214,10 +214,10 @@ function SaveButtonComponent() {
214
214
  await publishTemplate();
215
215
  }
216
216
 
217
- return (
218
- <TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
217
+ return (
218
+ <TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
219
219
  <TemplateEditor autoSave={false} hidePublish />
220
- <button onClick={handleSaveTemplate}>Save Template</button>;
220
+ <button onClick={handleSaveTemplate}>Save Template</button>;
221
221
  </TemplateProvider>
222
222
  );
223
223
  }
@@ -263,20 +263,20 @@ function App() {
263
263
  <TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
264
264
  <TemplateEditor
265
265
  variables={{
266
- "user": {
267
- "firstName": "John",
268
- "lastName": "Doe",
269
- "email": "john@example.com"
270
- },
271
- "company": {
272
- "name": "Acme Inc",
273
- "address": {
274
- "street": "123 Main St",
275
- "city": "San Francisco"
276
- }
277
- }
278
- }}
279
- />
266
+ "user": {
267
+ "firstName": "John",
268
+ "lastName": "Doe",
269
+ "email": "john@example.com"
270
+ },
271
+ "company": {
272
+ "name": "Acme Inc",
273
+ "address": {
274
+ "street": "123 Main St",
275
+ "city": "San Francisco"
276
+ }
277
+ }
278
+ }}
279
+ />
280
280
  </TemplateProvider>
281
281
  );
282
282
  }
@@ -287,6 +287,126 @@ function App() {
287
287
  1. When editing text, type `{{` to open the variable suggestions dropdown. Select the variable you want to insert from the list.
288
288
  2. Via curly braces `{}` icon in top toolbar (if the variables are available for selected element).
289
289
 
290
+ ## Error Handling
291
+
292
+ The Courier Editor includes a comprehensive error handling system that automatically provides user-friendly notifications for various error types including API errors, network failures, validation issues, and file upload problems.
293
+
294
+ ### Custom Error Handling
295
+
296
+ 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
+
298
+ ```tsx
299
+ import { useTemplateActions } from '@trycourier/react-designer';
300
+
301
+ function CustomComponent() {
302
+ const { setTemplateError } = useTemplateActions();
303
+
304
+ const handleCustomAction = async () => {
305
+ try {
306
+ // Your custom logic here
307
+ await someApiCall();
308
+ } catch (error) {
309
+ // Simple string error (automatically converted)
310
+ setTemplateError("Something went wrong with your custom action");
311
+
312
+ // Or create a structured error with custom toast configuration
313
+ setTemplateError({
314
+ message: "Custom error message",
315
+ toastProps: {
316
+ duration: 6000,
317
+ action: {
318
+ label: "Retry",
319
+ onClick: () => handleCustomAction(),
320
+ },
321
+ description: "Additional context about the error"
322
+ }
323
+ });
324
+ }
325
+ };
326
+
327
+ return <button onClick={handleCustomAction}>Custom Action</button>;
328
+ }
329
+ ```
330
+
331
+ ### Error Object Structure
332
+
333
+ All errors use a simple, consistent structure:
334
+
335
+ ```tsx
336
+ // Error interface
337
+ interface TemplateError {
338
+ message: string; // The error message to display
339
+ toastProps?: ExternalToast; // Optional Sonner toast configuration
340
+ }
341
+
342
+ // Usage examples
343
+ setTemplateError({
344
+ message: "Upload failed",
345
+ toastProps: {
346
+ duration: 5000,
347
+ description: "File size too large",
348
+ action: {
349
+ label: "Try Again",
350
+ onClick: () => retryUpload(),
351
+ }
352
+ }
353
+ });
354
+
355
+ // Different error scenarios
356
+ setTemplateError({ message: "Authentication failed", toastProps: { duration: 6000 } });
357
+ setTemplateError({ message: "Network error", toastProps: { description: "Check connection" } });
358
+ setTemplateError({ message: "Validation error", toastProps: { duration: 5000 } });
359
+ ```
360
+
361
+ ### Error Boundary Protection
362
+
363
+ The editor includes an error boundary component to catch and handle React rendering errors gracefully.
364
+
365
+ ```tsx
366
+ import { ErrorBoundary, useTemplateActions } from '@trycourier/react-designer';
367
+
368
+ function App() {
369
+ const { setTemplateError } = useTemplateActions();
370
+
371
+ return (
372
+ <ErrorBoundary
373
+ onError={(error, errorInfo) => {
374
+ // Custom error logging
375
+ console.error('Editor error:', error);
376
+
377
+ // Optional: integrate with template error system
378
+ setTemplateError({
379
+ message: `Render error: ${error.message}`,
380
+ toastProps: {
381
+ duration: 6000,
382
+ action: {
383
+ label: "Reload",
384
+ onClick: () => window.location.reload(),
385
+ },
386
+ }
387
+ });
388
+ }}
389
+ fallback={<div>Something went wrong. Please refresh the page.</div>}
390
+ >
391
+ <TemplateProvider templateId="template-123" tenantId="tenant-123" token="jwt">
392
+ <TemplateEditor />
393
+ </TemplateProvider>
394
+ </ErrorBoundary>
395
+ );
396
+ }
397
+ ```
398
+
399
+ ### Clearing Errors
400
+
401
+ To programmatically clear the current error state:
402
+
403
+ ```tsx
404
+ const { setTemplateError } = useTemplateActions();
405
+
406
+ // Clear the error
407
+ setTemplateError(null);
408
+ ```
409
+
290
410
  ## Brand Editor
291
411
 
292
412
  The Brand Editor component allows you to customize and manage a tenant's brand settings directly within your application. This specialized editor provides an interface for modifying brand colors, logos, and other visual elements that will be applied to your templates.