chore: added comment and default desc

This commit is contained in:
Junseo Park 2021-02-18 13:50:36 +09:00
parent 908ed06c33
commit 9091f74b8a

View File

@ -6,14 +6,13 @@ import { Form, Formik } from 'formik'
import { get } from '@utils/Query'
import { parseCookie, redirectTo } from '@utils/Tools'
import { AddBotSubmitSchema } from '@utils/Yup'
import { AddBotSubmit, AddBotSubmitSchema } from '@utils/Yup'
import { categories, library } from '@utils/Constants'
import { User } from '@types'
import { SubmittedBot, User } from '@types'
import { getToken } from '@utils/Csrf'
import Fetch from '@utils/Fetch'
const CheckBox = dynamic(() => import('@components/Form/CheckBox'))
const CsrfToken = dynamic(() => import('@components/Form/CsrfToken'))
const Label = dynamic(() => import('@components/Form/Label'))
const Input = dynamic(() => import('@components/Form/Input'))
const Divider = dynamic(() => import('@components/Divider'))
@ -34,11 +33,9 @@ const AddBot:NextPage<AddBotProps> = ({ logged, user, csrfToken }) => {
redirectTo(router, 'login')
}
async function submitBot(value) {
const res = await Fetch(`/bots/${value.id}`, { method: 'POST', body: JSON.stringify(value), headers: { 'content-type': 'application/json' } })
console.log(res)
return res
async function submitBot(value: AddBotSubmit) {
const res = await Fetch<SubmittedBot>(`/bots/${value.id}`, { method: 'POST', body: JSON.stringify(value), headers: { 'content-type': 'application/json' } })
redirectTo(router, `/pendingBots/${res.data.id}/${res.data.date}`)
}
if(!logged) {
toLogin()
@ -55,19 +52,25 @@ const AddBot:NextPage<AddBotProps> = ({ logged, user, csrfToken }) => {
id: '',
prefix: '',
library: '',
website: '',
git: '',
url: '',
discord: '',
category: [],
intro: '',
desc: '',
desc: `<!-- 이 설명을 지우시고 원하시는 설명을 적으셔도 좋습니다! -->
#
!
##
?
## 🛠
-
-
- ?`,
_csrf: csrfToken
}}
validationSchema={AddBotSubmitSchema}
onSubmit={async(values) => {
submitBot(values)
}}>
onSubmit={submitBot}>
{({ errors, touched, values, setFieldTouched, setFieldValue }) => (
<Form>
<div className='py-5'>
@ -108,9 +111,9 @@ const AddBot:NextPage<AddBotProps> = ({ logged, user, csrfToken }) => {
</Label>
<Label For='category' label='카테고리' labelDesc='봇에 해당되는 카테고리를 선택해주세요' required error={errors.category && touched.category ? errors.category as string : null}>
<Selects options={categories.map(el=> ({ label: el, value: el }))} handleChange={(value) => {
console.log(value)
setFieldValue('category', value.map(v=> v.value))
}} handleTouch={() => setFieldTouched('category', true)} />
}} handleTouch={() => setFieldTouched('category', true)} values={values.category as string[]} setValues={(value) => setFieldValue('category', value)} />
<span className='text-gray-400 mt-1 text-sm'> 3 . .</span>
</Label>
<Divider />
<Label For='website' label='웹사이트' labelDesc='봇의 웹사이트를 작성해주세요.' error={errors.website && touched.website ? errors.website : null}>
@ -131,14 +134,12 @@ const AddBot:NextPage<AddBotProps> = ({ logged, user, csrfToken }) => {
<Label For='intro' label='봇 소개' labelDesc='봇을 소개할 수 있는 간단한 설명을 적어주세요. (최대 60자)' error={errors.intro && touched.intro ? errors.intro : null} required>
<Input name='intro' placeholder='국내 봇을 한 곳에서.' />
</Label>
<Label For='intro' label='봇 설명' labelDesc='봇을 자세하게 설명해주세요! (최대 1500자)' error={errors.desc && touched.desc ? errors.desc : null} required>
<TextArea name='desc' placeholder='마크다운을 지원합니다' />
<Label For='intro' label='봇 설명' labelDesc={<> ! ( 1500)<br/> !</>} error={errors.desc && touched.desc ? errors.desc : null} required>
<TextArea name='desc' placeholder='봇에 대해 최대한 자세히 설명해주세요!' />
</Label>
<Label For='preview' label='설명 미리보기' labelDesc='다음 결과는 실제와 다를 수 있습니다'>
<Segment>
<div className='px-5 py-5'>
<Markdown text={values.desc} />
</div>
<Markdown text={values.desc} />
</Segment>
</Label>
<Divider />