Skip to content

Commit

Permalink
Merge pull request #39 from theticketfairy/dev
Browse files Browse the repository at this point in the history
Make EVENT_ID optional.
  • Loading branch information
jorgtz authored Mar 1, 2023
2 parents 960d59f + 1ac83e8 commit 2ad8181
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 38 deletions.
95 changes: 82 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const YourComponent: FC () => {
````ts
{
EVENT_ID: string,
EVENT_ID?: string | number,
CLIENT?: string,
ENV?: 'PROD' | 'DEV' | 'STAG',
CLIENT_ID?: string,
Expand Down Expand Up @@ -594,7 +594,6 @@ const sessionHandleRef = useRef<SessionHandleType>(null)
<Tickets
ref={sessionHandleRef}
eventId={EVENT_ID}
onAddToCartSuccess={handleOnAddToCartSuccess} />
```
Expand Down Expand Up @@ -1120,7 +1119,6 @@ const sessionHandleRef = useRef<SessionHandleType>(null)

<Checkout
ref={sessionHandleRef}
eventId={EVENT_ID}
hash={hash}
total={total}
onPaymentSuccess={handleOnPaymentSuccess}
Expand All @@ -1136,7 +1134,6 @@ const sessionHandleRef = useRef<SessionHandleType>(null)
```js
{
ref?: SessionHandleType
eventId: number
hash: string
total: string

Expand Down Expand Up @@ -1190,7 +1187,6 @@ const sessionHandleRef = useRef<SessionHandleType>(null)
```
| Property | Description |
|----------|-------------|
| eventId | Same as used in the `Tickets` component. |
| hash | retrieved from the `onCheckoutSuccess` callback in the `BillingInfo`component. |
| total | retrieved from the `onCheckoutSuccess` callback in the `BillingInfo` component. |
| onPaymentSuccess | will handle the success in the payment process. Will return the `hash`. |
Expand All @@ -1201,7 +1197,7 @@ const sessionHandleRef = useRef<SessionHandleType>(null)
### styles
```js
```ts
{
rootStyle?: ViewStyle
title?: StyleProp<TextStyle>
Expand Down Expand Up @@ -1252,7 +1248,7 @@ import { PurchaseConfirmation, SessionHandleType } from 'tf-checkout-react-nativ
Add it to the render function.
```js
```ts
const sessionHandleRef = useRef<SessionHandleType>(null)

<PurchaseConfirmation
Expand Down Expand Up @@ -1308,7 +1304,7 @@ import { MyOrders, SessionHandleType } from 'tf-checkout-react-native'
### Props
```tsx
```ts
{
ref={SessionHandleType}
onSelectOrder: (order: {
Expand Down Expand Up @@ -1349,10 +1345,10 @@ import { MyOrders, SessionHandleType } from 'tf-checkout-react-native'
}
}) => void

onFetchMyOrdersSuccess?: () => void
onFetchMyOrdersSuccess?: (data: IMyOrdersData) => void
onFetchMyOrdersError?: (error: IError) => void

onFetchOrderDetailsSuccess?: () => void
onFetchOrderDetailsSuccess?: (data: IMyOrderDetailsData) => void
onFetchOrderDetailsError?: (error: IError) => void

onLoadingChange?: (isLoading: boolean) => void
Expand All @@ -1369,6 +1365,61 @@ import { MyOrders, SessionHandleType } from 'tf-checkout-react-native'
}
}
```
IMyOrdersData
```ts
{
events: IMyOrdersEvent[]
orders: IMyOrdersOrder[]
filter?: string
brandFilter?: string
subBrands?: boolean
pagination: {
page: number
limit: number
totalCount: number
totalPages: number
}
}
```
IMyOrderDetailsData
```ts
{
header: {
isReferralDisabled: boolean
shareLink: string
total: string
salesReferred: string
}
items?: {
isActive: boolean
currency: string
discount: string
name: string
price: string
quantity: string
total: string
hash: string
}[]
tickets: {
currency: string
description: string
descriptionPlain?: string
eventName: string
hash: string
holderEmail?: string
holderName: string
holderPhone?: string
isOnSale: boolean
isSellable: boolean
pdfLink: string
qrData: string
resaleFeeAmount: number
status: string
ticketType: string
ticketTypeHash: string
}[]
}
```
### styles
```js
Expand Down Expand Up @@ -2292,8 +2343,8 @@ Exposes the following functions:
```ts
// Get event conditions for the current event.
getEventConditions(eventId: string): Promise<any>
// Get event conditions for the Event Id set on the setConfig.
getEventConditions(): Promise<any>

// Get purchase order details for the current event.
getPurchaseOrderDetails(orderId: string): Promise<{
Expand Down Expand Up @@ -2477,6 +2528,15 @@ getMyOrders(page: number, filter: string): Promise<{
eventUrl: string
image: string
}[]
filter?: string
brandFilter?: string
subBrands?: boolean
pagination: {
page: number
limit: number
totalCount: number
totalPages: number
}
}

myOrdersError?: {
Expand Down Expand Up @@ -2693,6 +2753,15 @@ Wrap your component with the Core component.
# Changelog
## 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.
- Add missing pagination data in `onFetchMyOrdersSuccess` response.
- 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
Expand All @@ -2703,7 +2772,7 @@ Wrap your component with the Core component.
- Update `addToCart` success response to include:
```
isTicketFree?: boolean
isTicketFree?: boolean
isPhoneHidden?: boolean
```
Expand Down
8 changes: 7 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ const App = () => {
return (
<>
<Checkout
eventId={EVENT_ID}
checkoutData={checkoutProps!}
onPaymentSuccess={handleOnPaymentSuccess}
onPressExit={handleStripeError}
Expand Down Expand Up @@ -432,6 +431,9 @@ const App = () => {
config={{
areActivityIndicatorsEnabled: false,
}}
onFetchMyOrdersSuccess={(data) => {
console.log('onFetchMyOrdersSuccess', data)
}}
onLoadingChange={(loading) => setIsLoading(loading)}
onSelectOrder={handleOnSelectOrder}
styles={{
Expand Down Expand Up @@ -898,6 +900,10 @@ const App = () => {
}}
isCheckingCurrentSession={isCheckingCurrentSession}
onLoadingChange={(loading) => setIsLoading(loading)}
onFetchTicketsError={(error) => {
console.log(`onFetchTicketsError`, error)
}}
onFetchEventError={(error) => console.log('onFetchEventError', error)}
onAddToCartSuccess={handleOnAddToCartSuccess}
onPressLogout={handleOnPressLogout}
onPressMyOrders={handleOnPressMyOrders}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tf-checkout-react-native",
"version": "1.0.26",
"version": "1.0.27",
"description": "TheTicketFairy ReactNative Checkout library",
"homepage": "https://github.com/theticketfairy/tf-checkout-react-native",
"main": "lib/index.js",
Expand Down
79 changes: 75 additions & 4 deletions src/api/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ export const registerNewUser = async (
export const addToWaitingList = async (
values: IWaitingListFields
): Promise<IAddToWaitingListResponse> => {
if (!Config.EVENT_ID) {
return {
addToWaitingListError: {
message: 'Event ID is not configured!',
},
}
}

const requestData = {
data: {
attributes: values,
Expand Down Expand Up @@ -378,6 +386,12 @@ export const fetchMyOrders = async (
const data: IMyOrdersData = {
events: [],
orders: [],
pagination: {
page: 0,
limit: 0,
totalCount: 0,
totalPages: 0,
},
}
let responseError: IError | undefined

Expand All @@ -398,8 +412,17 @@ export const fetchMyOrders = async (
)

if (response?.data) {
data.events = response.data.data.attributes.purchased_events
data.orders = response.data.data.attributes.orders
const dataAttributes = response.data.data.attributes

data.events = dataAttributes.purchased_events
data.orders = dataAttributes.orders
data.pagination.limit = dataAttributes.limit
data.pagination.page = dataAttributes.page
data.pagination.totalCount = dataAttributes.total_count
data.pagination.totalPages = dataAttributes.total_pages
data.filter = dataAttributes.filter
data.brandFilter = dataAttributes.brand_filter
data.subBrands = dataAttributes.sub_brands
}

return {
Expand Down Expand Up @@ -492,6 +515,14 @@ export const fetchOrderDetails = async (
export const fetchTickets = async (
promoCode?: string
): Promise<IFetchTicketsResponse> => {
if (!Config.EVENT_ID) {
return {
error: {
message: 'Event ID is not configured!',
},
}
}

const eventId = Config.EVENT_ID.toString()
const headers = {
'Promotion-Event': eventId,
Expand Down Expand Up @@ -558,6 +589,14 @@ export const fetchTickets = async (
export const addToCart = async (
data: IAddToCartParams
): Promise<IAddToCartResponse> => {
if (!Config.EVENT_ID) {
return {
error: {
message: 'Event ID is not configured!',
},
}
}

let responseError: IError | undefined
let responseData: ITicketsResponseData | undefined

Expand Down Expand Up @@ -599,6 +638,14 @@ export const addToCart = async (
}

export const fetchEvent = async (): Promise<IEventResponse> => {
if (!Config.EVENT_ID) {
return {
eventError: {
message: 'Event ID is not configured!',
},
}
}

let responseError: IError | undefined
let event: IEvent | undefined
const response: AxiosResponse | void = await Client.get(
Expand Down Expand Up @@ -626,6 +673,14 @@ export const fetchEvent = async (): Promise<IEventResponse> => {
export const postReferralVisit = async (
referralId: string
): Promise<IPostReferralResponse> => {
if (!Config.EVENT_ID) {
return {
postReferralError: {
message: 'Event ID is not configured!',
},
}
}

const eventId = Config.EVENT_ID.toString()
const referralIdNumber = parseInt(referralId, 10)
let responseError: IError | undefined
Expand Down Expand Up @@ -670,6 +725,14 @@ export const postReferralVisit = async (
export const unlockPasswordProtectedEvent = async (
password: string
): Promise<IEventResponse> => {
if (!Config.EVENT_ID) {
return {
eventError: {
message: 'Event ID is not configured!',
},
}
}

const eventId = Config.EVENT_ID.toString()
let responseError: IError | undefined
let responseData: any | undefined
Expand Down Expand Up @@ -845,10 +908,18 @@ export const checkoutOrder = async (
//#endregion

//#region Checkout
export const fetchEventConditions = async (eventId: string) => {
export const fetchEventConditions = async () => {
if (!Config.EVENT_ID) {
return {
error: {
message: 'Event ID is not configured!',
},
}
}

let responseError: IError | undefined
const response: AxiosResponse | void = await Client.get(
`v1/event/${eventId}/conditions`
`v1/event/${Config.EVENT_ID}/conditions`
).catch((error: AxiosError) => {
responseError = {
message: error.response?.data,
Expand Down
9 changes: 9 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ export interface IMyOrdersOrder {
export interface IMyOrdersData {
events: IMyOrdersEvent[]
orders: IMyOrdersOrder[]
filter?: string
brandFilter?: string
subBrands?: boolean
pagination: {
page: number
limit: number
totalCount: number
totalPages: number
}
}

export interface IMyOrdersResponse {
Expand Down
Loading

0 comments on commit 2ad8181

Please sign in to comment.