import { getGroupInfoAction } from '@/app/groups/add-group-by-url-button-actions' import { saveRecentGroup } from '@/app/groups/recent-groups-helpers' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Popover, PopoverContent, PopoverTrigger, } from '@/components/ui/popover' import { useMediaQuery } from '@/lib/hooks' import { Loader2, Plus } from 'lucide-react' import { useTranslations } from 'next-intl' import { useState } from 'react' type Props = { reload: () => void } export function AddGroupByUrlButton({ reload }: Props) { const t = useTranslations('Groups.AddByURL') const isDesktop = useMediaQuery('(min-width: 640px)') const [url, setUrl] = useState('') const [error, setError] = useState(false) const [open, setOpen] = useState(false) const [pending, setPending] = useState(false) return (

{t('title')}

{t('description')}

{ event.preventDefault() const [, groupId] = url.match( new RegExp(`${window.location.origin}/groups/([^/]+)`), ) ?? [] setPending(true) const group = groupId ? await getGroupInfoAction(groupId) : null setPending(false) if (!group) { setError(true) } else { saveRecentGroup({ id: group.id, name: group.name }) reload() setUrl('') setOpen(false) } }} > { setUrl(event.target.value) setError(false) }} />
{error &&

{t('error')}

}
) }