Skip to content

Commit

Permalink
Add Promoter discount link
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgtz committed Nov 7, 2023
1 parent da5570a commit 8859b2f
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 25 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ const sessionHandleRef = useRef<SessionHandleType>(null)
// For SSO
isCheckingCurrentSession?: boolean
referrerId?: string
}
```
Expand Down Expand Up @@ -2013,7 +2014,7 @@ This is the initial component to show. It will retrieve the tickets, event, pres
Exposes the following functions:
`getTickets` Fetches the tickets from the event set in the config function. It receives a promoCode parameter to apply to the tickets.
`getTickets` Fetches the tickets from the event set in the config function. It receives a promoCode and referrerId parameters to apply to the tickets. PromoCode is higher priority than referrerId
`getEvent` Fetches the event from the eventId set in the config function.
Expand All @@ -2028,7 +2029,7 @@ Exposes the following functions:
```js
{
// Fetches the tickets from the event set in the config function. It receives a promoCode parameter to apply to the tickets.
getTickets(promoCode?: string): Promise<{
getTickets({ promoCode?: string, referredId?: string }): Promise<{
tickets?: {
sortOrder: number
displayTicket?: boolean
Expand Down Expand Up @@ -3052,6 +3053,8 @@ Wrap your component with the Core component.
`deleteAllData` asynchronously deletes all the data stored in the local storage. Use this with caution, only in an edge case.
# Changelog
## Version 1.0.32
- Add `referredId` property to Tickets component and getTickets method.
## Version 1.0.31
- Add missing styles to LoginForm.
## Version 1.0.30
Expand Down
6 changes: 4 additions & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="restlessnites"/>
<data android:scheme="manacommon"/>
<data android:scheme="https" android:host="tickets-staging.manacommon.com" />

</intent-filter>

<intent-filter android:autoVerify="true">
Expand All @@ -36,7 +38,7 @@
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https"
android:host="restlessnites.com"
android:host="tickets-staging.manacommon.com"
android:pathPrefix="/reset-password" />
</intent-filter>

Expand Down
4 changes: 2 additions & 2 deletions example/ios/example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>restlessnites</string>
<string>tickets-staging.manacommon.com</string>
<key>CFBundleURLSchemes</key>
<array>
<string>restlessnites</string>
<string>tickets-staging.manacommon.com</string>
</array>
</dict>
</array>
Expand Down
45 changes: 34 additions & 11 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface IDeepLinkUrl {
url: string
}

const EVENT_ID = 13090
const EVENT_ID = 13369

const config: IConfig = {
EVENT_ID: EVENT_ID,
Expand All @@ -48,6 +48,8 @@ const config: IConfig = {

const App = () => {
const resetPasswordTokenRef = useRef('')
const isAppLoaded = useRef<null | boolean>(null)

const billingRef = useRef<SessionHandleType>(null)
const ticketsRef = useRef<SessionHandleType>(null)

Expand All @@ -60,6 +62,7 @@ const App = () => {
)

//#region Loadings
const [referredId, setReferredId] = useState<undefined | string>(undefined)
const [isCheckingCurrentSession, setIsCheckingCurrentSession] = useState(true)
const [isLoading, setIsLoading] = useState(false)
const [skippingStatus, setSkippingStatus] = useState<SkippingStatusType>(undefined)
Expand All @@ -79,8 +82,9 @@ const App = () => {
const [isTicketToSellActive, setIsTicketToSellActive] = useState<
boolean | undefined
>(undefined)

const resetData = () => {
console.log('%cApp.tsx line:85 Reseting data', 'color: white; background-color: #FF0000;');
setCartProps(undefined)
setIsLoading(false)
setSkippingStatus(undefined)
Expand Down Expand Up @@ -152,31 +156,43 @@ const App = () => {
}

//#endregion
const handleOpenUrl = ({url}: IDeepLinkUrl) =>{
const splitted = url.split("token=")
if (splitted.length <= 1) {
return
}
const handleOpenUrl = ({url}: IDeepLinkUrl) => {
console.log('=== Deep link ===', url)

const resetPasswordToken = url.split("token=")

console.log('%cApp.tsx line:160 resetPasswordToken', 'color: #007acc;', resetPasswordToken);

if (splitted[1]) {
resetPasswordTokenRef.current = splitted[1]
if (resetPasswordToken[1]) {
resetPasswordTokenRef.current = resetPasswordToken[1]
setComponentToShow(ComponentEnum.ResetPassword)
}

const referrerId = url.split("ttf_r=")
console.log('%cApp.tsx line:160 resetPasswordToken', 'color: #00FFcc;', referrerId);

if (referrerId[1]) {
setReferredId(referrerId[1])
resetData()
ticketsRef.current?.reloadData()
}

}

const getInitialURL = async () => {
console.log('getInitialURL')
const initialUrl = await Linking.getInitialURL();
console.log('initialUrl', initialUrl)
if (initialUrl === null) {
return;
}

return initialUrl
return handleOpenUrl({url: initialUrl})
}

//#region effects
useEffect(() => {

console.log('initial useEffect')
setTimeout(() => { ticketsRef.current?.refreshAccessToken() }, 2000)
const setConfigAsync = async () => {
setIsCheckingCurrentSession(true)
Expand All @@ -186,8 +202,10 @@ const App = () => {

setConfigAsync()
Linking.addEventListener('url', handleOpenUrl)
isAppLoaded.current = true

return () => {
console.log('Removing all event listeners')
Linking.removeAllListeners('url')
}
}, [])
Expand Down Expand Up @@ -219,6 +237,10 @@ const App = () => {
}, [selectedOrderDetails])
//#endregion

if (!isAppLoaded.current) {
getInitialURL()
}

const RenderComponent = () => {
switch (componentToShow) {
case ComponentEnum.BillingInfo:
Expand Down Expand Up @@ -925,6 +947,7 @@ const App = () => {
<View style={{ flex: 1 }}>
<Tickets
ref={ticketsRef}
referrerId={referredId}
config={{
areTicketsGrouped: true,
}}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "tf-checkout-react-native",
"version": "1.0.31",
"version": "1.0.32",
"description": "TheTicketFairy ReactNative Checkout library",
"homepage": "https://github.com/theticketfairy/tf-checkout-react-native",
"main": "lib/index.js",
"main": "src/index.tsx",
"types": "lib/index.d.ts",
"author": "TheTicketFairy <dev.jorgtz@gmail.com>",
"license": "MIT",
Expand Down
26 changes: 21 additions & 5 deletions src/api/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
ICountriesResponse,
IEventResponse,
IFetchAccessTokenResponse,
IFetchTicketsParams,
IFetchTicketsResponse,
IFreeRegistrationData,
IFreeRegistrationResponse,
Expand Down Expand Up @@ -563,9 +564,11 @@ export const fetchOrderDetails = async (
//#endregion

//#region Tickets
export const fetchTickets = async (
promoCode?: string
): Promise<IFetchTicketsResponse> => {
// PromoCode higher priority than ReferredId
export const fetchTickets = async ({
promoCode,
referredId,
}: IFetchTicketsParams): Promise<IFetchTicketsResponse> => {
if (!Config.EVENT_ID) {
return {
error: {
Expand All @@ -578,17 +581,30 @@ export const fetchTickets = async (
const headers = {
'Promotion-Event': eventId,
'Promotion-Code': promoCode,
'Referrer-Id': referredId,
}

let responseError

if (!referredId) {
delete headers['Referrer-Id']
}

if (!promoCode) {
//@ts-ignore
delete headers['Promotion-Event']
//@ts-ignore
delete headers['Promotion-Code']
}

if (!promoCode && !referredId) {
//@ts-ignore
delete headers['Promotion-Event']
}

// If there are promoCode and referredId, then we need to remove the Referrer-Id header
if (promoCode && referredId && headers['Referrer-Id']) {
delete headers['Referrer-Id']
}

const response = await Client.get(`v1/event/${eventId}/tickets/`, {
//@ts-ignore
headers: headers,
Expand Down
5 changes: 5 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export interface IPromoCodeResponse {
message: string
}

export interface IFetchTicketsParams {
promoCode?: string
referredId?: string
}

export interface IFetchTicketsResponse {
error?: IError
isAccessCodeRequired?: boolean
Expand Down
2 changes: 2 additions & 0 deletions src/containers/tickets/Tickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const Tickets = forwardRef<SessionHandleType, ITicketsProps>(
areAlertsEnabled: true,
areTicketsSortedBySoldOut: true,
},
referrerId,
},
ref
) => {
Expand Down Expand Up @@ -141,6 +142,7 @@ const Tickets = forwardRef<SessionHandleType, ITicketsProps>(
}

return await ticketsCoreRef.current.getTickets({
referredId: referrerId,
promoCode,
areTicketsSortedBySoldOut: config.areTicketsSortedBySoldOut,
areTicketsGrouped: config.areTicketsGrouped,
Expand Down
2 changes: 2 additions & 0 deletions src/containers/tickets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export interface ITicketsProps {
isPromoEnabled?: boolean
isAccessCodeEnabled?: boolean

referrerId?: string

onPressMyOrders: () => void
onPressLogout?: () => void

Expand Down
7 changes: 6 additions & 1 deletion src/core/TicketsCore/TicketsCore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const TicketsCore = forwardRef<TicketsCoreHandle, ICoreProps>((props, ref) => {
promoCode,
areTicketsSortedBySoldOut,
areTicketsGrouped,
referredId,
}: IGetTicketsOptions): Promise<IGetTicketsPayload> {
const groupTickets = (tickets: ITicket[]) => {
// Create an array of tickets with the GroupName set
Expand All @@ -70,8 +71,12 @@ const TicketsCore = forwardRef<TicketsCoreHandle, ICoreProps>((props, ref) => {

return ticketsSections
}
// PromoCode higher priority than ReferredId

const ticketsResponse = await fetchTickets(promoCode)
const ticketsResponse = await fetchTickets({
promoCode: promoCode,
referredId: referredId,
})

if (ticketsResponse.error || !ticketsResponse.tickets) {
return ticketsResponse
Expand Down
1 change: 1 addition & 0 deletions src/core/TicketsCore/TicketsCoreTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IGetTicketsOptions {
areTicketsSortedBySoldOut?: boolean
areTicketsGrouped?: boolean
promoCode?: string
referredId?: string
}

export interface IGroupedTickets {
Expand Down

0 comments on commit 8859b2f

Please sign in to comment.