import { useState } from 'react' import clsx from 'clsx' import { PencilIcon } from '@heroicons/react/outline' import { Group } from 'common/group' import { deleteGroup, 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 { uniq } from 'lodash' export function EditGroupButton(props: { group: Group; className?: string }) { const { group, className } = props const { memberIds } = group const router = useRouter() const [name, setName] = useState(group.name) const [about, setAbout] = useState(group.about ?? '') const [open, setOpen] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false) const [addMemberUsers, setAddMemberUsers] = useState([]) function updateOpen(newOpen: boolean) { setAddMemberUsers([]) setOpen(newOpen) } const saveDisabled = name === group.name && about === group.about && addMemberUsers.length === 0 const onSubmit = async () => { setIsSubmitting(true) await updateGroup(group, { name, about, memberIds: uniq([...memberIds, ...addMemberUsers.map((user) => user.id)]), }) setIsSubmitting(false) updateOpen(false) } return (
updateOpen(!open)} > Edit
setName(e.target.value || '')} />
setAbout(e.target.value || '')} />
) }