From 009e8232d481f67fe06b2b94046e7b1417b11b2c Mon Sep 17 00:00:00 2001 From: wonderlandpark Date: Sat, 13 Mar 2021 22:23:09 +0900 Subject: [PATCH] feat: can't report self --- pages/bots/[id]/index.tsx | 11 +++- pages/users/[id].tsx | 128 ++++++++++++++++++++++---------------- 2 files changed, 82 insertions(+), 57 deletions(-) diff --git a/pages/bots/[id]/index.tsx b/pages/bots/[id]/index.tsx index 9077233..3dca8eb 100644 --- a/pages/bots/[id]/index.tsx +++ b/pages/bots/[id]/index.tsx @@ -14,7 +14,7 @@ import { get } from '@utils/Query' import Day from '@utils/Day' import { ReportSchema } from '@utils/Yup' import Fetch from '@utils/Fetch' -import { checkBotFlag, checkUserFlag, formatNumber, parseCookie } from '@utils/Tools' +import { checkBotFlag, checkUserFlag, formatNumber, parseCookie, redirectTo } from '@utils/Tools' import { getToken } from '@utils/Csrf' import NotFound from '../../404' @@ -41,6 +41,10 @@ const Bots: NextPage = ({ data, date, user, theme, csrfToken, setThem const router = useRouter() const [ reportModal, setReportModal ] = useState(false) const [ reportRes, setReportRes ] = useState>(null) + function toLogin() { + localStorage.redirectTo = window.location.href + redirectTo(router, 'login') + } if (!data?.id) return if((checkBotFlag(data.flags, 'trusted') || checkBotFlag(data.flags, 'partnered')) && data.vanity && data.vanity !== router.query.id) router.push(`/bots/${data.vanity}`) return
@@ -182,7 +186,10 @@ const Bots: NextPage = ({ data, date, user, theme, csrfToken, setThem /> ))}
- setReportModal(true)} aria-hidden='true'> + { + if(!user) toLogin() + else setReportModal(true) + }} aria-hidden='true'> 신고하기 diff --git a/pages/users/[id].tsx b/pages/users/[id].tsx index 7da0397..42d6435 100644 --- a/pages/users/[id].tsx +++ b/pages/users/[id].tsx @@ -1,5 +1,6 @@ import { NextPage, NextPageContext } from 'next' import { useState } from 'react' +import { useRouter } from 'next/router' import dynamic from 'next/dynamic' import { SnowflakeUtil } from 'discord.js' import { ParsedUrlQuery } from 'querystring' @@ -7,8 +8,8 @@ import { josa } from 'josa' import { Field, Form, Formik } from 'formik' import { Bot, User, ResponseProps, Theme } from '@types' -import * as Query from '@utils/Query' -import { checkUserFlag } from '@utils/Tools' +import { get } from '@utils/Query' +import { checkUserFlag, parseCookie, redirectTo } from '@utils/Tools' import { getToken } from '@utils/Csrf' import Fetch from '@utils/Fetch' import { ReportSchema } from '@utils/Yup' @@ -30,9 +31,14 @@ const Modal = dynamic(() => import('@components/Modal')) const Button = dynamic(() => import('@components/Button')) const TextArea = dynamic(() => import('@components/Form/TextArea')) -const Users: NextPage = ({ data, csrfToken, theme }) => { +const Users: NextPage = ({ user, data, csrfToken, theme }) => { + const router = useRouter() const [ reportModal, setReportModal ] = useState(false) const [ reportRes, setReportRes ] = useState>(null) + function toLogin() { + localStorage.redirectTo = window.location.href + redirectTo(router, 'login') + } if (!data?.id) return return ( @@ -89,65 +95,73 @@ const Users: NextPage = ({ data, csrfToken, theme }) => { /> )} - { + { setReportModal(false) setReportRes(null) }} full dark={theme === 'dark'}> { - reportRes?.code === 200 ? -

성공적으로 신고하였습니다!

-

더 자세한 설명이 필요할 수 있습니다! 공식 디스코드에 참여해주세요

-
: { - const res = await Fetch(`/users/${data.id}/report`, { method: 'POST', body: JSON.stringify(body) }) - setReportRes(res) - }} validationSchema={ReportSchema} initialValues={{ - category: null, - description: '', - _csrf: csrfToken - }}> - { - ({ errors, touched, values, setFieldValue }) => ( -
-
- { - reportRes &&
- -

{reportRes.message}

-
    - {reportRes.errors?.map((el, n) =>
  • {el}
  • )} -
-
-
- } -

신고 구분

-

해당되는 항복을 선택해주세요.

- { - reportCats.map(el => -
- + user.id === data.id ?
+

+ " 현명한 조언을 해주는 것은 자기 이외에는 없다. " +

+
: + reportRes?.code === 200 ? +

성공적으로 신고하였습니다!

+

더 자세한 설명이 필요할 수 있습니다! 공식 디스코드에 참여해주세요

+
: { + const res = await Fetch(`/users/${data.id}/report`, { method: 'POST', body: JSON.stringify(body) }) + setReportRes(res) + }} validationSchema={ReportSchema} initialValues={{ + category: null, + description: '', + _csrf: csrfToken + }}> + { + ({ errors, touched, values, setFieldValue }) => ( + +
+ { + reportRes &&
+ +

{reportRes.message}

+
    + {reportRes.errors?.map((el, n) =>
  • {el}
  • )} +
+
- ) - } -
{errors.category && touched.category ? errors.category : null}
-

설명

-

신고하시는 내용을 자세하게 설명해주세요.

-