|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { Chip, ChipTag, toast } from '@sim/emcn' |
| 4 | +import { Duplicate, RefreshCw } from '@sim/emcn/icons' |
| 5 | +import { SettingsPanel } from '@/components/settings/settings-panel' |
| 6 | +import type { OrganizationNetwork } from '@/lib/api/contracts/organization-network' |
| 7 | +import { SettingsEmptyState } from '@/app/workspace/[workspaceId]/settings/components/settings-empty-state' |
| 8 | +import { SettingsSection } from '@/app/workspace/[workspaceId]/settings/components/settings-section/settings-section' |
| 9 | +import { useOrganizationNetwork } from '@/hooks/queries/organization-network' |
| 10 | + |
| 11 | +interface OrganizationNetworkSettingsProps { |
| 12 | + organizationId: string |
| 13 | +} |
| 14 | + |
| 15 | +const MODE_LABELS = { |
| 16 | + direct: 'Default routing', |
| 17 | + gateway: 'Gateway configured', |
| 18 | + blocked: 'Routing paused', |
| 19 | + unavailable: 'Status unavailable', |
| 20 | +} as const |
| 21 | + |
| 22 | +interface NetworkDetailsProps { |
| 23 | + data: OrganizationNetwork |
| 24 | +} |
| 25 | + |
| 26 | +function NetworkDetails({ data }: NetworkDetailsProps) { |
| 27 | + if (data.mode === 'direct') { |
| 28 | + return ( |
| 29 | + <p className='text-[var(--text-muted)] text-sm'> |
| 30 | + This organization uses the deployment’s default outbound network. Contact your platform |
| 31 | + administrator to arrange dedicated outbound IPs. |
| 32 | + </p> |
| 33 | + ) |
| 34 | + } |
| 35 | + if (data.mode === 'blocked' || data.mode === 'unavailable') { |
| 36 | + return ( |
| 37 | + <p role='status' className='text-[var(--text-muted)] text-sm'> |
| 38 | + {data.mode === 'blocked' |
| 39 | + ? 'Outbound routing has been paused by your platform administrator.' |
| 40 | + : 'Routing configuration could not be verified. Contact your platform administrator.'}{' '} |
| 41 | + Required gateway requests do not fall back to the default network. |
| 42 | + </p> |
| 43 | + ) |
| 44 | + } |
| 45 | + const { publicIps } = data |
| 46 | + async function copyAllowlist() { |
| 47 | + try { |
| 48 | + await navigator.clipboard.writeText(publicIps.map((ip) => `${ip}/32`).join('\n')) |
| 49 | + toast.success('IP allowlist copied') |
| 50 | + } catch { |
| 51 | + toast.error('Could not copy the IPs. Select and copy them below.') |
| 52 | + } |
| 53 | + } |
| 54 | + return ( |
| 55 | + <> |
| 56 | + <SettingsSection |
| 57 | + label='Outbound IP addresses' |
| 58 | + action={ |
| 59 | + publicIps.length > 0 ? ( |
| 60 | + <Chip leftIcon={Duplicate} onClick={copyAllowlist}> |
| 61 | + Copy allowlist |
| 62 | + </Chip> |
| 63 | + ) : undefined |
| 64 | + } |
| 65 | + > |
| 66 | + <div className='flex flex-col gap-3'> |
| 67 | + {data.publicIps.length > 0 ? ( |
| 68 | + <ul className='flex flex-col gap-2'> |
| 69 | + {data.publicIps.map((ip) => ( |
| 70 | + <li key={ip} className='font-mono text-[var(--text-body)] text-sm'> |
| 71 | + {ip}/32 |
| 72 | + </li> |
| 73 | + ))} |
| 74 | + </ul> |
| 75 | + ) : ( |
| 76 | + <p className='text-[var(--text-muted)] text-sm'> |
| 77 | + Your platform administrator has not published the gateway’s outbound IPs yet. |
| 78 | + </p> |
| 79 | + )} |
| 80 | + {data.region && <p className='text-[var(--text-muted)] text-sm'>Region: {data.region}</p>} |
| 81 | + <p className='text-[var(--text-muted)] text-sm'> |
| 82 | + Allow every listed address on destination firewalls. These are configured addresses; |
| 83 | + verify connectivity with an integration before relying on the allowlist. |
| 84 | + </p> |
| 85 | + </div> |
| 86 | + </SettingsSection> |
| 87 | + <SettingsSection label='Traffic coverage'> |
| 88 | + <p className='text-[var(--text-muted)] text-sm'> |
| 89 | + Supported HTTPS integration requests use this gateway from Sim and its background jobs. |
| 90 | + Browser traffic and traffic originating inside external services are outside this routing |
| 91 | + policy. Some transports, including remote sandboxes and database connections, are not |
| 92 | + supported when a gateway is required. |
| 93 | + </p> |
| 94 | + </SettingsSection> |
| 95 | + </> |
| 96 | + ) |
| 97 | +} |
| 98 | + |
| 99 | +export function OrganizationNetworkSettings({ organizationId }: OrganizationNetworkSettingsProps) { |
| 100 | + const { data, error, isPending, isFetching, refetch } = useOrganizationNetwork(organizationId) |
| 101 | + return ( |
| 102 | + <SettingsPanel |
| 103 | + actions={[ |
| 104 | + { |
| 105 | + id: 'refresh', |
| 106 | + text: 'Refresh', |
| 107 | + icon: RefreshCw, |
| 108 | + disabled: isFetching, |
| 109 | + onSelect: () => void refetch(), |
| 110 | + }, |
| 111 | + ]} |
| 112 | + > |
| 113 | + <div className='flex flex-col gap-7'> |
| 114 | + {isPending ? ( |
| 115 | + <SettingsEmptyState variant='inline'> |
| 116 | + <span role='status'>Loading network settings…</span> |
| 117 | + </SettingsEmptyState> |
| 118 | + ) : error ? ( |
| 119 | + <SettingsEmptyState variant='inline' tone='error'> |
| 120 | + <span role='alert'>{error.message}</span> |
| 121 | + </SettingsEmptyState> |
| 122 | + ) : data ? ( |
| 123 | + <> |
| 124 | + <div> |
| 125 | + <ChipTag>{MODE_LABELS[data.mode]}</ChipTag> |
| 126 | + </div> |
| 127 | + <NetworkDetails data={data} /> |
| 128 | + </> |
| 129 | + ) : null} |
| 130 | + </div> |
| 131 | + </SettingsPanel> |
| 132 | + ) |
| 133 | +} |
0 commit comments