PlatformWebhooksView.utils.ts 976 B

12345678910111213141516171819202122232425262728293031
  1. import type { WebhookDeliveryStatus } from './PlatformWebhooks.types'
  2. export const statusBadgeVariant: Record<
  3. WebhookDeliveryStatus,
  4. 'default' | 'success' | 'destructive'
  5. > = {
  6. pending: 'default',
  7. success: 'success',
  8. failure: 'destructive',
  9. skipped: 'default',
  10. }
  11. export const formatDate = (value: string) =>
  12. new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(
  13. new Date(value)
  14. )
  15. export const formatEvents = (eventTypes: string[]) =>
  16. eventTypes.includes('*') ? 'All events (*)' : eventTypes.join(', ')
  17. export const formatDeliveryStatus = (status: WebhookDeliveryStatus) =>
  18. `${status.charAt(0).toUpperCase()}${status.slice(1)}`
  19. export const responseCodeBadgeVariant = (
  20. responseCode?: number
  21. ): 'default' | 'success' | 'destructive' => {
  22. if (!responseCode) return 'default'
  23. if (responseCode >= 200 && responseCode < 300) return 'success'
  24. if (responseCode >= 400) return 'destructive'
  25. return 'default'
  26. }