import React, { FormEventHandler, useState } from 'react'; import FocusTrap from 'focus-trap-react'; import { Dialog, Overlay, OverlayCenter, OverlayBackdrop, Header, config, Box, Text, IconButton, Icon, Icons, Button, Input, color, } from 'folds'; import { stopPropagation } from '../../utils/keyboard'; import { isRoomAlias, isRoomId } from '../../utils/matrix'; import { parseMatrixToRoom, parseMatrixToRoomEvent, testMatrixTo } from '../../plugins/matrix-to'; import { tryDecodeURIComponent } from '../../utils/dom'; type JoinAddressProps = { onOpen: (roomIdOrAlias: string, via?: string[], eventId?: string) => void; onCancel: () => void; }; export function JoinAddressPrompt({ onOpen, onCancel }: JoinAddressProps) { const [invalid, setInvalid] = useState(false); const handleSubmit: FormEventHandler = (evt) => { evt.preventDefault(); setInvalid(false); const target = evt.target as HTMLFormElement | undefined; const addressInput = target?.addressInput as HTMLInputElement | undefined; const address = addressInput?.value.trim(); if (!address) return; if (isRoomId(address) || isRoomAlias(address)) { onOpen(address); return; } if (testMatrixTo(address)) { const decodedAddress = tryDecodeURIComponent(address); const toRoom = parseMatrixToRoom(decodedAddress); if (toRoom) { onOpen(toRoom.roomIdOrAlias, toRoom.viaServers); return; } const toEvent = parseMatrixToRoomEvent(decodedAddress); if (toEvent) { onOpen(toEvent.roomIdOrAlias, toEvent.viaServers, toEvent.eventId); return; } } setInvalid(true); }; return ( }>
Join with Address
Enter public address to join the community. Addresses looks like:
  • #community:server
  • https://matrix.to/#/#community:server
  • https://matrix.to/#/!xYzAj?via=server
  • Address {invalid && ( Invalid Address )}
    ); }