diff --git a/src/app/callback/page.jsx b/src/app/callback/page.jsx new file mode 100644 index 0000000..1bbd7d9 --- /dev/null +++ b/src/app/callback/page.jsx @@ -0,0 +1,31 @@ +'use client'; +import { useEffect } from 'react'; +import { useRouter } from 'next/router'; + +const CallbackPage = () => { + const router = useRouter(); + const { transactionId } = router.query; + + useEffect(() => { + const checkPaymentStatus = async () => { + if (transactionId) { + const response = await fetch('/api/phonepePaymentStatus', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ transactionId }), + }); + const data = await response.json(); + if (data.status === 'SUCCESS') { + alert('Payment successful!'); + } else { + alert('Payment failed. Please try again.'); + } + } + }; + checkPaymentStatus(); + }, [transactionId]); + + return
Processing your payment...
; +}; + +export default CallbackPage; diff --git a/src/app/register/page.jsx b/src/app/register/page.jsx index 7df0a55..b1b254a 100644 --- a/src/app/register/page.jsx +++ b/src/app/register/page.jsx @@ -25,12 +25,12 @@ import { userSchema } from '@/config/zodd/userDetailsSchema'; import { AuthContext } from '@/context/auth-context'; import { REGISTER_ORG } from '@/graphql/mutations/organizationMutations'; import { REGISTER_USER } from '@/graphql/mutations/userMutations'; +import { GET_USER_BY_UID } from '@/graphql/queries/userQueries'; import { useIsLoggedIn } from '@/hooks/useIsLoggedIn'; import { useUserDetails } from '@/hooks/useUserDetails'; import handleLoadingAndToast from '@/utils/handleLoadingToast'; import { uploadToCloudinary } from '@/utils/uploadToCloudinary'; import { useMutation, useSuspenseQuery } from '@apollo/client'; -import { GET_USER_BY_UID } from '@/graphql/queries/userQueries'; import { DisclaimerPara, @@ -301,6 +301,16 @@ function Page() { } const userCookie = Cookies.get('userDataDB'); + const userGoogleData = Cookies.get('userData'); + + if (userGoogleData) { + const googleData = JSON.parse(userGoogleData); + setUserDetails((prev) => ({ + ...prev, + name: googleData.name.toUpperCase(), + email: googleData.email, + })); + } const hasUserData = userDataDB?.user?.data?.length > 0; const userData = hasUserData ? userDataDB.user.data[0] : null; const isNitR = userData?.college === nitrID; diff --git a/src/components/EventsPage/Event/Event.jsx b/src/components/EventsPage/Event/Event.jsx index 101927d..44078d2 100644 --- a/src/components/EventsPage/Event/Event.jsx +++ b/src/components/EventsPage/Event/Event.jsx @@ -19,6 +19,7 @@ const initialState = { uid: null, registered: false, hasPaid: false, + isNitR: false, isCurrentSlideId: 0, }; @@ -49,9 +50,9 @@ export const Events = ({ EventItem }) => { const userData = Cookies.get('userDataDB'); if (userData) { - const { id, hasPaid } = JSON.parse(userData); + const { id, hasPaid, isNitR } = JSON.parse(userData); - setState((prev) => ({ ...prev, uid: id, hasPaid })); + setState((prev) => ({ ...prev, uid: id, hasPaid, isNitR })); } } catch (error) { console.error('Error parsing user data cookie:', error); @@ -115,7 +116,7 @@ export const Events = ({ EventItem }) => { })); try { - if (state.hasPaid) { + if (state.hasPaid || state.isNitR) { const response = await handleLoadingAndToast( registerForEvent({ variables: {