Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into payment
  • Loading branch information
Srish-ty committed Nov 3, 2024
2 parents 54f3dc9 + c55adf3 commit 27d0c17
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
31 changes: 31 additions & 0 deletions src/app/callback/page.jsx
Original file line number Diff line number Diff line change
@@ -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 <div>Processing your payment...</div>;
};

export default CallbackPage;
12 changes: 11 additions & 1 deletion src/app/register/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/components/EventsPage/Event/Event.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const initialState = {
uid: null,
registered: false,
hasPaid: false,
isNitR: false,
isCurrentSlideId: 0,
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -115,7 +116,7 @@ export const Events = ({ EventItem }) => {
}));

try {
if (state.hasPaid) {
if (state.hasPaid || state.isNitR) {
const response = await handleLoadingAndToast(
registerForEvent({
variables: {
Expand Down

0 comments on commit 27d0c17

Please sign in to comment.