add job company and location
This commit is contained in:
parent
1472de0f91
commit
a627322220
|
@ -492,34 +492,27 @@ export default {
|
|||
|
||||
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) {
|
||||
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 } })
|
||||
if (!fullSub) {
|
||||
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) {
|
||||
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 () => {
|
||||
// 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 } })
|
||||
if (user.msats < minuteMsats) {
|
||||
throw new UserInputError('insufficient funds')
|
||||
|
@ -528,6 +521,9 @@ export default {
|
|||
|
||||
const data = {
|
||||
title,
|
||||
company,
|
||||
location: location.toLowerCase() === 'remote' ? undefined : location,
|
||||
remote,
|
||||
text,
|
||||
url,
|
||||
maxBid,
|
||||
|
@ -878,6 +874,7 @@ function nestComments (flat, parentId) {
|
|||
export const SELECT =
|
||||
`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".company, "Item".location, "Item".remote,
|
||||
"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'
|
||||
|
|
|
@ -25,7 +25,7 @@ export default gql`
|
|||
updateDiscussion(id: ID!, title: String!, text: String): Item!
|
||||
createComment(text: String!, parentId: ID!): 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!
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,9 @@ export default gql`
|
|||
position: Int
|
||||
prior: Int
|
||||
maxBid: Int
|
||||
company: String
|
||||
location: String
|
||||
remote: Boolean
|
||||
sub: Sub
|
||||
status: String
|
||||
}
|
||||
|
|
|
@ -201,31 +201,34 @@ 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.
|
||||
// Formik does this too! When you specify `type` to useField(), it will
|
||||
// return the correct bag of props for you
|
||||
const [field] = useField({ ...props, type: 'checkbox' })
|
||||
return (
|
||||
<BootstrapForm.Check
|
||||
custom
|
||||
id={props.id || props.name}
|
||||
inline={inline}
|
||||
>
|
||||
<BootstrapForm.Check.Input
|
||||
{...field} {...props} type='checkbox' onChange={(e) => {
|
||||
field.onChange(e)
|
||||
handleChange && handleChange(e.target.checked)
|
||||
}}
|
||||
/>
|
||||
<BootstrapForm.Check.Label className='d-flex'>
|
||||
<div className='flex-grow-1'>{label}</div>
|
||||
{extra &&
|
||||
<div className={styles.checkboxExtra}>
|
||||
{extra}
|
||||
</div>}
|
||||
</BootstrapForm.Check.Label>
|
||||
</BootstrapForm.Check>
|
||||
<BootstrapForm.Group className={groupClassName}>
|
||||
{hiddenLabel && <BootstrapForm.Label className='invisible'>{label}</BootstrapForm.Label>}
|
||||
<BootstrapForm.Check
|
||||
custom
|
||||
id={props.id || props.name}
|
||||
inline={inline}
|
||||
>
|
||||
<BootstrapForm.Check.Input
|
||||
{...field} {...props} type='checkbox' onChange={(e) => {
|
||||
field.onChange(e)
|
||||
handleChange && handleChange(e.target.checked)
|
||||
}}
|
||||
/>
|
||||
<BootstrapForm.Check.Label className='d-flex'>
|
||||
<div className='flex-grow-1'>{label}</div>
|
||||
{extra &&
|
||||
<div className={styles.checkboxExtra}>
|
||||
{extra}
|
||||
</div>}
|
||||
</BootstrapForm.Check.Label>
|
||||
</BootstrapForm.Check>
|
||||
</BootstrapForm.Group>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,21 @@ export function ItemJob ({ item, rank, children }) {
|
|||
<div className={`${styles.main} flex-wrap d-inline`}>
|
||||
<Link href={`/items/${item.id}`} passHref>
|
||||
<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>
|
||||
</Link>
|
||||
{/* eslint-disable-next-line */}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Checkbox, Form, Input, MarkdownInput, SubmitButton } from './form'
|
||||
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 { useEffect, useState } from 'react'
|
||||
import Info from '../svgs/information-fill.svg'
|
||||
|
@ -54,9 +54,10 @@ export default function JobForm ({ item, sub }) {
|
|||
}`,
|
||||
{ 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,
|
||||
mutation upsertJob($id: ID, $title: String!, $company: String!, $location: String,
|
||||
$remote: Boolean, $text: String!, $url: String!, $maxBid: Int!, $status: String) {
|
||||
upsertJob(sub: "${sub.name}", id: $id, title: $title, company: $company,
|
||||
location: $location, remote: $remote, text: $text,
|
||||
url: $url, maxBid: $maxBid, status: $status) {
|
||||
id
|
||||
}
|
||||
|
@ -65,12 +66,17 @@ export default function JobForm ({ item, sub }) {
|
|||
|
||||
const JobSchema = Yup.object({
|
||||
title: Yup.string().required('required').trim(),
|
||||
company: 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}`)
|
||||
.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
|
||||
|
@ -101,6 +107,9 @@ export default function JobForm ({ item, sub }) {
|
|||
className='py-5'
|
||||
initial={{
|
||||
title: item?.title || '',
|
||||
company: item?.company || '',
|
||||
location: item?.location || '',
|
||||
remote: item?.remote || false,
|
||||
text: item?.text || '',
|
||||
url: item?.url || '',
|
||||
maxBid: item?.maxBid || sub.baseCost,
|
||||
|
@ -134,11 +143,28 @@ export default function JobForm ({ item, sub }) {
|
|||
})}
|
||||
>
|
||||
<Input
|
||||
label='title'
|
||||
label='job title'
|
||||
name='title'
|
||||
required
|
||||
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
|
||||
label='description'
|
||||
name='text'
|
||||
|
|
|
@ -18,6 +18,9 @@ export const ITEM_FIELDS = gql`
|
|||
meSats
|
||||
ncomments
|
||||
maxBid
|
||||
company
|
||||
location
|
||||
remote
|
||||
sub {
|
||||
name
|
||||
baseCost
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "Item" ADD COLUMN "company" TEXT;
|
|
@ -115,6 +115,7 @@ model Item {
|
|||
status Status @default(ACTIVE)
|
||||
statusUpdatedAt DateTime?
|
||||
location String?
|
||||
company String?
|
||||
latitude Float?
|
||||
longitude Float?
|
||||
remote Boolean?
|
||||
|
|
|
@ -10,4 +10,11 @@
|
|||
|
||||
.close:hover {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.inlineCheckGroup {
|
||||
margin-left: .5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
|
@ -19,6 +19,9 @@ const ITEM_SEARCH_FIELDS = gql`
|
|||
}
|
||||
status
|
||||
maxBid
|
||||
company
|
||||
location
|
||||
remote
|
||||
upvotes
|
||||
sats
|
||||
boost
|
||||
|
@ -28,13 +31,24 @@ const ITEM_SEARCH_FIELDS = gql`
|
|||
|
||||
async function _indexItem (item) {
|
||||
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 {
|
||||
await search.index({
|
||||
id: item.id,
|
||||
index: 'item',
|
||||
version: new Date(item.updatedAt).getTime(),
|
||||
versionType: 'external_gte',
|
||||
body: item
|
||||
body: itemcp
|
||||
})
|
||||
} catch (e) {
|
||||
// ignore version conflict ...
|
||||
|
|
Loading…
Reference in New Issue