From 2c93384aed5c19dcf46515ddeacb82c08e1a7bd4 Mon Sep 17 00:00:00 2001 From: ayussh-2 Date: Fri, 12 Jul 2024 03:51:38 +0530 Subject: [PATCH] chore: add check of srcID to filter paid users --- src/components/events/EventCard.jsx | 15 +++++-- src/components/events/Events.jsx | 10 ++++- src/components/events/EventsWrapper.jsx | 7 +++- .../events/IndividualEventModal.jsx | 14 +++++-- src/components/events/Register2Modal.jsx | 8 +++- src/components/events/TeamEventModal.jsx | 8 ++-- .../marginals/Nav_Hero/Description.jsx | 40 ++++++++++++++++--- .../Nav_Hero/ProfileMenuDropDown.jsx | 14 ++++--- 8 files changed, 91 insertions(+), 25 deletions(-) diff --git a/src/components/events/EventCard.jsx b/src/components/events/EventCard.jsx index 82201c7..047179e 100644 --- a/src/components/events/EventCard.jsx +++ b/src/components/events/EventCard.jsx @@ -36,7 +36,8 @@ EventCard.propTypes = { handleSelectEvent: PropTypes.func, handleRegisterEvent: PropTypes.func, registeredEvent: PropTypes.any, - mongoId: PropTypes.string + mongoId: PropTypes.string, + userSrcId: PropTypes.string } export default function EventCard({ @@ -44,7 +45,8 @@ export default function EventCard({ handleSelectEvent, handleRegisterEvent, registeredEvent, - mongoId + mongoId, + userSrcId }) { const [openModal, setOpenModal] = useState(false) function genDetails(str, length) { @@ -66,9 +68,15 @@ export default function EventCard({ function handleClick(id) { if (!mongoId) { - toast.error('Please login to register for the event') + toast.info('Please complete your profile to register for the event') return } + + if (!userSrcId) { + toast.info('Please complete your payment to register for the event') + return + } + handleRegisterEvent(id) } @@ -120,6 +128,7 @@ export default function EventCard({ + Rulebook {!registeredEvent ? ( diff --git a/src/components/events/Events.jsx b/src/components/events/Events.jsx index c1e63cc..237a15d 100644 --- a/src/components/events/Events.jsx +++ b/src/components/events/Events.jsx @@ -24,6 +24,7 @@ export default function Events() { const [event, setEvent] = useState(null) const [events, setEvents] = useState([]) const [mongoId, setMongoId] = useState(null) + const [userSrcId, setUserSrcId] = useState(null) const [soloRegistration, setSoloRegistration] = useState([]) const [teamRegistration, setTeamRegistration] = useState([]) const [combinedRegistrations, setCombinedRegistrations] = useState([]) @@ -64,6 +65,7 @@ export default function Events() { if (userDataInDb) { setMongoId(userDataInDb?.getUser?.id) + setUserSrcId(userDataInDb?.getUser?.srcID) } if (soloRegistrations) { setSoloRegistration(soloRegistrations?.eventRegistration) @@ -161,7 +163,12 @@ export default function Events() { )} {createPortal( isRegisterModalOpen && ( - + ), overlay )} @@ -183,6 +190,7 @@ export default function Events() { handlerFlagshipEvent={handleFlagshipCardModalOpen} swiperRef={swiperRef} mongoId={mongoId} + userSrcId={userSrcId} /> diff --git a/src/components/events/EventsWrapper.jsx b/src/components/events/EventsWrapper.jsx index 064bb3d..96e3f06 100644 --- a/src/components/events/EventsWrapper.jsx +++ b/src/components/events/EventsWrapper.jsx @@ -15,7 +15,8 @@ function EventsWrapper({ swiperRef, handleRegisterEvent, handlerFlagshipEvent, - mongoId + mongoId, + userSrcId }) { useEffect(() => { if (swiperRef.current) { @@ -65,6 +66,7 @@ function EventsWrapper({ handleSelectEvent={handleSelectEvent} handleRegisterEvent={handleRegisterEvent} mongoId={mongoId} + userSrcId={userSrcId} /> ) @@ -85,7 +87,8 @@ EventsWrapper.propTypes = { handlerFlagshipEvent: PropTypes.func.isRequired, swiperRef: PropTypes.object.isRequired, combinedArray: PropTypes.array, - mongoId: PropTypes.string + mongoId: PropTypes.string, + userSrcId: PropTypes.string } export default EventsWrapper diff --git a/src/components/events/IndividualEventModal.jsx b/src/components/events/IndividualEventModal.jsx index e6b3a2c..c7f2f64 100644 --- a/src/components/events/IndividualEventModal.jsx +++ b/src/components/events/IndividualEventModal.jsx @@ -22,8 +22,15 @@ import { } from './teamRegistrationModal' import { RegistrationSchema } from '../../config/content/teamRegistration/registerSchema' -export const IndiEventModal = ({ EventId, EventTitle, mongoId, hasPdfUpload, handleScroll }) => { - const [aicheID, setAicheID] = useState('') +export const IndiEventModal = ({ + EventId, + EventTitle, + mongoId, + hasPdfUpload, + handleScroll, + userSrcId +}) => { + const [aicheID, setAicheID] = useState(userSrcId) const [show, setShow] = useState(true) const [error, setError] = useState(null) const [pdf, setPdf] = useState(null) @@ -177,5 +184,6 @@ IndiEventModal.propTypes = { closeRegisterModal: PropTypes.func, mongoId: PropTypes.string, hasPdfUpload: PropTypes.bool, - handleScroll: PropTypes.func + handleScroll: PropTypes.func, + userSrcId: PropTypes.string } diff --git a/src/components/events/Register2Modal.jsx b/src/components/events/Register2Modal.jsx index 66d4a9d..53b3b5f 100644 --- a/src/components/events/Register2Modal.jsx +++ b/src/components/events/Register2Modal.jsx @@ -9,7 +9,8 @@ import { ProgressBar } from './eventModal.styles' export const RegisterModal = ({ event: { id, name, isTeamEvent, maxTeamSize }, closeModal, - mongoId + mongoId, + userSrcId }) => { const [scrollPosition, setScrollPosition] = useState(0) @@ -34,6 +35,7 @@ export const RegisterModal = ({ mongoId={mongoId} maxTeamSize={maxTeamSize} hasPdfUpload={hasPdfUpload} + userSrcId={userSrcId} /> ) : ( )} @@ -58,5 +61,6 @@ RegisterModal.propTypes = { maxTeamSize: PropTypes.number }), closeModal: PropTypes.func, - mongoId: PropTypes.string + mongoId: PropTypes.string, + userSrcId: PropTypes.string } diff --git a/src/components/events/TeamEventModal.jsx b/src/components/events/TeamEventModal.jsx index 004b914..6de8713 100644 --- a/src/components/events/TeamEventModal.jsx +++ b/src/components/events/TeamEventModal.jsx @@ -34,11 +34,12 @@ export const TeamEventModal = ({ maxTeamSize, hasPdfUpload, mongoId, - handleScroll + handleScroll, + userSrcId }) => { const [formData, setFormData] = useState({ teamname: '', - teamleadid: '', + teamleadid: userSrcId, userIds: [''] }) @@ -267,7 +268,8 @@ TeamEventModal.propTypes = { hasPdfUpload: PropTypes.bool, mongoId: PropTypes.string, maxTeamSize: PropTypes.number, - handleScroll: PropTypes.func + handleScroll: PropTypes.func, + userSrcId: PropTypes.string } export default TeamEventModal diff --git a/src/components/marginals/Nav_Hero/Description.jsx b/src/components/marginals/Nav_Hero/Description.jsx index 7ba50a9..821ce4b 100644 --- a/src/components/marginals/Nav_Hero/Description.jsx +++ b/src/components/marginals/Nav_Hero/Description.jsx @@ -12,9 +12,37 @@ import { ButtonWrapper } from './Description.styles' import { useContext } from 'react' import { AuthContext } from '../../../context/AuthContext' import { Link } from 'react-router-dom' +import { useQuery } from '@apollo/client' +import { GET_USER_BY_ID } from '../../../graphQL/queries/userQueries' +import { useEffect, useState } from 'react' const Description = () => { + const orgId = '668bd9deff0327a608b9b6ea' const { userInfo } = useContext(AuthContext) + const [uid, setUid] = useState(null) + const [user, setUser] = useState(null) + const { refetch: refetchUser } = useQuery(GET_USER_BY_ID, { + variables: { uid: uid, orgId }, + skip: true + }) + + useEffect(() => { + if (userInfo.uid) { + setUid(userInfo.uid) + getUserData() + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [userInfo, uid]) + + async function getUserData() { + try { + const { data } = await refetchUser({ uid: userInfo.uid, orgId }) + setUser(data.getUser) + } catch (err) { + console.log('Error fetching user data', err) + // console.log('Error fetching user data', err) + } + } function redirect() { window.open(DescriptionContent.brochureLink, '_blank') @@ -27,11 +55,13 @@ const Description = () => { {DescriptionContent.HeroButton} {userInfo.name ? ( - - - Pay Now - - + !user?.srcID && ( + + + Pay Now + + + ) ) : ( {DescriptionContent.RegisterButton} diff --git a/src/components/marginals/Nav_Hero/ProfileMenuDropDown.jsx b/src/components/marginals/Nav_Hero/ProfileMenuDropDown.jsx index dbfc3ec..f53db34 100644 --- a/src/components/marginals/Nav_Hero/ProfileMenuDropDown.jsx +++ b/src/components/marginals/Nav_Hero/ProfileMenuDropDown.jsx @@ -50,12 +50,14 @@ function ProfileMenuDropDown({ setProfileOpen, user }) { {detail.value} ))} - - - {' '} - Pay Now - - + {!user.srcID && ( + + + {' '} + Pay Now + + + )} Logout ) : (