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!

new captcha to remix and add routing

Maksim Mrugf3fe3fddde2b
diff --git a/app/pages/Captcha/Settings/CaptchaSettings.tsx b/app/pages/Captcha/Settings/CaptchaSettings.tsx
index d93bdf7cd..a8eb3a311 100644
--- a/app/pages/Captcha/Settings/CaptchaSettings.tsx
+++ b/app/pages/Captcha/Settings/CaptchaSettings.tsx
@@ -2,7 +2,7 @@
import React, {
useState, useEffect, useMemo, memo, useRef,
} from 'react'
-import { useLocation, useHistory, useParams } from 'react-router-dom'
+import { useLocation, useNavigate, useParams } from '@remix-run/react'
import { useTranslation } from 'react-i18next'
import cx from 'clsx'
import _isEmpty from 'lodash/isEmpty'
@@ -19,7 +19,6 @@ import _includes from 'lodash/includes'
import PropTypes from 'prop-types'
import { ExclamationTriangleIcon, TrashIcon, ClipboardDocumentIcon } from '@heroicons/react/24/outline'
-import Title from 'components/Title'
import { withAuthentication, auth } from 'hoc/protected'
import { isSelfhosted } from 'redux/constants'
import {
@@ -31,7 +30,7 @@ import Checkbox from 'ui/Checkbox'
import Modal from 'ui/Modal'
import Select from 'ui/Select'
import { trackCustom } from 'utils/analytics'
-import routes from 'routes'
+import routes from 'routesPath'
import { ICaptchaProject, IProject, IProjectNames } from 'redux/models/IProject'
import { IUser } from 'redux/models/IUser'
@@ -89,7 +88,7 @@ const CaptchaSettings = ({
} = useParams()
const project: ICaptchaProject | IProject = useMemo(() => _find([...projects, ...analyticsProjects], p => p.id === id) || {} as IProject | ICaptchaProject, [projects, analyticsProjects, id])
const isSettings: boolean = !_isEmpty(id) && (_replace(routes.captcha_settings, ':id', id) === pathname)
- const history = useHistory()
+ const navigate = useNavigate()
const [form, setForm] = useState<IForm>({
name: '',
id,
@@ -120,13 +119,13 @@ const CaptchaSettings = ({
useEffect(() => {
if (!user.isActive && !isSelfhosted) {
showError(t('project.captcha.settings.verify'))
- history.push(routes.dashboard)
+ navigate(routes.dashboard)
}
if (!isLoading && isSettings && !projectDeleting) {
if (_isEmpty(project) || project?.uiHidden) {
showError(t('project.captcha.noExist'))
- history.push(routes.dashboard)
+ navigate(routes.dashboard)
} else {
setForm({
...project,
@@ -176,7 +175,7 @@ const CaptchaSettings = ({
}
loadProjects()
- history.push(routes.dashboard)
+ navigate(routes.dashboard)
} catch (e) {
if (isSettings) {
updateProjectFailed(e as string)
@@ -197,7 +196,7 @@ const CaptchaSettings = ({
await deleteCaptchaProject(id)
removeProject(id)
projectDeleted(t('project.settings.deleted'))
- history.push(routes.dashboard)
+ navigate(routes.dashboard)
} catch (e) {
deleteProjectFailed(e as string)
} finally {
@@ -214,7 +213,7 @@ const CaptchaSettings = ({
await resetCaptchaProject(id)
deleteProjectCache(id)
projectDeleted(t('project.settings.resetted'))
- history.push(routes.dashboard)
+ navigate(routes.dashboard)
} catch (e) {
deleteProjectFailed(e as string)
} finally {
@@ -287,7 +286,7 @@ const CaptchaSettings = ({
}
const onCancel = () => {
- history.push(isSettings ? _replace(routes.captcha, ':id', id) : routes.dashboard)
+ navigate(isSettings ? _replace(routes.captcha, ':id', id) : routes.dashboard)
}
const title = isSettings ? `${t('project.settings.settings')} ${form.name}` : t('project.settings.create')
@@ -325,263 +324,259 @@ const CaptchaSettings = ({
if (_isEmpty(allProjectsNames)) {
getAllProjectsNames()
}
- // eslint-disable-next-line react-hooks/exhaustive-deps
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [tab])
return (
- <Title title={title}>
- <div
- className={cx('min-h-min-footer bg-gray-50 dark:bg-slate-900 flex flex-col py-6 px-4 sm:px-6 lg:px-8', {
- 'pb-40': isSettings,
- })}
- >
- <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
- <h2 className='mt-2 text-3xl font-bold text-gray-900 dark:text-gray-50'>
- {title}
- </h2>
- <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.general')}
- </h3>
- <div className='mt-6'>
- {(!isSettings && _filter(allProjectsNames || analyticsProjects, (item) => !item?.isCaptchaProject).length > 0) && (
- <nav className='-mb-px flex space-x-8'>
- {_map(tabForCreateCaptcha, (tabCaptcha) => (
- <button
- key={tabCaptcha.name}
- type='button'
- onClick={() => setTab(tabCaptcha.name)}
- className={cx('whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-md', {
- 'border-indigo-500 text-indigo-600 dark:text-indigo-500': tab === tabCaptcha.name,
- 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300 dark:hover:border-gray-300': tab !== tabCaptcha.name,
- })}
- >
- {t(tabCaptcha.label)}
- </button>
- ))}
- </nav>
- )}
- </div>
- {tab === tabForNew && (
- <>
- <Input
- name='name'
- id='name'
- type='text'
- label={t('project.captcha.settings.name')}
- value={form.name}
- placeholder='My awesome project'
- className='mt-4'
- onChange={handleInput}
- error={beenSubmitted ? errors.name : null}
- />
- <Input
- name='id'
- id='id'
- type='text'
- label={t('project.captcha.settings.pid')}
- value={form.id}
- className='mt-4'
- onChange={handleInput}
- error={beenSubmitted ? errors.id : null}
- disabled
- />
- </>
+ <div
+ className={cx('min-h-min-footer bg-gray-50 dark:bg-slate-900 flex flex-col py-6 px-4 sm:px-6 lg:px-8', {
+ 'pb-40': isSettings,
+ })}
+ >
+ <form className='max-w-7xl w-full mx-auto' onSubmit={handleSubmit}>
+ <h2 className='mt-2 text-3xl font-bold text-gray-900 dark:text-gray-50'>
+ {title}
+ </h2>
+ <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.general')}
+ </h3>
+ <div className='mt-6'>
+ {(!isSettings && _filter(allProjectsNames || analyticsProjects, (item) => !item?.isCaptchaProject).length > 0) && (
+ <nav className='-mb-px flex space-x-8'>
+ {_map(tabForCreateCaptcha, (tabCaptcha) => (
+ <button
+ key={tabCaptcha.name}
+ type='button'
+ onClick={() => setTab(tabCaptcha.name)}
+ className={cx('whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-md', {
+ 'border-indigo-500 text-indigo-600 dark:text-indigo-500': tab === tabCaptcha.name,
+ 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300 dark:hover:border-gray-300': tab !== tabCaptcha.name,
+ })}
+ >
+ {t(tabCaptcha.label)}
+ </button>
+ ))}
+ </nav>
)}
- {tab === tabForInheritance && (
- <Select
- title={_isEmpty(reuseProjectId) ? 'select project' : reuseProjectId}
- label={t('profileSettings.selectProject')}
- className='w-full'
- items={_filter(allProjectsNames || analyticsProjects, (item) => !item.isCaptchaProject)}
- labelExtractor={(item) => `${item.name} | ${item.id}`}
- keyExtractor={(item) => item.id}
- onSelect={(item) => setReuseProjectId(item)}
+ </div>
+ {tab === tabForNew && (
+ <Input
+ name='name'
+ id='name'
+ type='text'
+ label={t('project.captcha.settings.name')}
+ value={form.name}
+ placeholder='My awesome project'
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.name : null}
+ />
+ )}
+ {tab === tabForInheritance && (
+ <Select
+ title={_isEmpty(reuseProjectId) ? 'select project' : reuseProjectId}
+ label={t('profileSettings.selectProject')}
+ className='w-full'
+ items={_filter(allProjectsNames || analyticsProjects, (item) => !item.isCaptchaProject)}
+ labelExtractor={(item) => `${item.name} | ${item.id}`}
+ keyExtractor={(item) => item.id}
+ onSelect={(item) => setReuseProjectId(item)}
+ />
+ )}
+ {isSettings ? (
+ <>
+ <Input
+ name='id'
+ id='id'
+ type='text'
+ label={t('project.captcha.settings.pid')}
+ value={form.id}
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.id : null}
+ disabled
/>
- )}
- {isSettings ? (
- <>
- <Input
- name='origins'
- id='origins'
- type='text'
- label={t('project.settings.origins')}
- hint={t('project.settings.originsHint')}
- value={form.origins as string || ''}
- className='mt-4'
- onChange={handleInput}
- error={beenSubmitted ? errors.origins : null}
- />
- <Input
- name='ipBlacklist'
- id='ipBlacklist'
- type='text'
- label={t('project.settings.ipBlacklist')}
- hint={t('project.settings.ipBlacklistHint')}
- value={form.ipBlacklist as string || ''}
- className='mt-4'
- onChange={handleInput}
- error={beenSubmitted ? errors.ipBlacklist : null}
- isBeta
- />
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
- {t('profileSettings.captchaSecretKey')}
- </h3>
- {captchaSecretKey ? (
- <>
- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
- {t('profileSettings.captchaSecretKeyHint')}
- </p>
- <p className='mt-4 max-w-prose text-base text-gray-900 dark:text-gray-50'>
- {t('profileSettings.captchaSecretKey')}
- </p>
- <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2'>
- <div className='relative group'>
- <Input
- name='sercretKey'
- id='sercretKey'
- type='text'
- className='pr-9'
- value={captchaSecretKey}
- onChange={handleInput}
- disabled
- />
- <div className='absolute right-2 top-3'>
- <div className='group relative'>
- <Button
- type='button'
- onClick={() => setToClipboard(captchaSecretKey)}
- className='opacity-70 hover:opacity-100'
- noBorder
- >
- <>
- <ClipboardDocumentIcon className='w-6 h-6' />
- {copied && (
+ <Input
+ name='origins'
+ id='origins'
+ type='text'
+ label={t('project.settings.origins')}
+ hint={t('project.settings.originsHint')}
+ value={form.origins as string || ''}
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.origins : null}
+ />
+ <Input
+ name='ipBlacklist'
+ id='ipBlacklist'
+ type='text'
+ label={t('project.settings.ipBlacklist')}
+ hint={t('project.settings.ipBlacklistHint')}
+ value={form.ipBlacklist as string || ''}
+ className='mt-4'
+ onChange={handleInput}
+ error={beenSubmitted ? errors.ipBlacklist : null}
+ isBeta
+ />
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <h3 className='flex items-center mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.captchaSecretKey')}
+ </h3>
+ {captchaSecretKey ? (
+ <>
+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.captchaSecretKeyHint')}
+ </p>
+ <p className='mt-4 max-w-prose text-base text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.captchaSecretKey')}
+ </p>
+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2'>
+ <div className='relative group'>
+ <Input
+ name='sercretKey'
+ id='sercretKey'
+ type='text'
+ className='pr-9'
+ value={captchaSecretKey}
+ onChange={handleInput}
+ disabled
+ />
+ <div className='absolute right-2 top-3'>
+ <div className='group relative'>
+ <Button
+ type='button'
+ onClick={() => setToClipboard(captchaSecretKey)}
+ className='opacity-70 hover:opacity-100'
+ noBorder
+ >
+ <>
+ <ClipboardDocumentIcon className='w-6 h-6' />
+ {copied && (
<div className='animate-appear bg-white dark:bg-slate-800 cursor-auto rounded p-1 absolute sm:top-0 top-0.5 right-8 text-xs text-green-600'>
{t('common.copied')}
</div>
- )}
- </>
- </Button>
- </div>
+ )}
+ </>
+ </Button>
</div>
</div>
</div>
- </>
- ) : (
- <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
- {t('profileSettings.noApiKey')}
- </p>
- )}
- {captchaSecretKey ? (
- <Button className='mt-4' onClick={() => setShowRegenerateSecret(true)} danger large>
- {t('profileSettings.regenerateSecretKey')}
- </Button>
- ) : (
- <Button className='mt-4' onClick={onRegenerateSecretKey} primary large>
- {t('profileSettings.generateSecretKey')}
- </Button>
- )}
- <hr className='mt-5 border-gray-200 dark:border-gray-600' />
- <Checkbox
- checked={Boolean(form.active)}
- onChange={handleInput}
- name='active'
- id='active'
- className='mt-4'
- label={t('project.captcha.settings.enabled')}
- hint={t('project.captcha.settings.enabledHint')}
- />
- <Checkbox
- checked={Boolean(form.public)}
- onChange={handleInput}
- name='public'
- id='public'
- className='mt-4'
- label={t('project.settings.public')}
- hint={t('project.settings.publicHint')}
- />
- <div className='flex justify-between mt-8 h-20 sm:h-min'>
- <div className='flex flex-wrap items-center'>
- <Button className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-slate-700/50 dark:bg-slate-800 dark:hover:bg-slate-700' onClick={onCancel} secondary regular>
- {t('common.cancel')}
- </Button>
- <Button type='submit' loading={projectSaving} primary regular>
- {t('common.save')}
- </Button>
- </div>
- <div className='flex flex-wrap items-center justify-end'>
- <Button onClick={() => !projectResetting && setShowReset(true)} loading={projectDeleting} semiDanger semiSmall>
- <>
- <TrashIcon className='w-5 h-5 mr-1' />
- {t('project.settings.reset')}
- </>
- </Button>
- <Button className='ml-2' onClick={() => !projectDeleting && setShowDelete(true)} loading={projectDeleting} danger semiSmall>
- <>
- <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
- {t('project.settings.delete')}
- </>
- </Button>
</div>
- </div>
- <hr className='mt-2 sm:mt-5 border-gray-200 dark:border-gray-600' />
- </>
- ) : (
- <p className='text-gray-500 dark:text-gray-300 italic mt-1 mb-4 text-sm'>
- {t('project.settings.createHint')}
- </p>
- )}
-
- {!isSettings && (
- <div>
- <Button className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-slate-700/50 dark:bg-slate-800 dark:hover:bg-slate-700' onClick={onCancel} secondary regular>
- {t('common.cancel')}
+ </>
+ ) : (
+ <p className='max-w-prose text-base text-gray-900 dark:text-gray-50'>
+ {t('profileSettings.noApiKey')}
+ </p>
+ )}
+ {captchaSecretKey ? (
+ <Button className='mt-4' onClick={() => setShowRegenerateSecret(true)} danger large>
+ {t('profileSettings.regenerateSecretKey')}
</Button>
- <Button type='submit' loading={projectSaving} primary regular>
- {t('common.save')}
+ ) : (
+ <Button className='mt-4' onClick={onRegenerateSecretKey} primary large>
+ {t('profileSettings.generateSecretKey')}
</Button>
+ )}
+ <hr className='mt-5 border-gray-200 dark:border-gray-600' />
+ <Checkbox
+ checked={Boolean(form.active)}
+ onChange={handleInput}
+ name='active'
+ id='active'
+ className='mt-4'
+ label={t('project.captcha.settings.enabled')}
+ hint={t('project.captcha.settings.enabledHint')}
+ />
+ <Checkbox
+ checked={Boolean(form.public)}
+ onChange={handleInput}
+ name='public'
+ id='public'
+ className='mt-4'
+ label={t('project.settings.public')}
+ hint={t('project.settings.publicHint')}
+ />
+ <div className='flex justify-between mt-8 h-20 sm:h-min'>
+ <div className='flex flex-wrap items-center'>
+ <Button className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-slate-700/50 dark:bg-slate-800 dark:hover:bg-slate-700' onClick={onCancel} secondary regular>
+ {t('common.cancel')}
+ </Button>
+ <Button type='submit' loading={projectSaving} primary regular>
+ {t('common.save')}
+ </Button>
+ </div>
+ <div className='flex flex-wrap items-center justify-end'>
+ <Button onClick={() => !projectResetting && setShowReset(true)} loading={projectDeleting} semiDanger semiSmall>
+ <>
+ <TrashIcon className='w-5 h-5 mr-1' />
+ {t('project.settings.reset')}
+ </>
+ </Button>
+ <Button className='ml-2' onClick={() => !projectDeleting && setShowDelete(true)} loading={projectDeleting} danger semiSmall>
+ <>
+ <ExclamationTriangleIcon className='w-5 h-5 mr-1' />
+ {t('project.settings.delete')}
+ </>
+ </Button>
+ </div>
</div>
- )}
- </form>
- <Modal
- onClose={() => setShowDelete(false)}
- onSubmit={onDelete}
- submitText={t('project.settings.delete')}
- closeText={t('common.close')}
- title={t('project.settings.qDelete')}
- message={t('project.settings.deleteHint')}
- submitType='danger'
- type='error'
- isOpened={showDelete}
- />
- <Modal
- onClose={() => setShowReset(false)}
- onSubmit={onReset}
- submitText={t('project.settings.reset')}
- closeText={t('common.close')}
- title={t('project.settings.qReset')}
- message={t('project.settings.resetHint')}
- submitType='danger'
- type='error'
- isOpened={showReset}
- />
- <Modal
- onClose={() => setShowRegenerateSecret(false)}
- onSubmit={() => {
- setShowRegenerateSecret(false)
- onRegenerateSecretKey()
- }}
- submitText={t('profileSettings.regenerateSecretKey')}
- closeText={t('common.close')}
- title={t('profileSettings.regenerateSecretKeyTitle')}
- submitType='danger'
- type='error'
- message={t('profileSettings.regenerateSecretKeyMessage')}
- isOpened={showRegenerateSecret}
- />
- </div>
- </Title>
+ <hr className='mt-2 sm:mt-5 border-gray-200 dark:border-gray-600' />
+ </>
+ ) : (
+ <p className='text-gray-500 dark:text-gray-300 italic mt-1 mb-4 text-sm'>
+ {t('project.settings.createHint')}
+ </p>
+ )}
+
+ {!isSettings && (
+ <div>
+ <Button className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-slate-700/50 dark:bg-slate-800 dark:hover:bg-slate-700' onClick={onCancel} secondary regular>
+ {t('common.cancel')}
+ </Button>
+ <Button type='submit' loading={projectSaving} primary regular>
+ {t('common.save')}
+ </Button>
+ </div>
+ )}
+ </form>
+ <Modal
+ onClose={() => setShowDelete(false)}
+ onSubmit={onDelete}
+ submitText={t('project.settings.delete')}
+ closeText={t('common.close')}
+ title={t('project.settings.qDelete')}
+ message={t('project.settings.deleteHint')}
+ submitType='danger'
+ type='error'
+ isOpened={showDelete}
+ />
+ <Modal
+ onClose={() => setShowReset(false)}
+ onSubmit={onReset}
+ submitText={t('project.settings.reset')}
+ closeText={t('common.close')}
+ title={t('project.settings.qReset')}
+ message={t('project.settings.resetHint')}
+ submitType='danger'
+ type='error'
+ isOpened={showReset}
+ />
+ <Modal
+ onClose={() => setShowRegenerateSecret(false)}
+ onSubmit={() => {
+ setShowRegenerateSecret(false)
+ onRegenerateSecretKey()
+ }}
+ submitText={t('profileSettings.regenerateSecretKey')}
+ closeText={t('common.close')}
+ title={t('profileSettings.regenerateSecretKeyTitle')}
+ submitType='danger'
+ type='error'
+ message={t('profileSettings.regenerateSecretKeyMessage')}
+ isOpened={showRegenerateSecret}
+ />
+ </div>
)
}
diff --git a/app/routes/captchas.new.tsx b/app/routes/captchas.new.tsx
new file mode 100644
index 000000000..174bfc99d
--- /dev/null
+++ b/app/routes/captchas.new.tsx
@@ -0,0 +1,15 @@
+import CaptchaSettings from 'pages/Captcha/Settings'
+import type { V2_MetaFunction } from '@remix-run/node'
+
+export const meta: V2_MetaFunction = () => {
+ return [
+ {
+ title: 'Captcha Settings',
+ description: 'Captcha Settings',
+ },
+ ]
+}
+
+export default function Index() {
+ return <CaptchaSettings />
+}
diff --git a/app/routesPath/index.ts b/app/routesPath/index.ts
index 24cbc3167..08bb6bed9 100644
--- a/app/routesPath/index.ts
+++ b/app/routesPath/index.ts
@@ -11,7 +11,7 @@ const routes = Object.freeze({
verify: '/verify-email/:id', // add
change_email: '/change-email/:id', // add
new_project: '/projects/new', // add
- new_captcha: '/captchas/new',
+ new_captcha: '/captchas/new', // add
project_settings: '/projects/settings/:id',
captcha_settings: '/captchas/settings/:id',
project: '/projects/:id',