import { Checkbox, Form, Input, MarkdownInput, SubmitButton } from './form' import TextareaAutosize from 'react-textarea-autosize' import { InputGroup, Modal } from 'react-bootstrap' import * as Yup from 'yup' import { useEffect, useState } from 'react' import Info from '../svgs/information-fill.svg' import AccordianItem from './accordian-item' import styles from '../styles/post.module.css' import { useLazyQuery, gql, useMutation } from '@apollo/client' import { useRouter } from 'next/router' import Link from 'next/link' Yup.addMethod(Yup.string, 'or', function (schemas, msg) { return this.test({ name: 'or', message: msg, test: value => { if (Array.isArray(schemas) && schemas.length > 1) { const resee = schemas.map(schema => schema.isValidSync(value)) return resee.some(res => res) } else { throw new TypeError('Schemas is not correct array schema') } }, exclusive: false }) }) function satsMo2Min (monthly) { return Number.parseFloat(monthly / 30 / 24 / 60).toFixed(2) } // need to recent list items export default function JobForm ({ item, sub }) { const storageKeyPrefix = item ? undefined : `${sub.name}-job` const router = useRouter() const [pull, setPull] = useState(satsMo2Min(item?.maxBid || sub.baseCost)) const [info, setInfo] = useState() const [getAuctionPosition, { data }] = useLazyQuery(gql` query AuctionPosition($id: ID, $bid: Int!) { auctionPosition(sub: "${sub.name}", id: $id, bid: $bid) }`, { fetchPolicy: 'network-only' }) const [upsertJob] = useMutation(gql` mutation upsertJob($id: ID, $title: String!, $text: String!, $url: String!, $maxBid: Int!, $status: String) { upsertJob(sub: "${sub.name}", id: $id title: $title, text: $text, url: $url, maxBid: $maxBid, status: $status) { id } }` ) const JobSchema = Yup.object({ title: Yup.string().required('required').trim(), text: Yup.string().required('required').trim(), url: Yup.string() .or([Yup.string().email(), Yup.string().url()], 'invalid url or email') .required('Required'), maxBid: Yup.number('must be number') .integer('must be integer').min(sub.baseCost, `must be at least ${sub.baseCost}`) .max(100000000, 'must be less than 100000000') .test('multiple', `must be a multiple of ${sub.deltaCost} sats`, (val) => val % sub.deltaCost === 0) }) const position = data?.auctionPosition useEffect(() => { const initialMaxBid = Number(item?.maxBid || localStorage.getItem(storageKeyPrefix + '-maxBid')) || sub.baseCost getAuctionPosition({ variables: { id: item?.id, bid: initialMaxBid } }) setPull(satsMo2Min(initialMaxBid)) }, []) return ( <> setInfo(false)} >
setInfo(false)}>X
  1. The higher your bid the higher your job will rank
  2. The minimum bid is {sub.baseCost} sats/mo
  3. Your sats/mo must be a multiple of {sub.deltaCost} sats
  4. You can increase or decrease your bid, and edit or stop your job at anytime
  5. Your job will be hidden if your wallet runs out of sats and can be unhidden by filling your wallet again
{ let status if (start) { status = 'ACTIVE' } else if (stop) { status = 'STOPPED' } const variables = { sub: sub.name, maxBid: Number(maxBid), status, ...values } if (item) { variables.id = item.id } const { error } = await upsertJob({ variables }) if (error) { throw new Error({ message: error.toString() }) } if (item) { router.push(`/items/${item.id}`) } else { router.push(`/~${sub.name}/recent`) } })} > how to apply url or email address} name='url' required /> bid setInfo(true)} /> } name='maxBid' onChange={async (formik, e) => { if (e.target.value >= sub.baseCost && e.target.value <= 100000000) { setPull(satsMo2Min(e.target.value)) getAuctionPosition({ variables: { id: item?.id, bid: Number(e.target.value) } }) } else { setPull(satsMo2Min(sub.baseCost)) } }} append={sats/month} hint={{pull} sats/min will be pulled from your wallet} />
This bid puts your job in position: {position}
{item && } {item ? 'save' : 'post'} ) } function StatusControl ({ item }) { let StatusComp if (item.status !== 'STOPPED') { StatusComp = () => { return ( <> I want to stop my job} headerColor='var(--danger)' body={ stop my job} name='stop' inline /> } /> ) } } else { StatusComp = () => { return ( I want to resume my job} headerColor='var(--success)' body={ resume my job} name='start' inline /> } /> ) } } return (
{item.status === 'NOSATS' &&
you have no sats! fund your wallet to resume your job
}
) }