Allow pay per invoice for bounty and job posts
This commit is contained in:
parent
f2f09b22c4
commit
d186e869e1
|
@ -8,6 +8,8 @@ import InputGroup from 'react-bootstrap/InputGroup'
|
||||||
import { bountySchema } from '../lib/validate'
|
import { bountySchema } from '../lib/validate'
|
||||||
import { SubSelectInitial } from './sub-select-form'
|
import { SubSelectInitial } from './sub-select-form'
|
||||||
import CancelButton from './cancel-button'
|
import CancelButton from './cancel-button'
|
||||||
|
import { useCallback } from 'react'
|
||||||
|
import { useAnonymous } from '../lib/anonymous'
|
||||||
|
|
||||||
export function BountyForm ({
|
export function BountyForm ({
|
||||||
item,
|
item,
|
||||||
|
@ -49,19 +51,10 @@ export function BountyForm ({
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
const submitUpsertBounty = useCallback(
|
||||||
<Form
|
// we ignore the invoice since only stackers can post bounties
|
||||||
initial={{
|
// the invoice is only for funding the wallet
|
||||||
title: item?.title || '',
|
async (_, boost, bounty, values, __) => {
|
||||||
text: item?.text || '',
|
|
||||||
bounty: item?.bounty || 1000,
|
|
||||||
...AdvPostInitial({ forward: item?.fwdUser?.name }),
|
|
||||||
...SubSelectInitial({ sub: item?.subName || sub?.name })
|
|
||||||
}}
|
|
||||||
schema={schema}
|
|
||||||
onSubmit={
|
|
||||||
handleSubmit ||
|
|
||||||
(async ({ boost, bounty, ...values }) => {
|
|
||||||
const { error } = await upsertBounty({
|
const { error } = await upsertBounty({
|
||||||
variables: {
|
variables: {
|
||||||
sub: item?.subName || sub?.name,
|
sub: item?.subName || sub?.name,
|
||||||
|
@ -81,6 +74,24 @@ export function BountyForm ({
|
||||||
const prefix = sub?.name ? `/~${sub.name}` : ''
|
const prefix = sub?.name ? `/~${sub.name}` : ''
|
||||||
await router.push(prefix + '/recent')
|
await router.push(prefix + '/recent')
|
||||||
}
|
}
|
||||||
|
}, [upsertBounty, router])
|
||||||
|
|
||||||
|
const anonUpsertBounty = useAnonymous(submitUpsertBounty, { requireSession: true })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form
|
||||||
|
initial={{
|
||||||
|
title: item?.title || '',
|
||||||
|
text: item?.text || '',
|
||||||
|
bounty: item?.bounty || 1000,
|
||||||
|
...AdvPostInitial({ forward: item?.fwdUser?.name }),
|
||||||
|
...SubSelectInitial({ sub: item?.subName || sub?.name })
|
||||||
|
}}
|
||||||
|
schema={schema}
|
||||||
|
onSubmit={
|
||||||
|
handleSubmit ||
|
||||||
|
(async ({ boost, bounty, cost, ...values }) => {
|
||||||
|
await anonUpsertBounty(cost, boost, bounty, values)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
storageKeyPrefix={item ? undefined : 'bounty'}
|
storageKeyPrefix={item ? undefined : 'bounty'}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import InputGroup from 'react-bootstrap/InputGroup'
|
||||||
import Image from 'react-bootstrap/Image'
|
import Image from 'react-bootstrap/Image'
|
||||||
import BootstrapForm from 'react-bootstrap/Form'
|
import BootstrapForm from 'react-bootstrap/Form'
|
||||||
import Alert from 'react-bootstrap/Alert'
|
import Alert from 'react-bootstrap/Alert'
|
||||||
import { useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import Info from './info'
|
import Info from './info'
|
||||||
import AccordianItem from './accordian-item'
|
import AccordianItem from './accordian-item'
|
||||||
import styles from '../styles/post.module.css'
|
import styles from '../styles/post.module.css'
|
||||||
|
@ -17,6 +17,7 @@ import Avatar from './avatar'
|
||||||
import ActionTooltip from './action-tooltip'
|
import ActionTooltip from './action-tooltip'
|
||||||
import { jobSchema } from '../lib/validate'
|
import { jobSchema } from '../lib/validate'
|
||||||
import CancelButton from './cancel-button'
|
import CancelButton from './cancel-button'
|
||||||
|
import { useAnonymous } from '../lib/anonymous'
|
||||||
|
|
||||||
function satsMin2Mo (minute) {
|
function satsMin2Mo (minute) {
|
||||||
return minute * 30 * 24 * 60
|
return minute * 30 * 24 * 60
|
||||||
|
@ -50,24 +51,10 @@ export default function JobForm ({ item, sub }) {
|
||||||
}`
|
}`
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
const submitUpsertJob = useCallback(
|
||||||
<>
|
// we ignore the invoice since only stackers can post bounties
|
||||||
<Form
|
// the invoice is only for funding the wallet
|
||||||
className='pb-5 pt-3'
|
async (_, maxBid, stop, start, values, __) => {
|
||||||
initial={{
|
|
||||||
title: item?.title || '',
|
|
||||||
company: item?.company || '',
|
|
||||||
location: item?.location || '',
|
|
||||||
remote: item?.remote || false,
|
|
||||||
text: item?.text || '',
|
|
||||||
url: item?.url || '',
|
|
||||||
maxBid: item?.maxBid || 0,
|
|
||||||
stop: false,
|
|
||||||
start: false
|
|
||||||
}}
|
|
||||||
schema={jobSchema}
|
|
||||||
storageKeyPrefix={storageKeyPrefix}
|
|
||||||
onSubmit={(async ({ maxBid, stop, start, ...values }) => {
|
|
||||||
let status
|
let status
|
||||||
if (start) {
|
if (start) {
|
||||||
status = 'ACTIVE'
|
status = 'ACTIVE'
|
||||||
|
@ -94,6 +81,29 @@ export default function JobForm ({ item, sub }) {
|
||||||
} else {
|
} else {
|
||||||
await router.push(`/~${sub.name}/recent`)
|
await router.push(`/~${sub.name}/recent`)
|
||||||
}
|
}
|
||||||
|
}, [upsertJob, router])
|
||||||
|
|
||||||
|
const anonUpsertJob = useAnonymous(submitUpsertJob, { requireSession: true })
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form
|
||||||
|
className='pb-5 pt-3'
|
||||||
|
initial={{
|
||||||
|
title: item?.title || '',
|
||||||
|
company: item?.company || '',
|
||||||
|
location: item?.location || '',
|
||||||
|
remote: item?.remote || false,
|
||||||
|
text: item?.text || '',
|
||||||
|
url: item?.url || '',
|
||||||
|
maxBid: item?.maxBid || 0,
|
||||||
|
stop: false,
|
||||||
|
start: false
|
||||||
|
}}
|
||||||
|
schema={jobSchema}
|
||||||
|
storageKeyPrefix={storageKeyPrefix}
|
||||||
|
onSubmit={(async ({ maxBid, stop, start, ...values }) => {
|
||||||
|
await anonUpsertJob(1000, maxBid, stop, start, values)
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
|
|
|
@ -100,7 +100,8 @@ export const isInsufficientFundsError = (error) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
forceInvoice: false
|
forceInvoice: false,
|
||||||
|
requireSession: false
|
||||||
}
|
}
|
||||||
export const useAnonymous = (fn, options = defaultOptions) => {
|
export const useAnonymous = (fn, options = defaultOptions) => {
|
||||||
const me = useMe()
|
const me = useMe()
|
||||||
|
@ -164,6 +165,9 @@ export const useAnonymous = (fn, options = defaultOptions) => {
|
||||||
}, [invoice?.id])
|
}, [invoice?.id])
|
||||||
|
|
||||||
const anonFn = useCallback(async (amount, ...args) => {
|
const anonFn = useCallback(async (amount, ...args) => {
|
||||||
|
if (!me && options.requireSession) {
|
||||||
|
throw new Error('you must be logged in')
|
||||||
|
}
|
||||||
if (me && !options.forceInvoice) {
|
if (me && !options.forceInvoice) {
|
||||||
try {
|
try {
|
||||||
return await fn(amount, ...args)
|
return await fn(amount, ...args)
|
||||||
|
|
Loading…
Reference in New Issue