2022-01-25 23:02:02 +00:00
|
|
|
import clsx from 'clsx'
|
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { useState } from 'react'
|
2022-02-01 20:10:40 +00:00
|
|
|
import { PlusCircleIcon } from '@heroicons/react/solid'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { parseWordsAsTags } from 'common/util/parse'
|
2022-05-19 22:04:34 +00:00
|
|
|
import { createFold } from 'web/lib/firebase/fn-call'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { foldPath } from 'web/lib/firebase/folds'
|
|
|
|
import { toCamelCase } from 'common/util/format'
|
2022-03-17 07:56:25 +00:00
|
|
|
import { ConfirmationButton } from '../confirmation-button'
|
|
|
|
import { Col } from '../layout/col'
|
|
|
|
import { Spacer } from '../layout/spacer'
|
|
|
|
import { TagsList } from '../tags-list'
|
|
|
|
import { Title } from '../title'
|
2022-01-25 23:02:02 +00:00
|
|
|
|
|
|
|
export function CreateFoldButton() {
|
|
|
|
const [name, setName] = useState('')
|
|
|
|
const [about, setAbout] = useState('')
|
|
|
|
const [otherTags, setOtherTags] = useState('')
|
|
|
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
const tags = parseWordsAsTags(toCamelCase(name) + ' ' + otherTags)
|
|
|
|
|
|
|
|
const updateName = (newName: string) => {
|
|
|
|
setName(newName)
|
|
|
|
}
|
|
|
|
|
|
|
|
const onSubmit = async () => {
|
|
|
|
setIsSubmitting(true)
|
|
|
|
|
|
|
|
const result = await createFold({
|
|
|
|
name,
|
|
|
|
tags,
|
|
|
|
about,
|
|
|
|
}).then((r) => r.data || {})
|
|
|
|
|
|
|
|
if (result.fold) {
|
|
|
|
await router.push(foldPath(result.fold)).catch((e) => {
|
|
|
|
console.log(e)
|
|
|
|
setIsSubmitting(false)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
console.log(result.status, result.message)
|
|
|
|
setIsSubmitting(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfirmationButton
|
|
|
|
id="create-fold"
|
2022-03-31 08:38:57 +00:00
|
|
|
openModalBtn={{
|
2022-02-01 20:10:40 +00:00
|
|
|
label: 'New',
|
2022-02-11 18:40:22 +00:00
|
|
|
icon: <PlusCircleIcon className="mr-2 h-5 w-5" />,
|
2022-01-25 23:02:02 +00:00
|
|
|
className: clsx(
|
|
|
|
isSubmitting ? 'loading btn-disabled' : 'btn-primary',
|
|
|
|
'btn-sm'
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
submitBtn={{
|
|
|
|
label: 'Create',
|
2022-01-27 18:55:16 +00:00
|
|
|
className: clsx(name ? 'btn-primary' : 'btn-disabled'),
|
2022-01-25 23:02:02 +00:00
|
|
|
}}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
>
|
2022-02-01 18:12:55 +00:00
|
|
|
<Title className="!mt-0" text="Create a community" />
|
2022-01-25 23:02:02 +00:00
|
|
|
|
2022-02-11 18:40:22 +00:00
|
|
|
<Col className="gap-1 text-gray-500">
|
2022-01-27 07:10:28 +00:00
|
|
|
<div>
|
2022-02-01 18:12:55 +00:00
|
|
|
Markets are included in a community if they match one or more tags.
|
2022-01-27 07:10:28 +00:00
|
|
|
</div>
|
2022-01-25 23:02:02 +00:00
|
|
|
</Col>
|
|
|
|
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div className="form-control w-full">
|
|
|
|
<label className="label">
|
2022-02-01 18:12:55 +00:00
|
|
|
<span className="mb-1">Community name</span>
|
2022-01-25 23:02:02 +00:00
|
|
|
</label>
|
|
|
|
|
|
|
|
<input
|
2022-02-01 18:12:55 +00:00
|
|
|
placeholder="Name"
|
2022-01-25 23:02:02 +00:00
|
|
|
className="input input-bordered resize-none"
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={name}
|
2022-01-26 23:43:28 +00:00
|
|
|
maxLength={140}
|
2022-01-25 23:02:02 +00:00
|
|
|
onChange={(e) => updateName(e.target.value || '')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
|
|
|
<div className="form-control w-full">
|
|
|
|
<label className="label">
|
|
|
|
<span className="mb-1">About</span>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<input
|
2022-01-27 18:55:16 +00:00
|
|
|
placeholder="Short description (140 characters max, optional)"
|
2022-01-25 23:02:02 +00:00
|
|
|
className="input input-bordered resize-none"
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={about}
|
|
|
|
maxLength={140}
|
|
|
|
onChange={(e) => setAbout(e.target.value || '')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
|
|
|
<label className="label">
|
|
|
|
<span className="mb-1">Primary tag</span>
|
|
|
|
</label>
|
2022-02-01 21:03:06 +00:00
|
|
|
<TagsList noLink noLabel tags={[`#${toCamelCase(name)}`]} />
|
2022-01-25 23:02:02 +00:00
|
|
|
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
|
|
|
<div className="form-control w-full">
|
|
|
|
<label className="label">
|
|
|
|
<span className="mb-1">Additional tags</span>
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<input
|
|
|
|
placeholder="Politics, Economics, Rationality (Optional)"
|
|
|
|
className="input input-bordered resize-none"
|
|
|
|
disabled={isSubmitting}
|
|
|
|
value={otherTags}
|
|
|
|
onChange={(e) => setOtherTags(e.target.value || '')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
|
|
|
<TagsList
|
|
|
|
tags={parseWordsAsTags(otherTags).map((tag) => `#${tag}`)}
|
|
|
|
noLink
|
2022-02-01 21:03:06 +00:00
|
|
|
noLabel
|
2022-01-25 23:02:02 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</ConfirmationButton>
|
|
|
|
)
|
|
|
|
}
|