-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15a4758
commit a884493
Showing
9 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
VITE_PROJECT_ID=aa1989b48f2f9f37e9e29811f97d58af | ||
VITE_IS_MAINTENANCE = 0 | ||
VITE_MAINTENANCE_TIPS = 'The website is currently undergoing maintenance to add support for Phase II Upgrading.' | ||
|
||
VITE_SITE_KEY="6LcfgBYqAAAAAMWveYEvnQQFNg33AU71GBj60Rwl" | ||
VITE_SECRET_KEY="6LcfgBYqAAAAAHCFhPK_oiBKNts8JXKRMh9auxxr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useReCaptchaStore } from "@/hooks/useReCaptchaStore"; | ||
import { useEffect, useState } from "react"; | ||
|
||
interface GoogleRecaptchaProps { | ||
onSuccess?: () => void; | ||
} | ||
|
||
export default function GoogleRecaptcha({ onSuccess }: GoogleRecaptchaProps) { | ||
const [grecaptchaId, setGrecaptchaId] = useState<any>(null); | ||
const [isRecaptchaLoad, setIsRecaptchaLoad] = useState(true); | ||
|
||
const { setReCaptchaTs, setReCaptchaValue } = useReCaptchaStore(); | ||
|
||
const onChange = (value: string) => { | ||
console.log("Captcha value:", value); | ||
const ts = Date.now(); | ||
setReCaptchaValue(value); | ||
setReCaptchaTs(ts); | ||
onSuccess?.(); | ||
}; | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
const grecaptcha = (window as any)?.grecaptcha?.render("robot", { | ||
sitekey: "6LcfgBYqAAAAAMWveYEvnQQFNg33AU71GBj60Rwl", | ||
theme: "light", | ||
size: "normal", | ||
callback: onChange, | ||
}); | ||
// console.log('grecaptcha', grecaptcha) | ||
setGrecaptchaId(grecaptcha); | ||
if (!grecaptcha && grecaptcha !== 0) { | ||
setIsRecaptchaLoad(false); | ||
} else { | ||
setIsRecaptchaLoad(true); | ||
} | ||
}, 1000); | ||
}, []); | ||
return ( | ||
<div className="min-w-[304px] min-h-[78px] bg-[#fff] flex justify-center items-center"> | ||
<div id="robot"></div> | ||
{!isRecaptchaLoad && ( | ||
<div className="text-[#000] text-[16px]"> | ||
Due to your internet cannot access Google reCAPTCHA service, we can't | ||
verify if you're human or bot. Please check your internet setting. | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { create } from "zustand"; | ||
import { persist } from "zustand/middleware"; | ||
|
||
export type ReCaptchaStore = { | ||
reCaptchaValue: string; | ||
reCaptchaTs: number; | ||
setReCaptchaValue: (reCaptchaValue: string) => void; | ||
setReCaptchaTs: (reCaptchaTs: number) => void; | ||
}; | ||
|
||
export const useReCaptchaStore = create<ReCaptchaStore>()( | ||
persist( | ||
(set, get) => ({ | ||
reCaptchaValue: "", | ||
reCaptchaTs: 0, | ||
setReCaptchaValue: (reCaptchaValue: string) => { | ||
set({ reCaptchaValue }); | ||
}, | ||
setReCaptchaTs: (reCaptchaTs: number) => { | ||
set({ reCaptchaTs }); | ||
}, | ||
}), | ||
{ | ||
name: "ReCaptchaStore", | ||
} | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters