Commit 0396e588 by Arjun Jhukal

updated the new age gate

parent e2a44554
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import Chatbot from '@/components/atom/ChatbotIcon'; import Chatbot from '@/components/atom/ChatbotIcon';
import DashboardLayout from '@/components/layouts/DashboardLayout'; import DashboardLayout from '@/components/layouts/DashboardLayout';
import AgeVerificationModal from '@/components/organism/dialog'; import AgeVerificationModal from '@/components/organism/dialog';
import AgeGate from '@/components/organism/dialog/AgeGate';
import { useSearchParams } from 'next/navigation'; import { useSearchParams } from 'next/navigation';
import React, { Suspense, useEffect } from 'react'; import React, { Suspense, useEffect } from 'react';
...@@ -22,6 +23,8 @@ function LayoutContent({ children }: { children: React.ReactNode }) { ...@@ -22,6 +23,8 @@ function LayoutContent({ children }: { children: React.ReactNode }) {
{children} {children}
<AgeVerificationModal /> <AgeVerificationModal />
<Chatbot /> <Chatbot />
<AgeGate />
</DashboardLayout> </DashboardLayout>
) )
} }
......
...@@ -5,6 +5,7 @@ import React from 'react' ...@@ -5,6 +5,7 @@ import React from 'react'
export default function PrivateUserLayout({ children }: { children: React.ReactNode }) { export default function PrivateUserLayout({ children }: { children: React.ReactNode }) {
return ( return (
<ServerPrivate> <ServerPrivate>
<DashboardLayout> <DashboardLayout>
{children} {children}
</DashboardLayout> </DashboardLayout>
......
"use client";
import { useGetAgeGateUuidQuery, useVerifyAgeGateMutation } from "@/services/authApi";
import { useCallback, useEffect } from "react";
export default function AgeGate() {
const { data, isSuccess } = useGetAgeGateUuidQuery();
const [verifyAgeGate] = useVerifyAgeGateMutation();
const handleSuccess = useCallback(async (uuid: string) => {
try {
await verifyAgeGate({ age_verify_uuid: uuid }).unwrap();
window.location.reload();
} catch (err) {
console.error("[AgeGate] Backend verification failed:", err);
}
}, [verifyAgeGate]);
console.log("AgeGate data:", data?.data?.age_verify_uuid, "isSuccess:", isSuccess);
useEffect(() => {
if (!isSuccess || !data?.data?.age_verify_uuid) return;
if (data.data.is_age_verified) return;
const uuid = data.data.age_verify_uuid;
// 1. Set config BEFORE loading the script
(window as any).AgeCheckerConfig = {
key: process.env.NEXT_PUBLIC_AGE_CHECKER_KEY,
mode: "manual",
autoload: true,
onready: () => {
(window as any).AgeCheckerAPI.show(uuid);
},
onstatuschanged: (verification: { uuid: string; status: string }) => {
if (verification.status === "accepted") {
handleSuccess(verification.uuid);
}
},
};
// 3. Now load the script
const existing = document.querySelector('script[src*="agechecker.net"]');
if (existing) {
// Script already loaded, just show
(window as any).AgeCheckerAPI?.show(uuid);
return;
}
const script = document.createElement("script");
script.src = "https://cdn.agechecker.net/static/popup/v1/popup.js";
script.crossOrigin = "anonymous";
script.onerror = () => {
window.location.href = "https://agechecker.net/loaderror";
};
document.head.insertBefore(script, document.head.firstChild);
}, [isSuccess, data, handleSuccess]);
return null;
}
\ No newline at end of file
...@@ -165,6 +165,7 @@ export default function RegisterPage() { ...@@ -165,6 +165,7 @@ export default function RegisterPage() {
const cleanedPhone = values.phone.replace(/^0+/, ''); const cleanedPhone = values.phone.replace(/^0+/, '');
const fullPhoneNumber = `${values.country_code}${cleanedPhone}`; const fullPhoneNumber = `${values.country_code}${cleanedPhone}`;
try { try {
const response = await registerUser({ const response = await registerUser({
email: values.emailAddress, email: values.emailAddress,
...@@ -184,10 +185,9 @@ export default function RegisterPage() { ...@@ -184,10 +185,9 @@ export default function RegisterPage() {
visitor_id: userFromPropeelVisitorId || undefined, visitor_id: userFromPropeelVisitorId || undefined,
country_code: '', country_code: '',
}).unwrap(); }).unwrap();
dispatch( dispatch(
showToast({ showToast({
message: response?.data?.message || "User Registerd Successfully", message: response?.message || "User Registerd Successfully",
variant: ToastVariant.SUCCESS, variant: ToastVariant.SUCCESS,
autoTime: true, autoTime: true,
}), }),
......
...@@ -7,7 +7,7 @@ export const authApi = createApi({ ...@@ -7,7 +7,7 @@ export const authApi = createApi({
reducerPath: "authApi", reducerPath: "authApi",
baseQuery: baseQuery, baseQuery: baseQuery,
endpoints: (builder) => ({ endpoints: (builder) => ({
registerUser: builder.mutation<{ success: boolean, data: LoginResponse | null, message: string }, RegisterProps>({ registerUser: builder.mutation<LoginResponse, RegisterProps>({
query: (body) => ({ query: (body) => ({
url: `/api/auth/register`, url: `/api/auth/register`,
method: "POST", method: "POST",
...@@ -63,7 +63,20 @@ export const authApi = createApi({ ...@@ -63,7 +63,20 @@ export const authApi = createApi({
}, },
}) })
}), }),
getAgeGateUuid: builder.query<GlobalResponse & { data: { age_verify_uuid: string, is_age_verified: boolean } }, void>({
query: () => ({
url: `/api/user/age-verify`,
method: "GET",
})
}),
verifyAgeGate: builder.mutation<GlobalResponse, { age_verify_uuid: string }>({
query: ({ age_verify_uuid }) => ({
url: `/api/user/age-verify`,
method: "POST",
body: { age_verify_uuid }
})
})
}) })
}) })
export const { useLoginMutation, useRegisterUserMutation, useSendVerificationLinkAgainMutation, useForgotPasswordMutation, useVerifyOTPMutation, useResetPasswordMutation, useVerifyEmailMutation } = authApi; export const { useLoginMutation, useRegisterUserMutation, useSendVerificationLinkAgainMutation, useForgotPasswordMutation, useVerifyOTPMutation, useResetPasswordMutation, useVerifyEmailMutation, useGetAgeGateUuidQuery, useVerifyAgeGateMutation } = authApi;
\ No newline at end of file \ No newline at end of file
...@@ -25,6 +25,7 @@ export interface LoginResponse { ...@@ -25,6 +25,7 @@ export interface LoginResponse {
access_token: string, access_token: string,
// expires_in: 3600, // expires_in: 3600,
user: User, user: User,
redirection_link: string;
} }
message: string message: string
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment