import { useState } from 'react' import clsx from 'clsx' import { PencilIcon } from '@heroicons/react/outline' import { Group } from 'common/group' import { deleteGroup, joinGroup, updateGroup } from 'web/lib/firebase/groups' import { Spacer } from '../layout/spacer' import { useRouter } from 'next/router' import { Modal } from 'web/components/layout/modal' import { FilterSelectUsers } from 'web/components/filter-select-users' import { User } from 'common/user' import { useMemberIds } from 'web/hooks/use-group' import { Input } from '../input' import { Button } from '../button' export function EditGroupButton(props: { group: Group; className?: string }) { const { group, className } = props const router = useRouter() const [name, setName] = useState(group.name) const [open, setOpen] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false) const [addMemberUsers, setAddMemberUsers] = useState([]) const memberIds = useMemberIds(group.id) function updateOpen(newOpen: boolean) { setAddMemberUsers([]) setOpen(newOpen) } const saveDisabled = name === group.name && addMemberUsers.length === 0 const onSubmit = async () => { setIsSubmitting(true) await Promise.all(addMemberUsers.map((user) => joinGroup(group, user.id))) await updateGroup(group, { name }) setIsSubmitting(false) updateOpen(false) } return (
setName(e.target.value || '')} />
) }