core/pages/addbot.tsx
Junseo Park ae47f741b8
v2 Release (#154)
* chore(deps): update dependency typescript to v4.2.4 (#314)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency core-js to v3.10.1 (#315)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* feat: camo images in bot desc

* chore: added bot delete api

* feat: delete button working

* feat: added bot remove method

* chore: added csrfCaptchaSchema

* deps: update

* fix: some error at callback

* fix(deps): pin dependency abort-controller to 3.0.0 (#313)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/node-fetch to v2.5.10 (#316)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency eslint-plugin-react to v7.23.2 (#317)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* style: fixed for deepscan

* chore: improved user login interaction

* fix(deps): update dependency @sentry/webpack-plugin to v1.15.0 (#318)

* chore(deps): update dependency eslint to v7.24.0 (#320)

* fix(deps): update dependency postcss to v8.2.10 (#321)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* ci: updated ci stuff

* style: removed unnecessary script

* fix: not using SENTRY_RELEASE env

* chore: defaulting mysql password

* chore: added sentry_dsn env and only uploading for master

* ci: updated trigger

* ci: passing source branch env only at push

* chore(deps): update typescript-eslint monorepo to v4.22.0 (#322)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency eslint-config-prettier to v8.2.0 (#323)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/react-select to v4.0.15 (#325)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency eslint-plugin-prettier to v3.4.0 (#326)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/sanitize-html to v2 (#328)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/node to v14.14.41 (#324)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency ts-jest to v26.5.5 (#327)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* ci: debugging

* Update components/DeveloperLayout.tsx

Co-authored-by: zero734kr <zero734kr@gmail.com>

* Update components/Loader.tsx

Co-authored-by: zero734kr <zero734kr@gmail.com>

* Update components/ColorCard.tsx

Co-authored-by: zero734kr <zero734kr@gmail.com>

* Update components/ColorCard.tsx

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(deps): update dependency core-js to v3.11.0 (#329)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/sanitize-html to v2.3.1 (#330)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency postcss to v8.2.13 (#333)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency tailwindcss to v2.1.2 (#334)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency eslint to v7.25.0 (#335)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency @sentry/webpack-plugin to v1.15.1 (#332)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/node to v14.14.43 (#339)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/jest to v26.0.23 (#337)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency eslint-config-prettier to v8.3.0 (#336)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/react to v17.0.4 (#338)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* Update utils/ShowdownExtensions.ts

Co-authored-by: zero734kr <zero734kr@gmail.com>

* style: fixed some styles

* chore: updated api-docs git

* refactor: made change on sentry

* style: removed debug code

* deps: removed node-mock

* ci: removed env

* style: code style

* test: module names

* chore: docker using python

* chore: docker using build-base

* ci: fixed syntax error

* chore: changed sql type

* feat: added vote

* fix: version for v1

* feat: added v1 bot vote check

* feat: clearing cache for deleted bot

* chore: delete bot real working

IMPORTANT: NOW DELETE BOT REAL WORKS!

* fix: router called at non-client

* style: removed space

* feat: added vote check endpoint

* fix: router called at non-client

* fix(deps): update sentry monorepo to v6.3.5 (#331)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency core-js to v3.11.2 (#340)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency @types/react to v17.0.5 (#345)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update typescript-eslint monorepo to v4.22.1 (#343)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix: BotCard button component rendered as Tag

* feat: update docs

* feat: using koreanbots cdn for og image

* fix: missing querystring label

* docs: some text change

https://github.com/koreanbots/v2-testing/issues/72#issuecomment-807929228

* fix: removed unexpected char

close: https://github.com/koreanbots/v2-testing/issues/76

* fix: redirecting at serverside

* fix(deps): pin dependencies (#342)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency ts-jest to v26.5.6 (#347)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency postcss to v8.2.14 (#349)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency core-js to v3.11.3 (#348)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix: router instance called at serverside while rendering

* Merge branch 'master' of https://github.com/koreanbots/koreanbots

* feat: Sentry enabled only at production

* fix: menu not closing

close: https://github.com/koreanbots/v2-testing/issues/50

* chore: improved mobile design

* fix: tooltip overflows screen

close: https://github.com/koreanbots/v2-testing/issues/28

* fix: router called at server-side

close: https://github.com/koreanbots/v2-testing/issues/77

* typo: fixed typo issue

* typo: improved typo

* fix: router called at serverside

* chore: removed custom scrollbar style

* style: fixed null checks

* feat: added owner transfer and edit

* chore: clearing cache for updates

* chore: redirecting on update

* chore: added button margin

* feat: disabled webhook

* chore: added some spaces

* feat: added padding for ad

* feat: remove wave

* feat: added security page

* chore: some margin

* feat: added bug reporters

* style: fixed eslint

* fix(developers): https://github.com/koreanbots/v2-testing/issues/74

* chore: improved ad

* feat: migrated to @sentry/nextjs

* fix: card invite button fixed

* chore: not releasing

* chore: debugging

* chore: skiping sentry auto release

* feat: added docker hub build hook

* fix: docker hook

* fix: docker hook geting sentry dsn as build-arg

* chore: added sentry envs

* chore(docker): cleanup

* fix: bugs at card

* typo: fixed

* chore: margin top at message

* fix: card building weird

* fix: sentry disabled

* fix: query string invalid

fix: https://github.com/koreanbots/v2-testing/issues/92

* fix: https://github.com/koreanbots/v2-testing/issues/94

* chore: improved style

close: https://github.com/koreanbots/v2-testing/issues/83

* fix: scrollbar shown even its not overflowed

fix: https://github.com/koreanbots/v2-testing/issues/86

* fix: home not displayed at dev portal

fix: https://github.com/koreanbots/v2-testing/issues/84

* types: searchParams is optional prop

* feat: added required field notice

close: https://github.com/koreanbots/v2-testing/issues/90

* typo: fixed typo issues

For https://github.com/koreanbots/v2-testing/issues/79

* fix: causing error on other git url

ISSUE: https://sentry.io/share/issue/a13341dc1aab4e5aa994fee8857afff7/

* fix: handle AbortError

* chore(deps): update dependency eslint to v7.26.0 (#353)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency core-js to v3.12.1 (#350)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore: reordered bot section

* typo: fixed typo issue

from https://github.com/koreanbots/v2-testing/issues/79

* feat: opening new tab for discord link

close: https://github.com/koreanbots/v2-testing/issues/99

* feat: added opensearch

* Update renovate.json

* chore: prevent clickjacking

* chore: added moz SearchForm for opensearch xml

* fix(deps): update dependency rc-tooltip to v5 (#351)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update sentry monorepo to v6.3.6 (#354)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency prettier to v2.3.0 (#355)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update typescript-eslint monorepo to v4.23.0 (#356)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency postcss to v8.2.15 (#357)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency react-select to v4.3.1 (#358)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(deps): update dependency knex to v0.95.5 (#359)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* style: added space

* feat: added get botSubmits list api

* chore: updated endpoint

* typo: fixed and improved typo issues

* chore: improved message for empty category

close: https://github.com/koreanbots/v2-testing/issues/100

* feat: support pwa

* types: added missing typing

* chore: changed manifest

* fix: catching error for ga blocked

* fix: added missing argument

* chore: made some changes

* style: could be null

* chore: improved pwa

* fix: https://github.com/koreanbots/v2-testing/issues/105

* feat: added staff missing permission

* fix: https://github.com/koreanbots/v2-testing/issues/104

* feat: added width style

* Update pages/_app.tsx

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* style: suggestions at review

* feat: updated api-docs

* chore: added dest option

* chore: changed icon path

* feat: just commiting service worker

* feat: added bug bounty group

* ci: removed reviewdog

* feat: added google optimize

* chore: added maskable icon and changed short_name

* ci: made some changes on renovate

* Create SECURITY.md

* feat: fetching docs from github

* feat: added tos at footer

* feat(iOS): added pwa splash screen

* types: improved component typing

* feat: discord rebranded

* ci: configured renovate ignore

* [TYPO] 기여 규칙 링크 수정 (#367)

* fix(deps): update sentry monorepo to v6.4.0 (#364)

* feat: added logging

* style: reordered import

* feat: improved logging

* feat: private api changes

* feat: added OG

* chore: updated migrate.sql

* ci: updated renovate

* fix: seo

* feat: added approve api

* chore: some changes at deny

* feat: added approve

* refactor: using next-seo for seo

* ci(renovate): removed unused option

* chore: not passing pwa at navbar

* style: removed line break

* fix: https://github.com/koreanbots/v2-testing/issues/89

* feat: directly fetching from discord

* feat: support searching with index

* style: fix deepscan

* fix: invalid avatar url

* fix: https://github.com/koreanbots/v2-testing/issues/110

reopen: https://github.com/koreanbots/v2-testing/issues/89

* feat: added error message at submit button

* fix: https://github.com/koreanbots/v2-testing/issues/89

* feat: added deny presets article

* feat: added query aliases

* chore: update docs

* chore: remvoed empty file

* feat: increased ratelimit

* feat: added bot lists

* style: removed unused variable

* fix(deps): update dependency knex to v0.95.6 (#365)

* chore(deps): update typescript-eslint monorepo to v4.24.0 (#366)

* chore(deps): update dependency @types/react to v17.0.6 (#368)

* fix(deps): update dependency formik to v2.2.8 (#369)

* fix(deps): update dependency next to v10.2.2 (#370)

* fix(deps): update sentry monorepo to v6.4.1 (#371)

* fix(deps): update dependency sanitize-html to v2.4.0 (#372)

* fix(deps): update dependency postcss to v8.3.0 (#373)

* docs: updated license

* feat: added refresh data

* feat: better image size

close: https://github.com/koreanbots/v2-testing/issues/81

* chore: changed slogan

* fix: invalid v1 api

* fix: forbidden error

* feat: added char count at textarea

close: https://github.com/koreanbots/v2-testing/issues/112

* feat: changed edit page route

* fix(deps): update dependency next to v10.2.3 (#376)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency typescript to v4.3.2 (#383)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps): update dependency eslint to v7.27.0 (#374)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* deps: removed core-js

* deps: lock updated

* feat: added stable docker compose file

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: zero734kr <zero734kr@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: MintyU <deathcat@outlook.kr>
2021-05-27 22:25:29 +09:00

222 lines
12 KiB
TypeScript

import { NextPage, NextPageContext } from 'next'
import { useRef, useState } from 'react'
import { useRouter } from 'next/router'
import dynamic from 'next/dynamic'
import Link from 'next/link'
import { NextSeo } from 'next-seo'
import { Form, Formik } from 'formik'
import HCaptcha from '@hcaptcha/react-hcaptcha'
import { get } from '@utils/Query'
import { cleanObject, parseCookie, redirectTo } from '@utils/Tools'
import { AddBotSubmit, AddBotSubmitSchema } from '@utils/Yup'
import { categories, library } from '@utils/Constants'
import { getToken } from '@utils/Csrf'
import Fetch from '@utils/Fetch'
import { ResponseProps, SubmittedBot, Theme, User } from '@types'
const CheckBox = dynamic(() => import('@components/Form/CheckBox'))
const Label = dynamic(() => import('@components/Form/Label'))
const Login = dynamic(() => import('@components/Login'))
const Input = dynamic(() => import('@components/Form/Input'))
const Divider = dynamic(() => import('@components/Divider'))
const TextArea = dynamic(() => import('@components/Form/TextArea'))
const Segment = dynamic(() => import('@components/Segment'))
const Markdown = dynamic(() => import('@components/Markdown'))
const Select = dynamic(() => import('@components/Form/Select'))
const Selects = dynamic(() => import('@components/Form/Selects'))
const Button = dynamic(() => import('@components/Button'))
const Container = dynamic(() => import('@components/Container'))
const Message = dynamic(() => import('@components/Message'))
const Captcha = dynamic(() => import('@components/Captcha'))
const AddBot:NextPage<AddBotProps> = ({ logged, user, csrfToken, theme }) => {
const [ data, setData ] = useState<ResponseProps<SubmittedBot>>(null)
const [ captcha, setCaptcha ] = useState(false)
const [ touchedSumbit, setTouched ] = useState(false)
const captchaRef = useRef<HCaptcha>()
const router = useRouter()
const initialValues: AddBotSubmit = {
agree: false,
id: '',
prefix: '',
library: '',
category: [],
intro: '',
desc: `<!-- 이 설명을 지우시고 원하시는 설명을 적으셔도 좋습니다! -->
# 봇이름
자신의 봇을 자유롭게 표현해보세요!
## ✏️ 소개
무엇이 목적인 봇인가요?
## 🛠️ 기능
- 어떤
- 기능
- 있나요?`,
_csrf: csrfToken,
_captcha: 'captcha'
}
function toLogin() {
localStorage.redirectTo = window.location.href
redirectTo(router, 'login')
}
async function submitBot(value: AddBotSubmit, token: string) {
const res = await Fetch<SubmittedBot>(`/bots/${value.id}`, { method: 'POST', body: JSON.stringify(cleanObject<AddBotSubmit>({ ...value, _captcha: token})) })
setData(res)
}
if(!logged) return <Login>
<NextSeo title='새로운 봇 추가하기' description='자신의 봇을 한국 디스코드봇 리스트에 등록하세요.' />
</Login>
return <Container paddingTop className='py-5'>
<NextSeo title='새로운 봇 추가하기' description='자신의 봇을 한국 디스코드봇 리스트에 등록하세요.' />
<h1 className='text-3xl font-bold'> </h1>
<div className='mt-1 mb-5'>
, <span className='font-semibold'>{user.username}#{user.tag}</span>! <a role='button' tabIndex={0} onKeyDown={toLogin} onClick={toLogin} className='text-discord-blurple cursor-pointer outline-none'> ?</a>
</div>
{
data ? data.code == 200 && data.data ? <Message type='success'>
<h2 className='text-lg font-black'> !</h2>
<p> ! . {redirectTo(router, `/pendingBots/${data.data.id}/${data.data.date}`)}</p>
</Message> : <Message type='error'>
<h2 className='text-lg font-black'>{data.message || '오류가 발생했습니다.'}</h2>
<ul className='list-disc list-inside'>
{data.errors?.map((el, n) => <li key={n}>{el}</li>)}
</ul>
</Message> : <></>
}
<Formik initialValues={initialValues}
validationSchema={AddBotSubmitSchema}
onSubmit={() => setCaptcha(true)}>
{({ errors, touched, values, isValid, setFieldTouched, setFieldValue }) => (
<Form>
<div className='py-3'>
<Message type='warning'>
<h2 className='text-lg font-black'> !</h2>
<ul className='list-disc list-inside'>
<li><Link href='/discord'><a rel='noreferrer' target='_blank' className='text-blue-500 hover:text-blue-600'> </a></Link> ?</li>
<li> <Link href='/guidelines'><a rel='noreferrer' target='_blank' className='text-blue-500 hover:text-blue-600'></a></Link> ?</li>
<li> ? , .</li>
<li> ? , .</li>
( ) . <br/>
<strong> (Slash Command) .</strong> . ( .)
<ul>
<li>- 명령어: 도움, , , help, commands</li>
<li>- , <br/>
: []hellothisisverification 응답: 유저#()</li>
</ul>
<li>, API에 .</li>
</ul>
</Message>
</div>
<Label For='agree' error={errors.agree && touched.agree ? errors.agree : null} grid={false}>
<div className='flex items-center'>
<CheckBox name='agree' />
<strong className='text-sm ml-2'> , .</strong>
</div>
</Label>
<Divider />
<Label For='id' label='봇 ID' labelDesc='봇의 클라이언트 ID를 의미합니다.' error={errors.id && touched.id ? errors.id : null} short required>
<Input name='id' placeholder='653534001742741552' />
</Label>
<Label For='prefix' label='접두사' labelDesc='봇의 사용시 앞 쪽에 붙은 기호를 의미합니다. (Prefix)' error={errors.prefix && touched.prefix ? errors.prefix : null} short required>
<Input name='prefix' placeholder='!' />
</Label>
<Label For='library' label='라이브러리' labelDesc='봇에 사용된 라이브러리를 선택해주세요. 해당되는 라이브러리가 없다면 기타를 선택해주세요.' short required error={errors.library && touched.library ? errors.library : null}>
<Select options={library.map(el=> ({ label: el, value: el }))} handleChange={(value) => setFieldValue('library', value.value)} handleTouch={() => setFieldTouched('library', true)} />
</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) => {
setFieldValue('category', value.map(v=> v.value))
}} handleTouch={() => setFieldTouched('category', true)} values={values.category as string[]} setValues={(value) => setFieldValue('category', value)} />
<span className='text-gray-400 mt-1 text-sm'> 3 . . <strong> .</strong></span>
</Label>
<Divider />
<Label For='website' label='웹사이트' labelDesc='봇의 웹사이트를 작성해주세요.' error={errors.website && touched.website ? errors.website : null}>
<Input name='website' placeholder='https://koreanbots.dev' />
</Label>
<Label For='git' label='Git URL' labelDesc='봇 소스코드의 Git 주소를 입력해주세요. (오픈소스인 경우)' error={errors.git && touched.git ? errors.git : null}>
<Input name='git' placeholder='https://github.com/koreanbots/koreanbots'/>
</Label>
<Label For='inviteLink' label='초대링크' labelDesc='봇의 초대링크입니다. 비워두시면 자동으로 생성합니다.' error={errors.url && touched.url ? errors.url : null}>
<Input name='url' placeholder='https://discord.com/oauth2/authorize?client_id=653534001742741552&scope=bot&permissions=0' />
<span className='text-gray-400 mt-1 text-sm'>
<Link href='/calculator'>
<a rel='noreferrer' target='_blank' className='text-blue-500 hover:text-blue-400'></a>
</Link> !
</span>
</Label>
{
values.category.includes('빗금 명령어') && <Message type='warning'>
<h2 className='text-lg font-semibold'> (Slash Command) .</h2>
<p> .
.</p>
</Message>
}
<Label For='discord' label='지원 디스코드 서버' labelDesc='봇의 지원 디스코드 서버를 입력해주세요. (봇에 대해 도움을 받을 수 있는 공간입니다.)' error={errors.discord && touched.discord ? errors.discord : null} short>
<div className='flex items-center'>
discord.gg/<Input name='discord' placeholder='JEh53MQ' />
</div>
</Label>
<Divider />
<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)<br/> !</>} error={errors.desc && touched.desc ? errors.desc : null} required>
<TextArea max={1500} name='desc' placeholder='봇에 대해 최대한 자세히 설명해주세요!' theme={theme === 'dark' ? 'dark' : 'light'} value={values.desc} setValue={(value) => setFieldValue('desc', value)} />
</Label>
<Label For='preview' label='설명 미리보기' labelDesc='다음 결과는 실제와 다를 수 있습니다.'>
<Segment>
<Markdown text={values.desc} />
</Segment>
</Label>
<Divider />
<p className='text-base mt-2 mb-5'>
<span className='text-red-500 font-semibold'> *</span> =
</p>
{
captcha ? <Captcha ref={captchaRef} dark={theme === 'dark'} onVerify={(token) => {
submitBot(values, token)
window.scrollTo({ top: 0 })
setCaptcha(false)
captchaRef?.current?.resetCaptcha()
}} /> : <>
{
touchedSumbit && !isValid && <div className='my-1 text-red-500 text-xs font-light'> . .</div>
}
<Button type='submit' onClick={() => {
setTouched(true)
if(!isValid) window.scrollTo({ top: 0 })
} }>
<>
<i className='far fa-paper-plane'/>
</>
</Button>
</>
}
</Form>
)}
</Formik>
</Container>
}
export const getServerSideProps = async (ctx: NextPageContext) => {
const parsed = parseCookie(ctx.req)
const user = await get.Authorization(parsed?.token)
return { props: { logged: !!user, user: await get.user.load(user || ''), csrfToken: getToken(ctx.req, ctx.res) } }
}
interface AddBotProps {
logged: boolean
user: User
csrfToken: string
theme: Theme
}
export default AddBot