feat: disabled webhook

This commit is contained in:
wonderlandpark 2021-05-07 08:36:05 +09:00
parent 4d4bf56650
commit 094303fc9c

View File

@ -2,12 +2,10 @@ import { NextPage, NextPageContext } from 'next'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { useState } from 'react' import { useState } from 'react'
import { Form, Formik } from 'formik'
import useCopyClipboard from 'react-use-clipboard' import useCopyClipboard from 'react-use-clipboard'
import { get } from '@utils/Query' import { get } from '@utils/Query'
import { DeveloperBot, DeveloperBotSchema } from '@utils/Yup' import { parseCookie, redirectTo } from '@utils/Tools'
import { cleanObject, parseCookie, redirectTo } from '@utils/Tools'
import { getToken } from '@utils/Csrf' import { getToken } from '@utils/Csrf'
import Fetch from '@utils/Fetch' import Fetch from '@utils/Fetch'
@ -18,7 +16,6 @@ import NotFound from 'pages/404'
import Link from 'next/link' import Link from 'next/link'
const Button = dynamic(() => import('@components/Button')) const Button = dynamic(() => import('@components/Button'))
const Input = dynamic(() => import('@components/Form/Input'))
const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout')) const DeveloperLayout = dynamic(() => import('@components/DeveloperLayout'))
const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar')) const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar'))
const Message = dynamic(() => import('@components/Message')) const Message = dynamic(() => import('@components/Message'))
@ -32,13 +29,13 @@ const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot, theme,
const [ tokenCopied, setTokenCopied ] = useCopyClipboard(spec?.token, { const [ tokenCopied, setTokenCopied ] = useCopyClipboard(spec?.token, {
successDuration: 1000 successDuration: 1000
}) })
async function updateApplication(d: DeveloperBot) { // async function updateApplication(d: DeveloperBot) {
const res = await Fetch(`/applications/bots/${bot.id}`, { // const res = await Fetch(`/applications/bots/${bot.id}`, {
method: 'PATCH', // method: 'PATCH',
body: JSON.stringify(cleanObject(d)) // body: JSON.stringify(cleanObject(d))
}) // })
setData(res) // setData(res)
} // }
async function resetToken() { async function resetToken() {
const res = await Fetch<{ token: string }>(`/applications/bots/${bot.id}/reset`, { const res = await Fetch<{ token: string }>(`/applications/bots/${bot.id}/reset`, {
@ -91,9 +88,19 @@ const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot, theme,
<Button onClick={() => setShowToken(!showToken)}>{showToken ? '숨기기' : '보기'}</Button> <Button onClick={() => setShowToken(!showToken)}>{showToken ? '숨기기' : '보기'}</Button>
<Button onClick={setTokenCopied} className={tokenCopied ? 'bg-green-400 text-white' : null}>{tokenCopied ? '복사됨' : '복사'}</Button> <Button onClick={setTokenCopied} className={tokenCopied ? 'bg-green-400 text-white' : null}>{tokenCopied ? '복사됨' : '복사'}</Button>
<Button onClick={()=> setModalOpen(true)}></Button> <Button onClick={()=> setModalOpen(true)}></Button>
<Modal isOpen={modalOpened} onClose={() => setModalOpen(false)} dark={theme === 'dark'} header='정말로 토큰을 재발급하시겠습니까?'>
<p> </p>
<div className='text-right pt-6'>
<Button className='bg-gray-500 text-white hover:opacity-90' onClick={()=> setModalOpen(false)}></Button>
<Button onClick={async ()=> {
const res = await resetToken()
spec.token = res.data.token
setModalOpen(false)
}}></Button>
</div>
</Modal>
</div> </div>
<Formik validationSchema={DeveloperBotSchema} initialValues={{ {/* <Formik validationSchema={DeveloperBotSchema} initialValues={{
webhook: spec.webhook || '', webhook: spec.webhook || '',
_csrf: csrfToken _csrf: csrfToken
}} }}
@ -107,20 +114,9 @@ const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot, theme,
{touched.webhook && errors.webhook ? <div className='text-red-500 text-xs font-light mt-1'>{errors.webhook}</div> : null} {touched.webhook && errors.webhook ? <div className='text-red-500 text-xs font-light mt-1'>{errors.webhook}</div> : null}
</div> </div>
<Button type='submit'><i className='far fa-save'/> </Button> <Button type='submit'><i className='far fa-save'/> </Button>
<Modal isOpen={modalOpened} onClose={() => setModalOpen(false)} dark={theme === 'dark'} header='정말로 토큰을 재발급하시겠습니까?'>
<p> </p>
<div className='text-right pt-6'>
<Button className='bg-gray-500 text-white hover:opacity-90' onClick={()=> setModalOpen(false)}></Button>
<Button onClick={async ()=> {
const res = await resetToken()
spec.token = res.data.token
setModalOpen(false)
}}></Button>
</div>
</Modal>
</Form> </Form>
)} )}
</Formik> </Formik> */}
</div> </div>
</div> </div>
</div> </div>