3b3717d307
* Folds=>groups * Show groups on user profile * Allow group creation from /create * Refactoring to groups * Convert folds to groups * Add new add to group notification * Fix user profile tab bug * Add groups nav and tab for my groups * Remove bad profile pages * remove comments * Add group list dropdown to sidebar * remove unused * group cards ui * Messages=>Comments, v2, groupDetails * Discussion time * Cleaning up some code * Remove follow count * Fix pool scoring for cpmm * Fix imports * Simplify rules, add GroupUser collection * Fix group cards * Refactor * Refactor * Small fixes * Remove string * Add api error detail handling * Clear name field * Componentize * Spacing * Undo userpage memo * Member groups are already in my tab * Remove active contracts reference for now * Remove unused * Refactoring * Allow adding old questions to a group * Rename * Wording * Throw standard v2 APIError * Hide input for non-members, add about under title * Multiple names to & # more * Move comments firestore rules to appropriate subpaths * Group membership, pool=>volume * Cleanup, useEvent * Raise state to parent * Eliminate unused * Cleaning up * Clean code * Revert tags input deletion * Cleaning code * Stylling * Limit members to display * Array cleanup * Add categories back in * Private=>closed * Unused vars
141 lines
4.1 KiB
TypeScript
141 lines
4.1 KiB
TypeScript
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'
|
|
|
|
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<User[]>([])
|
|
|
|
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: [...memberIds, ...addMemberUsers.map((user) => user.id)],
|
|
})
|
|
|
|
setIsSubmitting(false)
|
|
updateOpen(false)
|
|
}
|
|
|
|
return (
|
|
<div className={clsx('flex p-1', className)}>
|
|
<div
|
|
className={clsx(
|
|
'btn-ghost cursor-pointer whitespace-nowrap rounded-full text-sm text-white'
|
|
)}
|
|
onClick={() => updateOpen(!open)}
|
|
>
|
|
<PencilIcon className="inline h-4 w-4" /> Edit
|
|
</div>
|
|
<Modal open={open} setOpen={updateOpen}>
|
|
<div className="h-full rounded-md bg-white p-8">
|
|
<div className="form-control w-full">
|
|
<label className="label">
|
|
<span className="mb-1">Group name</span>
|
|
</label>
|
|
|
|
<input
|
|
placeholder="Your group name"
|
|
className="input input-bordered resize-none"
|
|
disabled={isSubmitting}
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value || '')}
|
|
/>
|
|
</div>
|
|
|
|
<Spacer h={4} />
|
|
|
|
<div className="form-control w-full">
|
|
<label className="label">
|
|
<span className="mb-1">About</span>
|
|
</label>
|
|
|
|
<input
|
|
placeholder="Short description (140 characters max)"
|
|
className="input input-bordered resize-none"
|
|
disabled={isSubmitting}
|
|
value={about}
|
|
maxLength={140}
|
|
onChange={(e) => setAbout(e.target.value || '')}
|
|
/>
|
|
</div>
|
|
|
|
<Spacer h={4} />
|
|
|
|
<div className="form-control w-full">
|
|
<label className="label">
|
|
<span className="mb-0">Add members</span>
|
|
</label>
|
|
<FilterSelectUsers
|
|
setSelectedUsers={setAddMemberUsers}
|
|
selectedUsers={addMemberUsers}
|
|
ignoreUserIds={memberIds}
|
|
/>
|
|
</div>
|
|
|
|
<div className="modal-action">
|
|
<label
|
|
htmlFor="edit"
|
|
onClick={() => {
|
|
if (confirm('Are you sure you want to delete this group?')) {
|
|
deleteGroup(group)
|
|
updateOpen(false)
|
|
router.replace('/groups')
|
|
}
|
|
}}
|
|
className={clsx(
|
|
'btn btn-sm btn-outline mr-auto self-center hover:border-red-500 hover:bg-red-500'
|
|
)}
|
|
>
|
|
Delete
|
|
</label>
|
|
<label
|
|
htmlFor="edit"
|
|
className={'btn'}
|
|
onClick={() => updateOpen(false)}
|
|
>
|
|
Cancel
|
|
</label>
|
|
<label
|
|
className={clsx(
|
|
'btn',
|
|
saveDisabled ? 'btn-disabled' : 'btn-primary',
|
|
isSubmitting && 'loading'
|
|
)}
|
|
htmlFor="edit"
|
|
onClick={onSubmit}
|
|
>
|
|
Save
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
</div>
|
|
)
|
|
}
|