2024-03-20 00:37:31 +00:00
|
|
|
import { ITEM } from '@/fragments/items'
|
|
|
|
import { getGetServerSideProps } from '@/api/ssrApollo'
|
|
|
|
import { DiscussionForm } from '@/components/discussion-form'
|
|
|
|
import { LinkForm } from '@/components/link-form'
|
|
|
|
import { CenterLayout } from '@/components/layout'
|
|
|
|
import JobForm from '@/components/job-form'
|
|
|
|
import { PollForm } from '@/components/poll-form'
|
|
|
|
import { BountyForm } from '@/components/bounty-form'
|
2023-05-11 00:26:07 +00:00
|
|
|
import { useState } from 'react'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
|
|
|
import { useRouter } from 'next/router'
|
2024-03-20 00:37:31 +00:00
|
|
|
import PageLoading from '@/components/page-loading'
|
|
|
|
import { FeeButtonProvider } from '@/components/fee-button'
|
|
|
|
import SubSelect from '@/components/sub-select'
|
2021-08-11 20:13:10 +00:00
|
|
|
|
2023-08-28 17:52:15 +00:00
|
|
|
export const getServerSideProps = getGetServerSideProps({
|
|
|
|
query: ITEM,
|
|
|
|
notFound: data => !data.item,
|
|
|
|
authRequired: true
|
|
|
|
})
|
2021-08-11 20:13:10 +00:00
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
export default function PostEdit ({ ssrData }) {
|
|
|
|
const router = useRouter()
|
|
|
|
const { data } = useQuery(ITEM, { variables: { id: router.query.id } })
|
|
|
|
if (!data && !ssrData) return <PageLoading />
|
|
|
|
|
|
|
|
const { item } = data || ssrData
|
2023-07-23 14:16:12 +00:00
|
|
|
const [sub, setSub] = useState(item.subName)
|
2023-07-21 22:33:11 +00:00
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
const editThreshold = new Date(item.createdAt).getTime() + 10 * 60000
|
|
|
|
|
2023-05-11 00:26:07 +00:00
|
|
|
let FormType = DiscussionForm
|
2023-11-21 23:32:22 +00:00
|
|
|
let itemType = 'DISCUSSION'
|
2023-05-11 00:26:07 +00:00
|
|
|
if (item.isJob) {
|
|
|
|
FormType = JobForm
|
2023-11-21 23:32:22 +00:00
|
|
|
itemType = 'JOB'
|
2023-05-11 00:26:07 +00:00
|
|
|
} else if (item.url) {
|
|
|
|
FormType = LinkForm
|
2023-11-21 23:32:22 +00:00
|
|
|
itemType = 'LINK'
|
2023-05-11 00:26:07 +00:00
|
|
|
} else if (item.pollCost) {
|
|
|
|
FormType = PollForm
|
2023-11-21 23:32:22 +00:00
|
|
|
itemType = 'POLL'
|
2023-05-11 00:26:07 +00:00
|
|
|
} else if (item.bounty) {
|
|
|
|
FormType = BountyForm
|
2023-11-21 23:32:22 +00:00
|
|
|
itemType = 'BOUNTY'
|
2023-05-11 00:26:07 +00:00
|
|
|
}
|
2021-08-11 20:13:10 +00:00
|
|
|
|
2023-11-11 00:18:10 +00:00
|
|
|
const existingBoostLineItem = item.boost
|
|
|
|
? {
|
|
|
|
existingBoost: {
|
|
|
|
label: 'old boost',
|
|
|
|
term: `- ${item.boost}`,
|
|
|
|
modifier: cost => cost - item.boost
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: undefined
|
|
|
|
|
2021-08-11 20:13:10 +00:00
|
|
|
return (
|
2023-07-23 15:08:43 +00:00
|
|
|
<CenterLayout sub={sub}>
|
2023-11-11 00:18:10 +00:00
|
|
|
<FeeButtonProvider baseLineItems={existingBoostLineItem}>
|
|
|
|
<FormType item={item} editThreshold={editThreshold}>
|
2023-11-21 23:32:22 +00:00
|
|
|
{!item.isJob &&
|
|
|
|
<SubSelect
|
2024-02-23 15:32:20 +00:00
|
|
|
className='d-flex'
|
|
|
|
size='medium'
|
2023-11-21 23:32:22 +00:00
|
|
|
label='territory'
|
|
|
|
filterSubs={s => s.name !== 'jobs' && s.postTypes?.includes(itemType)}
|
|
|
|
onChange={(_, e) => setSub(e.target.value)}
|
|
|
|
sub={sub}
|
|
|
|
/>}
|
2023-11-11 00:18:10 +00:00
|
|
|
</FormType>
|
|
|
|
</FeeButtonProvider>
|
2023-07-23 15:08:43 +00:00
|
|
|
</CenterLayout>
|
2021-08-11 20:13:10 +00:00
|
|
|
)
|
|
|
|
}
|