Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add check of srcID to filter paid users #97

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/components/events/EventCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ EventCard.propTypes = {
handleSelectEvent: PropTypes.func,
handleRegisterEvent: PropTypes.func,
registeredEvent: PropTypes.any,
mongoId: PropTypes.string
mongoId: PropTypes.string,
userSrcId: PropTypes.string
}

export default function EventCard({
event: { poster, id, name, subHeading, description, rules, isTeamEvent },
handleSelectEvent,
handleRegisterEvent,
registeredEvent,
mongoId
mongoId,
userSrcId
}) {
const [openModal, setOpenModal] = useState(false)
function genDetails(str, length) {
Expand All @@ -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)
}

Expand Down Expand Up @@ -120,6 +128,7 @@ export default function EventCard({
<SeemoreIcon src={seeMoreIcon} />
</CardModalBtn>
</CardBody>

<CardFooter>
<ButtonRules onClick={redirectToRules}>Rulebook</ButtonRules>
{!registeredEvent ? (
Expand Down
10 changes: 9 additions & 1 deletion src/components/events/Events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand Down Expand Up @@ -64,6 +65,7 @@ export default function Events() {

if (userDataInDb) {
setMongoId(userDataInDb?.getUser?.id)
setUserSrcId(userDataInDb?.getUser?.srcID)
}
if (soloRegistrations) {
setSoloRegistration(soloRegistrations?.eventRegistration)
Expand Down Expand Up @@ -161,7 +163,12 @@ export default function Events() {
)}
{createPortal(
isRegisterModalOpen && (
<RegisterModal mongoId={mongoId} closeModal={handleRegisterModalClose} event={event} />
<RegisterModal
mongoId={mongoId}
closeModal={handleRegisterModalClose}
userSrcId={userSrcId}
event={event}
/>
),
overlay
)}
Expand All @@ -183,6 +190,7 @@ export default function Events() {
handlerFlagshipEvent={handleFlagshipCardModalOpen}
swiperRef={swiperRef}
mongoId={mongoId}
userSrcId={userSrcId}
/>
<Arrow src={nextArrowIcon} alt="Next" onClick={handleNext} />
</Section>
Expand Down
7 changes: 5 additions & 2 deletions src/components/events/EventsWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function EventsWrapper({
swiperRef,
handleRegisterEvent,
handlerFlagshipEvent,
mongoId
mongoId,
userSrcId
}) {
useEffect(() => {
if (swiperRef.current) {
Expand Down Expand Up @@ -65,6 +66,7 @@ function EventsWrapper({
handleSelectEvent={handleSelectEvent}
handleRegisterEvent={handleRegisterEvent}
mongoId={mongoId}
userSrcId={userSrcId}
/>
</SwiperSlide>
)
Expand All @@ -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
14 changes: 11 additions & 3 deletions src/components/events/IndividualEventModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -177,5 +184,6 @@ IndiEventModal.propTypes = {
closeRegisterModal: PropTypes.func,
mongoId: PropTypes.string,
hasPdfUpload: PropTypes.bool,
handleScroll: PropTypes.func
handleScroll: PropTypes.func,
userSrcId: PropTypes.string
}
8 changes: 6 additions & 2 deletions src/components/events/Register2Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -34,6 +35,7 @@ export const RegisterModal = ({
mongoId={mongoId}
maxTeamSize={maxTeamSize}
hasPdfUpload={hasPdfUpload}
userSrcId={userSrcId}
/>
) : (
<IndiEventModal
Expand All @@ -43,6 +45,7 @@ export const RegisterModal = ({
mongoId={mongoId}
maxTeamSize={maxTeamSize}
hasPdfUpload={hasPdfUpload}
userSrcId={userSrcId}
/>
)}
</Section>
Expand All @@ -58,5 +61,6 @@ RegisterModal.propTypes = {
maxTeamSize: PropTypes.number
}),
closeModal: PropTypes.func,
mongoId: PropTypes.string
mongoId: PropTypes.string,
userSrcId: PropTypes.string
}
8 changes: 5 additions & 3 deletions src/components/events/TeamEventModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ export const TeamEventModal = ({
maxTeamSize,
hasPdfUpload,
mongoId,
handleScroll
handleScroll,
userSrcId
}) => {
const [formData, setFormData] = useState({
teamname: '',
teamleadid: '',
teamleadid: userSrcId,
userIds: ['']
})

Expand Down Expand Up @@ -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
40 changes: 35 additions & 5 deletions src/components/marginals/Nav_Hero/Description.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -27,11 +55,13 @@ const Description = () => {
<ButtonContainer>
<HelpButton onClick={redirect}>{DescriptionContent.HeroButton}</HelpButton>
{userInfo.name ? (
<PaymentButton>
<Link target="_blank" to={DescriptionContent.paymentLink}>
Pay Now
</Link>
</PaymentButton>
!user?.srcID && (
<PaymentButton>
<Link target="_blank" to={DescriptionContent.paymentLink}>
Pay Now
</Link>
</PaymentButton>
)
) : (
<Link to="/register">
<RegisterButton>{DescriptionContent.RegisterButton}</RegisterButton>
Expand Down
14 changes: 8 additions & 6 deletions src/components/marginals/Nav_Hero/ProfileMenuDropDown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ function ProfileMenuDropDown({ setProfileOpen, user }) {
<Label>{detail.label}:</Label> <Value>{detail.value}</Value>
</ProfileDropDownItem>
))}
<PaymentButton>
<Link target="_blank" to={DescriptionContent.paymentLink}>
{' '}
Pay Now
</Link>
</PaymentButton>
{!user.srcID && (
<PaymentButton>
<Link target="_blank" to={DescriptionContent.paymentLink}>
{' '}
Pay Now
</Link>
</PaymentButton>
)}
<LogoutButton onClick={logout}>Logout</LogoutButton>
</>
) : (
Expand Down
Loading