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