Skip to content

Commit

Permalink
Merge pull request #51 from theticketfairy/feat/TTF-8973-add-promoter…
Browse files Browse the repository at this point in the history
…-discount-link

Add Promoter discount link
  • Loading branch information
jorgtz authored Dec 8, 2023
2 parents da5570a + 6e08735 commit 9e9eadd
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 25 deletions.
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ const sessionHandleRef = useRef<SessionHandleType>(null)
// For SSO
isCheckingCurrentSession?: boolean
// Referral discounts
referrerId?: string
}
```
Expand Down Expand Up @@ -2013,7 +2016,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 +2031,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 @@ -3051,10 +3054,23 @@ 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. This will apply special prices fo the passed `refferentId` property.
## Version 1.0.31
- Add missing styles to LoginForm.
## Version 1.0.30
- Show errors in Billing UI form fields.
- Add config prop to Billing UI component, includes 2 configuration flags.
```
Expand All @@ -3066,6 +3082,8 @@ Wrap your component with the Core component.
- Replacing `"rn-material-ui-textfield": "1.0.5"` library with `"rn-material-ui-textfield": "jorgtz/rn-material-ui-textfield"`, make sure to replace it in all the package.json files.
## Version 1.0.29
- Update Stripe SDK to version 0.26.0.
Expand All @@ -3090,7 +3108,9 @@ Wrap your component with the Core component.
## Version 1.0.28
- Add `getAccountTickets` request in `MyOrdersCore` and `TicketsCore`, it will allow get Tickets from the logged-in user.
- Add filter to `getMyOrders` request in `MyOrdersCore` component, to filter by time frame by passing the following string:
Expand All @@ -3102,7 +3122,10 @@ Wrap your component with the Core component.
- Add more data to the `getOrderDetails` success response.
- Add `ticketsSold` prop to Event's object in fetchEvent success data.
## Version 1.0.27
- Make `EVENT_ID` optional in the `setConfig` function. An error will be returned when `EVENT_ID` is not set and trying to make a request that requires it.
- Remove `eventId` prop from `Checkout UI` component in favor of use the one on the Config.
Expand All @@ -3111,7 +3134,10 @@ Wrap your component with the Core component.
- Add missing success data in `onFetchOrderDetailsSuccess` response.
## Version 1.0.26
- Add the possibility to remove all of the following Billing/Street Address fields from free tickets:
- Billing Street Address
- City
Expand All @@ -3125,7 +3151,10 @@ isTicketFree?: boolean
isPhoneHidden?: boolean
```
## Version 1.0.25
- Exposes `refreshAccessToken` function.
- Changed returned `data` prop to `userProfile` in LoginCore response.
- In **LoginCore Component**:
Expand All @@ -3140,7 +3169,10 @@ isPhoneHidden?: boolean
- Export function `refreshAccessToken`
- Add `reloadData` to re-fetch servers data in UI components.
## Version 1.0.24
- Add **SingleSignOn** feature.
- Add show Tickets in groups and the option to sort them by sold out.
- Add config prop to Tickets component:
Expand All @@ -3160,14 +3192,22 @@ isPhoneHidden?: boolean
- Added `styles` and `texts` props for TTF Privacy Policy checkbox.
- Added **Password Protected** event feature.
## Version 1.0.23
- Fix Checkout not allowing free registrations
## Version 1.0.22
- Added cartTimer component, that will show the cart's remaining expiration time in the Billing screen.
- setConfig not longer receives the `DOMAIN` prop, instead it receives the `CLIENT`
- Added a three dot button to my orders to show the possible actions.
8 changes: 6 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,11 @@
<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="http" />
<data android:scheme="https" />
<data android:host="tickets-staging.manacommon.com" />
</intent-filter>

<intent-filter android:autoVerify="true">
Expand All @@ -36,7 +40,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
Loading

0 comments on commit 9e9eadd

Please sign in to comment.