Skip to content

Commit

Permalink
turnstile
Browse files Browse the repository at this point in the history
  • Loading branch information
joleeee committed Apr 10, 2024
1 parent 7e41f4d commit b42bf78
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.exports = withBundleAnalyzer(
STRIPE_PUBLIC_KEY_PROKOM: process.env.STRIPE_PUBLIC_KEY_PROKOM || null,
STRIPE_PUBLIC_KEY_TRIKOM: process.env.STRIPE_PUBLIC_KEY_TRIKOM || null,
RECAPTCHA_PUBLIC_KEY: process.env.RECAPTCHA_PUBLIC_KEY || '',
OW4_DJANGO_TURNSTILE_PUBLIC_KEY: process.env.OW4_DJANGO_TURNSTILE_PUBLIC_KEY || '',
},
redirects,
images: {
Expand Down
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@fortawesome/free-regular-svg-icons": "^5.7.2",
"@fortawesome/free-solid-svg-icons": "^5.7.1",
"@fortawesome/react-fontawesome": "^0.1.4",
"@marsidev/react-turnstile": "^0.5.4",
"@next/bundle-analyzer": "^9.3.4",
"@reduxjs/toolkit": "^1.3.4",
"@sentry/browser": "^5.6.3",
Expand Down Expand Up @@ -101,6 +102,7 @@
"react-select": "^3.0.8",
"react-spring": "^8.0.20",
"react-stripe-elements": "^5.0.1",
"react-turnstile": "^1.1.3",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"sharp": "^0.33.2",
Expand Down
1 change: 1 addition & 0 deletions src/common/constants/turnstile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const OW4_DJANGO_TURNSTILE_PUBLIC_KEY = process.env.OW4_DJANGO_TURNSTILE_PUBLIC_KEY || '';

Check failure on line 1 in src/common/constants/turnstile.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/constants/turnstile.ts#L1

Insert `⏎` (prettier/prettier)
2 changes: 1 addition & 1 deletion src/events/api/attendee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const userAttendEvent = async (
show_as_attending_event: options?.showAsAttending,
allow_pictures: options?.allowPictures,
extras: options?.extras,
recaptcha: captcha,
turnstile: captcha,
},
undefined,
{ user }
Expand Down
2 changes: 1 addition & 1 deletion src/events/components/Attendance/AttendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const AttendButton: FC<IAttendButtonProps> = (props: IAttendButtonProps) => {
}
};
const toggleModal = () => setShowModal(!showModal);
const modal = <CaptchaModal showModal={showModal} toggleModal={toggleModal} setRecaptcha={signUp} />;
const modal = <CaptchaModal showModal={showModal} toggleModal={toggleModal} setCaptcha={signUp} />;
const onConfirmModalClose = (retValue: boolean) => {
setShowConfirmModal(false);

Expand Down
12 changes: 6 additions & 6 deletions src/events/components/Attendance/CaptchaModal.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React, { FC } from 'react';
import { Modal } from '@dotkomonline/design-system';
import ReCAPTCHA from 'react-google-recaptcha';
import { RECAPTCHA_KEY } from 'common/constants/google';
import { OW4_DJANGO_TURNSTILE_PUBLIC_KEY } from 'common/constants/turnstile';
import Turnstile from "react-turnstile";

Check failure on line 4 in src/events/components/Attendance/CaptchaModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint

src/events/components/Attendance/CaptchaModal.tsx#L4

Replace `"react-turnstile"` with `'react-turnstile'` (prettier/prettier)

interface ICaptchaModalProps {
showModal: boolean;
header?: string;
text?: string;
toggleModal: () => void;
setRecaptcha: (token: string | null) => void;
setCaptcha: (token: string | null) => void;
}

const CaptchaModal: FC<ICaptchaModalProps> = (props: ICaptchaModalProps) => {
const { showModal, toggleModal, setRecaptcha, header, text } = props;
const { showModal, toggleModal, setCaptcha, header, text } = props;

const validCaptcha = (token: string | null) => {
if (token) {
setRecaptcha(token);
setCaptcha(token);
toggleModal();
}
//TODO Do something with unvalid token?
Expand All @@ -28,7 +28,7 @@ const CaptchaModal: FC<ICaptchaModalProps> = (props: ICaptchaModalProps) => {
<Modal open={showModal} onClose={toggleModal}>
<h1>{header}</h1>
<p>{text}</p>
<ReCAPTCHA sitekey={RECAPTCHA_KEY} onChange={validCaptcha} />
<Turnstile sitekey={OW4_DJANGO_TURNSTILE_PUBLIC_KEY} onVerify={validCaptcha} />
</Modal>
);
};
Expand Down

0 comments on commit b42bf78

Please sign in to comment.