stacker.news/components/adv-post-form.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-09-11 21:52:19 +00:00
import AccordianItem from './accordian-item'
import * as Yup from 'yup'
import { Input } from './form'
import { InputGroup } from 'react-bootstrap'
2022-03-09 19:44:50 +00:00
import { BOOST_MIN } from '../lib/constants'
2022-04-19 18:32:39 +00:00
import { NAME_QUERY } from '../fragments/users'
2021-09-11 21:52:19 +00:00
2022-04-19 18:32:39 +00:00
export function AdvPostSchema (client) {
return {
boost: Yup.number().typeError('must be a number')
2022-04-25 17:07:31 +00:00
.min(BOOST_MIN, `must be blank or at least ${BOOST_MIN}`).integer('must be whole'),
2022-04-19 18:32:39 +00:00
forward: Yup.string()
.test({
name: 'name',
test: async name => {
if (!name || !name.length) return true
const { data } = await client.query({ query: NAME_QUERY, variables: { name }, fetchPolicy: 'network-only' })
return !data.nameAvailable
},
message: 'user does not exist'
})
}
2021-09-11 21:52:19 +00:00
}
export const AdvPostInitial = {
2022-04-18 20:19:07 +00:00
boost: '',
forward: ''
2021-09-11 21:52:19 +00:00
}
export default function AdvPostForm () {
return (
<AccordianItem
2021-09-12 16:55:38 +00:00
header={<div style={{ fontWeight: 'bold', fontSize: '92%' }}>options</div>}
2021-09-11 21:52:19 +00:00
body={
2022-04-18 20:19:07 +00:00
<>
<Input
2022-04-25 17:07:31 +00:00
label={<>boost</>}
2022-04-18 20:19:07 +00:00
name='boost'
hint={<span className='text-muted'>ranks posts higher temporarily based on the amount</span>}
append={<InputGroup.Text className='text-monospace'>sats</InputGroup.Text>}
/>
<Input
2022-04-25 17:07:31 +00:00
label={<>forward sats to</>}
2022-04-18 20:19:07 +00:00
name='forward'
2022-04-19 18:32:39 +00:00
hint={<span className='text-muted'>100% of sats will be sent to this user</span>}
2022-04-18 20:19:07 +00:00
prepend=<InputGroup.Text>@</InputGroup.Text>
2022-04-19 18:32:39 +00:00
showValid
2022-04-18 20:19:07 +00:00
/>
</>
2021-09-11 21:52:19 +00:00
}
/>
)
}