refine territory details on post form
This commit is contained in:
parent
f8cbd43be7
commit
9a9e81b109
@ -29,6 +29,7 @@ import { AWS_S3_URL_REGEXP } from '../lib/constants'
|
|||||||
import { whenRange } from '../lib/time'
|
import { whenRange } from '../lib/time'
|
||||||
import { useFeeButton } from './fee-button'
|
import { useFeeButton } from './fee-button'
|
||||||
import Thumb from '../svgs/thumb-up-fill.svg'
|
import Thumb from '../svgs/thumb-up-fill.svg'
|
||||||
|
import Info from './info'
|
||||||
|
|
||||||
export function SubmitButton ({
|
export function SubmitButton ({
|
||||||
children, variant, value, onClick, disabled, nonDisabledText, ...props
|
children, variant, value, onClick, disabled, nonDisabledText, ...props
|
||||||
@ -825,7 +826,7 @@ export function Form ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Select ({ label, items, groupClassName, onChange, noForm, overrideValue, hint, ...props }) {
|
export function Select ({ label, items, info, groupClassName, onChange, noForm, overrideValue, hint, ...props }) {
|
||||||
const [field, meta, helpers] = noForm ? [{}, {}, {}] : useField(props)
|
const [field, meta, helpers] = noForm ? [{}, {}, {}] : useField(props)
|
||||||
const formik = noForm ? null : useFormikContext()
|
const formik = noForm ? null : useFormikContext()
|
||||||
const invalid = meta.touched && meta.error
|
const invalid = meta.touched && meta.error
|
||||||
@ -838,31 +839,34 @@ export function Select ({ label, items, groupClassName, onChange, noForm, overri
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<FormGroup label={label} className={groupClassName}>
|
<FormGroup label={label} className={groupClassName}>
|
||||||
<BootstrapForm.Select
|
<span className='d-flex align-items-center'>
|
||||||
{...field} {...props}
|
<BootstrapForm.Select
|
||||||
onChange={(e) => {
|
{...field} {...props}
|
||||||
if (field?.onChange) {
|
onChange={(e) => {
|
||||||
field.onChange(e)
|
if (field?.onChange) {
|
||||||
}
|
field.onChange(e)
|
||||||
|
}
|
||||||
|
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
onChange(formik, e)
|
onChange(formik, e)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
isInvalid={invalid}
|
isInvalid={invalid}
|
||||||
>
|
>
|
||||||
{items.map(item => {
|
{items.map(item => {
|
||||||
if (item && typeof item === 'object') {
|
if (item && typeof item === 'object') {
|
||||||
return (
|
return (
|
||||||
<optgroup key={item.label} label={item.label}>
|
<optgroup key={item.label} label={item.label}>
|
||||||
{item.items.map(item => <option key={item}>{item}</option>)}
|
{item.items.map(item => <option key={item}>{item}</option>)}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return <option key={item}>{item}</option>
|
return <option key={item}>{item}</option>
|
||||||
}
|
}
|
||||||
})}
|
})}
|
||||||
</BootstrapForm.Select>
|
</BootstrapForm.Select>
|
||||||
|
{info && <Info>{info}</Info>}
|
||||||
|
</span>
|
||||||
<BootstrapForm.Control.Feedback type='invalid'>
|
<BootstrapForm.Control.Feedback type='invalid'>
|
||||||
{meta.touched && meta.error}
|
{meta.touched && meta.error}
|
||||||
</BootstrapForm.Control.Feedback>
|
</BootstrapForm.Control.Feedback>
|
||||||
|
@ -9,12 +9,12 @@ import { DiscussionForm } from './discussion-form'
|
|||||||
import { LinkForm } from './link-form'
|
import { LinkForm } from './link-form'
|
||||||
import { PollForm } from './poll-form'
|
import { PollForm } from './poll-form'
|
||||||
import { BountyForm } from './bounty-form'
|
import { BountyForm } from './bounty-form'
|
||||||
import SubSelect, { SubInfo } from './sub-select'
|
import SubSelect from './sub-select'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
import FeeButton, { FeeButtonProvider, postCommentBaseLineItems, postCommentUseRemoteLineItems } from './fee-button'
|
import FeeButton, { FeeButtonProvider, postCommentBaseLineItems, postCommentUseRemoteLineItems } from './fee-button'
|
||||||
import Delete from './delete'
|
import Delete from './delete'
|
||||||
import CancelButton from './cancel-button'
|
import CancelButton from './cancel-button'
|
||||||
import { TerritoryDetails } from './territory-header'
|
import { TerritoryInfo } from './territory-header'
|
||||||
|
|
||||||
export function PostForm ({ type, sub, children }) {
|
export function PostForm ({ type, sub, children }) {
|
||||||
const me = useMe()
|
const me = useMe()
|
||||||
@ -99,15 +99,20 @@ export function PostForm ({ type, sub, children }) {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='position-relative d-flex flex-column align-items-center'>
|
<div className='position-relative d-flex flex-column align-items-start'>
|
||||||
{errorMessage &&
|
{errorMessage &&
|
||||||
<Alert className='position-absolute' style={{ top: '-6rem' }} variant='danger' onClose={() => setErrorMessage(undefined)} dismissible>
|
<Alert className='position-absolute' style={{ top: '-6rem' }} variant='danger' onClose={() => setErrorMessage(undefined)} dismissible>
|
||||||
{errorMessage}
|
{errorMessage}
|
||||||
</Alert>}
|
</Alert>}
|
||||||
<SubSelect prependSubs={['pick territory']} className='w-auto d-flex' noForm sub={sub?.name} hint={sub?.moderated && 'this territory is moderated'} />
|
<SubSelect
|
||||||
<div className='mb-3 w-100'>
|
prependSubs={['pick territory']}
|
||||||
{sub && <TerritoryDetails sub={sub} />}
|
className='w-auto d-flex'
|
||||||
</div>
|
noForm
|
||||||
|
large
|
||||||
|
sub={sub?.name}
|
||||||
|
info={sub && <TerritoryInfo sub={sub} />}
|
||||||
|
hint={sub?.moderated && 'this territory is moderated'}
|
||||||
|
/>
|
||||||
<div>
|
<div>
|
||||||
{postButtons}
|
{postButtons}
|
||||||
</div>
|
</div>
|
||||||
@ -169,12 +174,9 @@ export default function Post ({ sub }) {
|
|||||||
prependSubs={sub?.name ? undefined : ['pick territory']}
|
prependSubs={sub?.name ? undefined : ['pick territory']}
|
||||||
filterSubs={s => s.postTypes?.includes(type.toUpperCase())}
|
filterSubs={s => s.postTypes?.includes(type.toUpperCase())}
|
||||||
className='w-auto d-flex'
|
className='w-auto d-flex'
|
||||||
label={
|
large
|
||||||
<span className='d-flex align-items-center'>
|
label='territory'
|
||||||
territory
|
info={sub && <TerritoryInfo sub={sub} />}
|
||||||
<SubInfo />
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
hint={sub?.moderated && 'this territory is moderated'}
|
hint={sub?.moderated && 'this territory is moderated'}
|
||||||
/>}
|
/>}
|
||||||
</PostForm>
|
</PostForm>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { Select } from './form'
|
import { Select } from './form'
|
||||||
import Info from './info'
|
|
||||||
import { SSR } from '../lib/constants'
|
import { SSR } from '../lib/constants'
|
||||||
import { SUBS } from '../fragments/subs'
|
import { SUBS } from '../fragments/subs'
|
||||||
import { useQuery } from '@apollo/client'
|
import { useQuery } from '@apollo/client'
|
||||||
@ -43,23 +42,7 @@ export function useSubs ({ prependSubs = [], sub, filterSubs = () => true, appen
|
|||||||
return subs
|
return subs
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SubInfo = () => (
|
export default function SubSelect ({ prependSubs, sub, onChange, large, appendSubs, filterSubs, className, ...props }) {
|
||||||
<Info>
|
|
||||||
<div>
|
|
||||||
<div className='fw-bold'>The territory your post will go in ...</div>
|
|
||||||
<ul>
|
|
||||||
<li>If it's bitcoin related, put it in the bitcoin territory.</li>
|
|
||||||
<li>If it's nostr related, put it in the nostr territory.</li>
|
|
||||||
<li>If it's tech related, put it in the tech territory.</li>
|
|
||||||
<li>If it's stacker news related, put it in the meta territory.</li>
|
|
||||||
<li>If it's a job, put it in the jobs territory.</li>
|
|
||||||
<li>etc...</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</Info>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default function SubSelect ({ prependSubs, sub, onChange, appendSubs, filterSubs, className, ...props }) {
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const subs = useSubs({ prependSubs, sub, filterSubs, appendSubs })
|
const subs = useSubs({ prependSubs, sub, filterSubs, appendSubs })
|
||||||
const valueProps = props.noForm
|
const valueProps = props.noForm
|
||||||
@ -118,7 +101,7 @@ export default function SubSelect ({ prependSubs, sub, onChange, appendSubs, fil
|
|||||||
size='sm'
|
size='sm'
|
||||||
{...valueProps}
|
{...valueProps}
|
||||||
{...props}
|
{...props}
|
||||||
className={`${className} ${styles.subSelect}`}
|
className={`${className} ${styles.subSelect} ${large ? '' : styles.subSelectSmall}`}
|
||||||
items={subs}
|
items={subs}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
.subSelect {
|
.subSelect {
|
||||||
max-width: 90px !important;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis !important;
|
text-overflow: ellipsis !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subSelectSmall {
|
||||||
|
max-width: 90px !important;
|
||||||
}
|
}
|
@ -22,6 +22,14 @@ export function TerritoryDetails ({ sub }) {
|
|||||||
</small>
|
</small>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
<TerritoryInfo sub={sub} />
|
||||||
|
</AccordianCard>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TerritoryInfo ({ sub }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
<div className='py-2'>
|
<div className='py-2'>
|
||||||
<Text>{sub.desc}</Text>
|
<Text>{sub.desc}</Text>
|
||||||
</div>
|
</div>
|
||||||
@ -38,7 +46,7 @@ export function TerritoryDetails ({ sub }) {
|
|||||||
</div>
|
</div>
|
||||||
<TerritoryBillingLine sub={sub} />
|
<TerritoryBillingLine sub={sub} />
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</AccordianCard>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user