2024-09-19 18:13:14 +00:00
import { Checkbox , Form , Input , MarkdownInput , SubmitButton } from './form'
2023-07-24 18:35:05 +00:00
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'
import Image from 'react-bootstrap/Image'
2024-07-01 17:02:29 +00:00
import { useEffect , useState } from 'react'
2022-04-18 16:08:58 +00:00
import Info from './info'
2024-03-20 00:37:31 +00:00
import styles from '@/styles/post.module.css'
2024-07-01 17:02:29 +00:00
import { useLazyQuery , gql } from '@apollo/client'
2022-07-21 22:55:05 +00:00
import Avatar from './avatar'
2024-03-20 00:37:31 +00:00
import { jobSchema } from '@/lib/validate'
2024-09-19 18:13:14 +00:00
import { BOOST _MIN , BOOST _MULT , MAX _TITLE _LENGTH , MEDIA _URL } from '@/lib/constants'
2024-07-01 17:02:29 +00:00
import { UPSERT _JOB } from '@/fragments/paidAction'
import useItemSubmit from './use-item-submit'
2024-09-19 18:13:14 +00:00
import { BoostInput } from './adv-post-form'
import { numWithUnits , giveOrdinalSuffix } from '@/lib/format'
import useDebounceCallback from './use-debounce-callback'
import FeeButton from './fee-button'
import CancelButton from './cancel-button'
2022-02-17 17:23:43 +00:00
// need to recent list items
export default function JobForm ( { item , sub } ) {
const storageKeyPrefix = item ? undefined : ` ${ sub . name } -job `
2022-07-21 22:55:05 +00:00
const [ logoId , setLogoId ] = useState ( item ? . uploadId )
2022-02-17 17:23:43 +00:00
2024-09-19 18:13:14 +00:00
const [ getAuctionPosition , { data } ] = useLazyQuery ( gql `
query AuctionPosition ( $id : ID , $boost : Int ) {
auctionPosition ( sub : "${item?.subName || sub?.name}" , id : $id , boost : $boost )
} ` ,
{ fetchPolicy : 'cache-and-network' } )
const getPositionDebounce = useDebounceCallback ( ( ... args ) => getAuctionPosition ( ... args ) , 1000 , [ getAuctionPosition ] )
useEffect ( ( ) => {
if ( item ? . boost ) {
getPositionDebounce ( { variables : { boost : item . boost , id : item . id } } )
}
} , [ item ? . boost ] )
2024-07-01 17:02:29 +00:00
const extraValues = logoId ? { logo : Number ( logoId ) } : { }
const onSubmit = useItemSubmit ( UPSERT _JOB , { item , sub , extraValues } )
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
2022-02-17 17:23:43 +00:00
return (
< >
< Form
2023-05-11 00:26:07 +00:00
className = 'pb-5 pt-3'
2022-02-17 17:23:43 +00:00
initial = { {
title : item ? . title || '' ,
2022-03-07 21:50:13 +00:00
company : item ? . company || '' ,
location : item ? . location || '' ,
remote : item ? . remote || false ,
2024-09-19 18:13:14 +00:00
boost : item ? . boost || '' ,
2022-02-17 17:23:43 +00:00
text : item ? . text || '' ,
url : item ? . url || '' ,
2022-02-26 16:41:30 +00:00
stop : false ,
start : false
2022-02-17 17:23:43 +00:00
} }
2024-09-19 18:13:14 +00:00
schema = { jobSchema ( { existingBoost : item ? . boost } ) }
2022-02-17 17:23:43 +00:00
storageKeyPrefix = { storageKeyPrefix }
2024-05-28 17:18:54 +00:00
requireSession
2023-08-31 02:48:49 +00:00
onSubmit = { onSubmit }
2022-02-17 17:23:43 +00:00
>
2022-07-21 22:55:05 +00:00
< div className = 'form-group' >
< label className = 'form-label' > logo < / l a b e l >
< div className = 'position-relative' style = { { width : 'fit-content' } } >
< Image
2024-03-13 14:04:09 +00:00
src = { logoId ? ` ${ MEDIA _URL } / ${ logoId } ` : '/jobs-default.png' } width = '135' height = '135' roundedCircle
2022-07-21 22:55:05 +00:00
/ >
< Avatar onSuccess = { setLogoId } / >
< / d i v >
< / d i v >
2022-02-17 17:23:43 +00:00
< Input
2022-03-07 21:50:13 +00:00
label = 'job title'
2022-02-17 17:23:43 +00:00
name = 'title'
required
autoFocus
2022-08-25 18:46:07 +00:00
clear
2023-09-12 00:20:44 +00:00
maxLength = { MAX _TITLE _LENGTH }
2022-02-17 17:23:43 +00:00
/ >
2022-03-07 21:50:13 +00:00
< Input
label = 'company'
name = 'company'
required
2022-08-25 18:46:07 +00:00
clear
2022-03-07 21:50:13 +00:00
/ >
2023-07-24 18:35:05 +00:00
< Row className = 'me-0' >
2022-03-07 21:50:13 +00:00
< Col >
< Input
label = 'location'
name = 'location'
2022-08-25 18:46:07 +00:00
clear
2022-03-07 21:50:13 +00:00
/ >
< / C o l >
2023-07-27 00:18:42 +00:00
< Col className = 'd-flex ps-0' xs = 'auto' >
< Checkbox
label = { < div className = 'fw-bold' > remote < / d i v > } n a m e = ' r e m o t e ' h i d d e n L a b e l
groupClassName = { styles . inlineCheckGroup }
/ >
< / C o l >
2023-07-24 18:35:05 +00:00
< / R o w >
2022-02-17 17:23:43 +00:00
< MarkdownInput
2022-07-13 23:00:48 +00:00
topLevel
2022-02-17 17:23:43 +00:00
label = 'description'
name = 'text'
minRows = { 6 }
required
/ >
< Input
2023-07-24 18:35:05 +00:00
label = { < > how to apply < small className = 'text-muted ms-2' > url or email address < /small></ > }
2022-02-17 17:23:43 +00:00
name = 'url'
required
2022-08-25 18:46:07 +00:00
clear
2022-02-17 17:23:43 +00:00
/ >
2024-09-19 18:13:14 +00:00
< BoostInput
label = {
< div className = 'd-flex align-items-center' > boost
< Info >
< ol className = 'line-height-md' >
< li > Boost ranks jobs higher based on the amount < / l i >
< li > The minimum boost is { numWithUnits ( BOOST _MIN , { abbreviate : false } ) } < / l i >
< li > Boost must be divisible by { numWithUnits ( BOOST _MULT , { abbreviate : false } ) } < / l i >
< li > 100 % of boost goes to the territory founder and top stackers as rewards < / l i >
< / o l >
< / I n f o >
< / d i v >
}
hint = { < span className = 'text-muted' > { data ? . auctionPosition ? ` your job will rank ${ giveOrdinalSuffix ( data . auctionPosition ) } ` : 'higher boost ranks your job higher' } < / s p a n > }
onChange = { ( _ , e ) => getPositionDebounce ( { variables : { boost : Number ( e . target . value ) , id : item ? . id } } ) }
/ >
< JobButtonBar itemId = { item ? . id } / >
2022-02-17 17:23:43 +00:00
< / F o r m >
< / >
)
}
2022-02-26 16:41:30 +00:00
2024-09-19 18:13:14 +00:00
export function JobButtonBar ( {
itemId , disable , className , children , handleStop , onCancel , hasCancel = true ,
createText = 'post' , editText = 'save' , stopText = 'remove'
} ) {
2022-09-29 20:42:33 +00:00
return (
2024-09-19 18:13:14 +00:00
< div className = { ` mt-3 ${ className } ` } >
< div className = 'd-flex justify-content-between' >
{ itemId &&
< SubmitButton valueName = 'status' value = 'STOPPED' variant = 'grey-medium' > { stopText } < / S u b m i t B u t t o n > }
{ children }
< div className = 'd-flex align-items-center ms-auto' >
{ hasCancel && < CancelButton onClick = { onCancel } / > }
< FeeButton
text = { itemId ? editText : createText }
variant = 'secondary'
disabled = { disable }
2022-02-28 20:09:21 +00:00
/ >
2024-09-19 18:13:14 +00:00
< / d i v >
2022-09-29 20:42:33 +00:00
< / d i v >
2022-02-26 16:41:30 +00:00
< / d i v >
)
}