Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Captcha View Components to ts

kruzhambusb253b5bd8b80
diff --git a/src/api/index.ts b/src/api/index.ts
index 8c7149d49..a4ae1f6f4 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -595,7 +595,7 @@ export const setTheme = (theme: string) =>
: error.response.data.message
})
-interface IGetLiveVisitorsInfo {
+export interface IGetLiveVisitorsInfo {
dv: string
br: string
os: string
diff --git a/src/pages/Captcha/View/components/CCRow.jsx b/src/pages/Captcha/View/components/CCRow.tsx
similarity index 87%
rename from src/pages/Captcha/View/components/CCRow.jsx
rename to src/pages/Captcha/View/components/CCRow.tsx
index 2f9452b2b..bed9f85f1 100644
--- a/src/pages/Captcha/View/components/CCRow.jsx
+++ b/src/pages/Captcha/View/components/CCRow.tsx
@@ -10,7 +10,10 @@ import PropTypes from 'prop-types'
* @param {string} language - Language to use for country name.
* @returns {JSX.Element}
*/
-const CCRow = ({ rowName, language }) => (
+const CCRow = ({ rowName, language }: {
+ rowName: string
+ language: string
+}): JSX.Element => (
<>
<Flag
className='rounded-sm'
diff --git a/src/pages/Captcha/View/components/Filters.jsx b/src/pages/Captcha/View/components/Filters.tsx
similarity index 81%
rename from src/pages/Captcha/View/components/Filters.jsx
rename to src/pages/Captcha/View/components/Filters.tsx
index 2eb6158db..9793fbada 100644
--- a/src/pages/Captcha/View/components/Filters.jsx
+++ b/src/pages/Captcha/View/components/Filters.tsx
@@ -12,7 +12,18 @@ import countries from 'utils/isoCountries'
*/
const Filter = ({
column, filter, isExclusive, onRemoveFilter, onChangeExclusive, tnMapping, language, t,
-}) => {
+}: {
+ column: string
+ filter: string
+ isExclusive: boolean
+ // eslint-disable-next-line no-shadow
+ onRemoveFilter: (column: string, filter: string) => void
+ // eslint-disable-next-line no-shadow
+ onChangeExclusive: (column: string, filter: string, isExclusive: boolean) => void
+ tnMapping: Record<string, string>
+ language: string
+ t: (key: string) => string
+}): JSX.Element => {
const displayColumn = tnMapping[column]
let displayFilter = filter
@@ -58,6 +69,17 @@ const Filter = ({
*/
const Filters = ({
filters, onRemoveFilter, onChangeExclusive, tnMapping,
+}: {
+ filters: {
+ column: string
+ filter: string
+ isExclusive: boolean
+ }[]
+ // eslint-disable-next-line no-shadow
+ onRemoveFilter: (column: string, filter: string) => void
+ // eslint-disable-next-line no-shadow
+ onChangeExclusive: (column: string, filter: string, isExclusive: boolean) => void
+ tnMapping: Record<string, string>
}) => {
const { t, i18n: { language } } = useTranslation('common')
diff --git a/src/pages/Captcha/View/components/InteractiveMap.jsx b/src/pages/Captcha/View/components/InteractiveMap.tsx
similarity index 85%
rename from src/pages/Captcha/View/components/InteractiveMap.jsx
rename to src/pages/Captcha/View/components/InteractiveMap.tsx
index ec078aee3..807cc1de6 100644
--- a/src/pages/Captcha/View/components/InteractiveMap.jsx
+++ b/src/pages/Captcha/View/components/InteractiveMap.tsx
@@ -5,21 +5,38 @@ import { useTranslation } from 'react-i18next'
import PropTypes from 'prop-types'
import countries from 'utils/isoCountries'
import { PROJECT_TABS } from 'redux/constants'
+import { StateType } from 'redux/store'
import { getTimeFromSeconds, getStringFromTime } from 'utils/generic'
import countriesList from 'utils/countries'
import { useSelector } from 'react-redux'
-const InteractiveMap = ({ data, onClickCountry, total }) => {
+const InteractiveMap = ({ data, onClickCountry, total }: {
+ data: Record<string, number>
+ onClickCountry: (country: string) => void
+ total: number
+}) => {
const { t, i18n: { language } } = useTranslation('common')
- const [hoverShow, setHoverShow] = useState(false)
- const [dataHover, setDataHover] = useState(null)
- const [cursorPosition, setCursorPosition] = useState(null)
+ const [hoverShow, setHoverShow] = useState<boolean>(false)
+ const [dataHover, setDataHover] = useState<{
+ countries: string
+ data: number
+ }>({} as {
+ countries: string
+ data: number
+ })
+ const [cursorPosition, setCursorPosition] = useState<{
+ pageX: number
+ pageY: number
+ }>({} as {
+ pageX: number
+ pageY: number
+ })
- const projectTab = useSelector((state) => state.ui.projects.projectTab)
+ const projectTab = useSelector((state: StateType) => state.ui.projects.projectTab)
const isTrafficTab = projectTab === PROJECT_TABS.traffic
- const onMouseMove = (e) => {
+ const onMouseMove = (e: React.MouseEvent<SVGSVGElement, MouseEvent>) => {
const rect = e.currentTarget.getBoundingClientRect()
const pageX = e.clientX - rect.left
const pageY = e.clientY - rect.top
diff --git a/src/pages/Captcha/View/components/LiveVisitorsDropdown.jsx b/src/pages/Captcha/View/components/LiveVisitorsDropdown.tsx
similarity index 88%
rename from src/pages/Captcha/View/components/LiveVisitorsDropdown.jsx
rename to src/pages/Captcha/View/components/LiveVisitorsDropdown.tsx
index bdcdd240b..dbf934a2e 100644
--- a/src/pages/Captcha/View/components/LiveVisitorsDropdown.jsx
+++ b/src/pages/Captcha/View/components/LiveVisitorsDropdown.tsx
@@ -1,19 +1,23 @@
import React, { useState, useEffect } from 'react'
import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
+// @ts-ignore
import OutsideClickHandler from 'react-outside-click-handler'
import {
ChevronDownIcon, ChevronUpIcon, XMarkIcon,
} from '@heroicons/react/24/outline'
import Flag from 'react-flagkit'
-import { getLiveVisitorsInfo } from 'api'
+import { getLiveVisitorsInfo, IGetLiveVisitorsInfo } from 'api'
-const LiveVisitorsDropdown = ({ live, projectId }) => {
+const LiveVisitorsDropdown = ({ live, projectId }: {
+ live: number
+ projectId: string
+}): JSX.Element => {
const { t } = useTranslation()
- const [show, setShow] = useState(false)
- const [liveInfo, setLiveInfo] = useState([])
- const [loading, setLoading] = useState(true)
+ const [show, setShow] = useState<boolean>(false)
+ const [liveInfo, setLiveInfo] = useState<IGetLiveVisitorsInfo[]>([])
+ const [loading, setLoading] = useState<boolean>(true)
const getLiveVisitors = async () => {
await getLiveVisitorsInfo(projectId)
diff --git a/src/pages/Captcha/View/components/NoEvents.jsx b/src/pages/Captcha/View/components/NoEvents.tsx
similarity index 88%
rename from src/pages/Captcha/View/components/NoEvents.jsx
rename to src/pages/Captcha/View/components/NoEvents.tsx
index 554696c07..ddc5ac585 100644
--- a/src/pages/Captcha/View/components/NoEvents.jsx
+++ b/src/pages/Captcha/View/components/NoEvents.tsx
@@ -18,8 +18,17 @@ import { DOCS_CAPTCHA_URL } from 'redux/constants'
*/
const NoEvents = ({
filters, resetFilters,
-}) => {
- const { t } = useTranslation('common')
+}: {
+ filters: {
+ column: string
+ filter: string
+ isExclusive: boolean
+ }[]
+ resetFilters: () => void
+}): JSX.Element => {
+ const { t }: {
+ t: (key: string) => string
+ } = useTranslation('common')
return (
<div className='flex flex-col py-6 sm:px-6 lg:px-8 mt-5'>
@@ -29,6 +38,7 @@ const NoEvents = ({
</h2>
<h2 className='text-2xl mb-8 text-center leading-snug'>
<Trans
+ // @ts-ignore
t={t}
i18nKey='project.noCaptchaEv'
components={{
diff --git a/src/pages/Captcha/View/components/RefRow.jsx b/src/pages/Captcha/View/components/RefRow.tsx
similarity index 79%
rename from src/pages/Captcha/View/components/RefRow.jsx
rename to src/pages/Captcha/View/components/RefRow.tsx
index 9847c7956..bee34ee08 100644
--- a/src/pages/Captcha/View/components/RefRow.jsx
+++ b/src/pages/Captcha/View/components/RefRow.tsx
@@ -9,22 +9,25 @@ import PropTypes from 'prop-types'
* @param {boolean} showIcons - Whether to show favicon icons near links or not.
* @returns {JSX.Element}
*/
-const RefRow = ({ rowName, showIcons }) => {
- let isUrl = true
- let url = rowName
+const RefRow = ({ rowName, showIcons }: {
+ rowName: string
+ showIcons: boolean
+}): JSX.Element => {
+ let isUrl: boolean = true
+ let url: URL | null = null
try {
- url = new URL(rowName)
+ url = new URL(rowName) as URL
} catch {
isUrl = false
}
return (
<div>
- {showIcons && isUrl && !_isEmpty(url.hostname) && (
+ {showIcons && isUrl && !_isEmpty(url?.hostname) && (
<img
className='w-5 h-5 mr-1.5 float-left'
- src={`https://icons.duckduckgo.com/ip3/${url.hostname}.ico`}
+ src={`https://icons.duckduckgo.com/ip3/${url?.hostname}.ico`}
alt=''
aria-hidden='true'
/>