add job company and location

This commit is contained in:
keyan 2022-03-07 15:50:13 -06:00
parent 1472de0f91
commit a627322220
10 changed files with 112 additions and 42 deletions

View File

@ -492,34 +492,27 @@ export default {
return await updateItem(parent, { id, data: { title, text } }, { me, models }) return await updateItem(parent, { id, data: { title, text } }, { me, models })
}, },
upsertJob: async (parent, { id, sub, title, text, url, maxBid, status }, { me, models }) => { upsertJob: async (parent, { id, sub, title, company, location, remote, text, url, maxBid, status }, { me, models }) => {
if (!me) { if (!me) {
throw new AuthenticationError('you must be logged in to create job') throw new AuthenticationError('you must be logged in to create job')
} }
if (!sub) {
throw new UserInputError('jobs must have a sub', { argumentName: 'sub' })
}
const fullSub = await models.sub.findUnique({ where: { name: sub } }) const fullSub = await models.sub.findUnique({ where: { name: sub } })
if (!fullSub) { if (!fullSub) {
throw new UserInputError('not a valid sub', { argumentName: 'sub' }) throw new UserInputError('not a valid sub', { argumentName: 'sub' })
} }
const params = { title, text, url }
for (const param in params) {
if (!params[param]) {
throw new UserInputError(`jobs must have ${param}`, { argumentName: param })
}
}
if (fullSub.baseCost > maxBid) { if (fullSub.baseCost > maxBid) {
throw new UserInputError(`bid must be at least ${fullSub.baseCost}`, { argumentName: 'maxBid' }) throw new UserInputError(`bid must be at least ${fullSub.baseCost}`, { argumentName: 'maxBid' })
} }
if (!location && !remote) {
throw new UserInputError('must specify location or remote', { argumentName: 'location' })
}
const checkSats = async () => { const checkSats = async () => {
// check if the user has the funds to run for the first minute // check if the user has the funds to run for the first minute
const minuteMsats = maxBid * 5 / 216 const minuteMsats = maxBid * 1000
const user = await models.user.findUnique({ where: { id: me.id } }) const user = await models.user.findUnique({ where: { id: me.id } })
if (user.msats < minuteMsats) { if (user.msats < minuteMsats) {
throw new UserInputError('insufficient funds') throw new UserInputError('insufficient funds')
@ -528,6 +521,9 @@ export default {
const data = { const data = {
title, title,
company,
location: location.toLowerCase() === 'remote' ? undefined : location,
remote,
text, text,
url, url,
maxBid, maxBid,
@ -878,6 +874,7 @@ function nestComments (flat, parentId) {
export const SELECT = export const SELECT =
`SELECT "Item".id, "Item".created_at as "createdAt", "Item".updated_at as "updatedAt", "Item".title, `SELECT "Item".id, "Item".created_at as "createdAt", "Item".updated_at as "updatedAt", "Item".title,
"Item".text, "Item".url, "Item"."userId", "Item"."parentId", "Item"."pinId", "Item"."maxBid", "Item".text, "Item".url, "Item"."userId", "Item"."parentId", "Item"."pinId", "Item"."maxBid",
"Item".company, "Item".location, "Item".remote,
"Item"."subName", "Item".status, ltree2text("Item"."path") AS "path"` "Item"."subName", "Item".status, ltree2text("Item"."path") AS "path"`
const LEFT_JOIN_SATS_SELECT = 'SELECT i.id, SUM(CASE WHEN "ItemAct".act = \'VOTE\' THEN "ItemAct".sats ELSE 0 END) as sats, SUM(CASE WHEN "ItemAct".act = \'BOOST\' THEN "ItemAct".sats ELSE 0 END) as boost' const LEFT_JOIN_SATS_SELECT = 'SELECT i.id, SUM(CASE WHEN "ItemAct".act = \'VOTE\' THEN "ItemAct".sats ELSE 0 END) as sats, SUM(CASE WHEN "ItemAct".act = \'BOOST\' THEN "ItemAct".sats ELSE 0 END) as boost'

View File

@ -25,7 +25,7 @@ export default gql`
updateDiscussion(id: ID!, title: String!, text: String): Item! updateDiscussion(id: ID!, title: String!, text: String): Item!
createComment(text: String!, parentId: ID!): Item! createComment(text: String!, parentId: ID!): Item!
updateComment(id: ID!, text: String!): Item! updateComment(id: ID!, text: String!): Item!
upsertJob(id: ID, sub: ID!, title: String!, text: String!, url: String!, maxBid: Int!, status: String): Item! upsertJob(id: ID, sub: ID!, title: String!, company: String!, location: String, remote: Boolean, text: String!, url: String!, maxBid: Int!, status: String): Item!
act(id: ID!, sats: Int): ItemActResult! act(id: ID!, sats: Int): ItemActResult!
} }
@ -66,6 +66,9 @@ export default gql`
position: Int position: Int
prior: Int prior: Int
maxBid: Int maxBid: Int
company: String
location: String
remote: Boolean
sub: Sub sub: Sub
status: String status: String
} }

View File

@ -201,12 +201,14 @@ export function Input ({ label, groupClassName, ...props }) {
) )
} }
export function Checkbox ({ children, label, extra, handleChange, inline, ...props }) { export function Checkbox ({ children, label, groupClassName, hiddenLabel, extra, handleChange, inline, ...props }) {
// React treats radios and checkbox inputs differently other input types, select, and textarea. // React treats radios and checkbox inputs differently other input types, select, and textarea.
// Formik does this too! When you specify `type` to useField(), it will // Formik does this too! When you specify `type` to useField(), it will
// return the correct bag of props for you // return the correct bag of props for you
const [field] = useField({ ...props, type: 'checkbox' }) const [field] = useField({ ...props, type: 'checkbox' })
return ( return (
<BootstrapForm.Group className={groupClassName}>
{hiddenLabel && <BootstrapForm.Label className='invisible'>{label}</BootstrapForm.Label>}
<BootstrapForm.Check <BootstrapForm.Check
custom custom
id={props.id || props.name} id={props.id || props.name}
@ -226,6 +228,7 @@ export function Checkbox ({ children, label, extra, handleChange, inline, ...pro
</div>} </div>}
</BootstrapForm.Check.Label> </BootstrapForm.Check.Label>
</BootstrapForm.Check> </BootstrapForm.Check>
</BootstrapForm.Group>
) )
} }

View File

@ -34,7 +34,21 @@ export function ItemJob ({ item, rank, children }) {
<div className={`${styles.main} flex-wrap d-inline`}> <div className={`${styles.main} flex-wrap d-inline`}>
<Link href={`/items/${item.id}`} passHref> <Link href={`/items/${item.id}`} passHref>
<a className={`${styles.title} text-reset mr-2`}> <a className={`${styles.title} text-reset mr-2`}>
{item.searchTitle ? <SearchTitle title={item.searchTitle} /> : item.title} {item.searchTitle
? <SearchTitle title={item.searchTitle} />
: (
<>{item.title}
{item.company &&
<>
<span> \ </span>
{item.company}
</>}
{(item.location || item.remote) &&
<>
<span> \ </span>
{`${item.location || ''}${item.location && item.remote ? ' or ' : ''}${item.remote ? 'Remote' : ''}`}
</>}
</>)}
</a> </a>
</Link> </Link>
{/* eslint-disable-next-line */} {/* eslint-disable-next-line */}

View File

@ -1,6 +1,6 @@
import { Checkbox, Form, Input, MarkdownInput, SubmitButton } from './form' import { Checkbox, Form, Input, MarkdownInput, SubmitButton } from './form'
import TextareaAutosize from 'react-textarea-autosize' import TextareaAutosize from 'react-textarea-autosize'
import { InputGroup, Modal } from 'react-bootstrap' import { InputGroup, Modal, Form as BForm, Col } from 'react-bootstrap'
import * as Yup from 'yup' import * as Yup from 'yup'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import Info from '../svgs/information-fill.svg' import Info from '../svgs/information-fill.svg'
@ -54,9 +54,10 @@ export default function JobForm ({ item, sub }) {
}`, }`,
{ fetchPolicy: 'network-only' }) { fetchPolicy: 'network-only' })
const [upsertJob] = useMutation(gql` const [upsertJob] = useMutation(gql`
mutation upsertJob($id: ID, $title: String!, $text: String!, mutation upsertJob($id: ID, $title: String!, $company: String!, $location: String,
$url: String!, $maxBid: Int!, $status: String) { $remote: Boolean, $text: String!, $url: String!, $maxBid: Int!, $status: String) {
upsertJob(sub: "${sub.name}", id: $id title: $title, text: $text, upsertJob(sub: "${sub.name}", id: $id, title: $title, company: $company,
location: $location, remote: $remote, text: $text,
url: $url, maxBid: $maxBid, status: $status) { url: $url, maxBid: $maxBid, status: $status) {
id id
} }
@ -65,12 +66,17 @@ export default function JobForm ({ item, sub }) {
const JobSchema = Yup.object({ const JobSchema = Yup.object({
title: Yup.string().required('required').trim(), title: Yup.string().required('required').trim(),
company: Yup.string().required('required').trim(),
text: Yup.string().required('required').trim(), text: Yup.string().required('required').trim(),
url: Yup.string() url: Yup.string()
.or([Yup.string().email(), Yup.string().url()], 'invalid url or email') .or([Yup.string().email(), Yup.string().url()], 'invalid url or email')
.required('Required'), .required('Required'),
maxBid: Yup.number('must be number') maxBid: Yup.number('must be number')
.integer('must be integer').min(sub.baseCost, `must be at least ${sub.baseCost}`) .integer('must be integer').min(sub.baseCost, `must be at least ${sub.baseCost}`),
location: Yup.string().when('remote', {
is: (value) => !value,
then: Yup.string().required('required').trim()
})
}) })
const position = data?.auctionPosition const position = data?.auctionPosition
@ -101,6 +107,9 @@ export default function JobForm ({ item, sub }) {
className='py-5' className='py-5'
initial={{ initial={{
title: item?.title || '', title: item?.title || '',
company: item?.company || '',
location: item?.location || '',
remote: item?.remote || false,
text: item?.text || '', text: item?.text || '',
url: item?.url || '', url: item?.url || '',
maxBid: item?.maxBid || sub.baseCost, maxBid: item?.maxBid || sub.baseCost,
@ -134,11 +143,28 @@ export default function JobForm ({ item, sub }) {
})} })}
> >
<Input <Input
label='title' label='job title'
name='title' name='title'
required required
autoFocus autoFocus
/> />
<Input
label='company'
name='company'
required
/>
<BForm.Row className='mr-0'>
<Col>
<Input
label='location'
name='location'
/>
</Col>
<Checkbox
label={<div className='font-weight-bold'>remote</div>} name='remote' hiddenLabel
groupClassName={styles.inlineCheckGroup}
/>
</BForm.Row>
<MarkdownInput <MarkdownInput
label='description' label='description'
name='text' name='text'

View File

@ -18,6 +18,9 @@ export const ITEM_FIELDS = gql`
meSats meSats
ncomments ncomments
maxBid maxBid
company
location
remote
sub { sub {
name name
baseCost baseCost

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Item" ADD COLUMN "company" TEXT;

View File

@ -115,6 +115,7 @@ model Item {
status Status @default(ACTIVE) status Status @default(ACTIVE)
statusUpdatedAt DateTime? statusUpdatedAt DateTime?
location String? location String?
company String?
latitude Float? latitude Float?
longitude Float? longitude Float?
remote Boolean? remote Boolean?

View File

@ -11,3 +11,10 @@
.close:hover { .close:hover {
opacity: 0.7; opacity: 0.7;
} }
.inlineCheckGroup {
margin-left: .5rem;
display: flex;
flex-direction: column;
justify-content: center;
}

View File

@ -19,6 +19,9 @@ const ITEM_SEARCH_FIELDS = gql`
} }
status status
maxBid maxBid
company
location
remote
upvotes upvotes
sats sats
boost boost
@ -28,13 +31,24 @@ const ITEM_SEARCH_FIELDS = gql`
async function _indexItem (item) { async function _indexItem (item) {
console.log('indexing item', item.id) console.log('indexing item', item.id)
// HACK: modify the title for jobs so that company/location are searchable
// and highlighted without further modification
const itemcp = { ...item }
if (item.company) {
itemcp.title += ` \\ ${item.company}`
}
if (item.location || item.remote) {
itemcp.title += ` \\ ${item.location || ''}${item.location && item.remote ? ' or ' : ''}${item.remote ? 'Remote' : ''}`
}
try { try {
await search.index({ await search.index({
id: item.id, id: item.id,
index: 'item', index: 'item',
version: new Date(item.updatedAt).getTime(), version: new Date(item.updatedAt).getTime(),
versionType: 'external_gte', versionType: 'external_gte',
body: item body: itemcp
}) })
} catch (e) { } catch (e) {
// ignore version conflict ... // ignore version conflict ...