Skip to content

Commit

Permalink
feat: 🎸 add default recaptcha
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian-potter committed Jun 7, 2024
1 parent 722d162 commit 6610428
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/app/recaptcha/page.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
"use client";
import React, { useEffect, useMemo } from "react";
import GoogleReCaptcha from "src/components/GoogleReCaptcha";
import { BaseReCaptcha } from "src/components/GoogleReCaptcha/types";
import { useSendMessageByIframe } from "src/hooks/iframe";
import { TSearch } from "src/types";
import "./index.css";
'use client';
import React, { useEffect, useMemo } from 'react';
import GoogleReCaptcha from 'src/components/GoogleReCaptcha';
import { BaseReCaptcha } from 'src/components/GoogleReCaptcha/types';
import { useSendMessageByIframe } from 'src/hooks/iframe';
import { TSearch } from 'src/types';
import './index.css';

export default function Recaptcha({
searchParams = {},
}: {
searchParams: TSearch;
}) {
export default function Recaptcha({ searchParams = {} }: { searchParams: TSearch }) {
const { onSuccess } = useSendMessageByIframe({
target: "@portkey/ui-did-react:ReCaptcha",
target: '@portkey/ui-did-react:ReCaptcha',
});

const {
theme = "light",
siteKey,
size = "normal",
theme = 'light',
siteKey = '6LfR_bElAAAAAJSOBuxle4dCFaciuu9zfxRQfQC0',
size = 'normal',
} = useMemo(() => {
return searchParams as Omit<BaseReCaptcha, "customReCaptchaHandler">;
return searchParams as Omit<BaseReCaptcha, 'customReCaptchaHandler'>;
}, [searchParams]);

useEffect(() => {
document.body.classList.add("recaptcha-body");
document.body.classList.add('recaptcha-body');
}, []);

return (
<div className="h-screen flex justify-center items-center">
{siteKey ? (
<GoogleReCaptcha
theme={theme || "light"}
size={size || "normal"}
theme={theme || 'light'}
size={size || 'normal'}
siteKey={siteKey}
onSuccess={(res) => {
onSuccess({
type: "PortkeyReCaptchaOnSuccess",
type: 'PortkeyReCaptchaOnSuccess',
data: res,
});
}}
onError={(res) => {
console.log(res, "onError");
console.log(res, 'onError');
}}
onExpire={(err) => {
console.log(err, "onExpire");
console.log(err, 'onExpire');
}}
/>
) : (
"Invalid siteKey"
'Invalid siteKey'
)}
</div>
);
Expand Down

0 comments on commit 6610428

Please sign in to comment.