tf-checkout-react 1.0.45 → 1.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.ts +1 -0
- package/dist/components/billing-info-container/utils.d.ts +1 -1
- package/dist/components/common/CheckboxField.d.ts +2 -2
- package/dist/components/ticketsContainer/TicketRow.d.ts +10 -0
- package/dist/components/ticketsContainer/TicketsSection.d.ts +10 -0
- package/dist/components/ticketsContainer/index.d.ts +2 -1
- package/dist/components/ticketsContainer/utils.d.ts +4 -0
- package/dist/components/waitingList/index.d.ts +7 -0
- package/dist/tf-checkout-react.cjs.development.css +2 -1
- package/dist/tf-checkout-react.cjs.development.js +273 -62
- package/dist/tf-checkout-react.cjs.development.js.map +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js.map +1 -1
- package/dist/tf-checkout-react.esm.js +279 -65
- package/dist/tf-checkout-react.esm.js.map +1 -1
- package/dist/validators/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/api/index.ts +3 -1
- package/src/components/.DS_Store +0 -0
- package/src/components/billing-info-container/index.tsx +18 -11
- package/src/components/billing-info-container/utils.ts +3 -2
- package/src/components/common/CheckboxField.tsx +3 -2
- package/src/components/common/CustomField.tsx +1 -1
- package/src/components/ticketsContainer/TicketRow.tsx +86 -0
- package/src/components/ticketsContainer/TicketsSection.tsx +82 -0
- package/src/components/ticketsContainer/index.tsx +82 -208
- package/src/components/ticketsContainer/utils.ts +11 -0
- package/src/components/waitingList/index.tsx +162 -0
- package/src/components/waitingList/style.css +18 -0
- package/src/validators/index.ts +9 -3
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import Button from '@mui/material/Button'
|
|
3
|
+
import CircularProgress from '@mui/material/CircularProgress'
|
|
4
|
+
import { Field, Form, Formik } from 'formik'
|
|
5
|
+
import { CustomField } from '../common/CustomField'
|
|
6
|
+
import { addToWaitingList } from '../../api'
|
|
7
|
+
import {
|
|
8
|
+
combineValidators,
|
|
9
|
+
requiredValidator,
|
|
10
|
+
emailValidator,
|
|
11
|
+
} from '../../validators'
|
|
12
|
+
import { ENV } from '../../env'
|
|
13
|
+
|
|
14
|
+
import './style.css'
|
|
15
|
+
|
|
16
|
+
interface WaitingListProps {
|
|
17
|
+
tickets: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface WaitingListFields {
|
|
21
|
+
ticketTypeId: string;
|
|
22
|
+
quantity: string;
|
|
23
|
+
firstName: string;
|
|
24
|
+
lastName: string;
|
|
25
|
+
email: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const generateQuantity = (n: number) => {
|
|
29
|
+
const quantityList = []
|
|
30
|
+
for (let i = 1; i <= n; i++) {
|
|
31
|
+
quantityList.push({ label: i, value: i })
|
|
32
|
+
}
|
|
33
|
+
return quantityList
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const WaitingList = ({ tickets = {} }: WaitingListProps) => {
|
|
37
|
+
const [showSuccessMessage, setShowSuccessMessage] = useState(false)
|
|
38
|
+
const [loading, setLoading] = useState(false)
|
|
39
|
+
const ticketTypesList = Object.values(tickets).map((d: any) => ({
|
|
40
|
+
label: d.displayName,
|
|
41
|
+
value: d.id,
|
|
42
|
+
}))
|
|
43
|
+
|
|
44
|
+
const handleSubmit = async (values: WaitingListFields) => {
|
|
45
|
+
try {
|
|
46
|
+
setLoading(true)
|
|
47
|
+
const id = ENV.EVENT_ID
|
|
48
|
+
const requestData = {
|
|
49
|
+
data: {
|
|
50
|
+
attributes: values,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
const { data } = await addToWaitingList(id, requestData)
|
|
54
|
+
|
|
55
|
+
if (data.success) {
|
|
56
|
+
setShowSuccessMessage(true)
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.log(error)
|
|
60
|
+
} finally {
|
|
61
|
+
setLoading(false)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className="waiting-list">
|
|
67
|
+
{showSuccessMessage ? (
|
|
68
|
+
<div className="success-message">
|
|
69
|
+
<h3>{`You've been added to the waiting list!`}</h3>
|
|
70
|
+
<p>{`You'll be notified if tickets become available.`}</p>
|
|
71
|
+
</div>
|
|
72
|
+
) : (
|
|
73
|
+
<>
|
|
74
|
+
<h2>WAITING LIST</h2>
|
|
75
|
+
<Formik
|
|
76
|
+
initialValues={{
|
|
77
|
+
ticketTypeId: '',
|
|
78
|
+
quantity: '',
|
|
79
|
+
firstName: '',
|
|
80
|
+
lastName: '',
|
|
81
|
+
email: '',
|
|
82
|
+
}}
|
|
83
|
+
onSubmit={handleSubmit}
|
|
84
|
+
>
|
|
85
|
+
<Form>
|
|
86
|
+
<div className="field-item">
|
|
87
|
+
<Field
|
|
88
|
+
name="ticketTypeId"
|
|
89
|
+
label="Ticket types"
|
|
90
|
+
type="select"
|
|
91
|
+
component={CustomField}
|
|
92
|
+
selectOptions={[
|
|
93
|
+
{ label: 'Type of Ticket', value: '', disabled: true },
|
|
94
|
+
...ticketTypesList,
|
|
95
|
+
]}
|
|
96
|
+
/>
|
|
97
|
+
</div>
|
|
98
|
+
<div className="field-item">
|
|
99
|
+
<Field
|
|
100
|
+
name="quantity"
|
|
101
|
+
label="Quantity"
|
|
102
|
+
type="select"
|
|
103
|
+
component={CustomField}
|
|
104
|
+
selectOptions={[
|
|
105
|
+
{ label: 'Quantity Requested', value: '', disabled: true },
|
|
106
|
+
...generateQuantity(10),
|
|
107
|
+
]}
|
|
108
|
+
/>
|
|
109
|
+
</div>
|
|
110
|
+
<div className="field-item">
|
|
111
|
+
<Field
|
|
112
|
+
name="firstName"
|
|
113
|
+
label="First name"
|
|
114
|
+
validate={(value: string) =>
|
|
115
|
+
requiredValidator(value, 'Please enter your First name')
|
|
116
|
+
}
|
|
117
|
+
component={CustomField}
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
<div className="field-item">
|
|
121
|
+
<Field
|
|
122
|
+
name="lastName"
|
|
123
|
+
label="Last name"
|
|
124
|
+
validate={(value: string) =>
|
|
125
|
+
requiredValidator(value, 'Please enter your Last name')
|
|
126
|
+
}
|
|
127
|
+
component={CustomField}
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
<div className="field-item">
|
|
131
|
+
<Field
|
|
132
|
+
name="email"
|
|
133
|
+
label="Email"
|
|
134
|
+
validate={combineValidators(
|
|
135
|
+
(value: string) =>
|
|
136
|
+
requiredValidator(value, 'Please enter your Email'),
|
|
137
|
+
(value: string) => emailValidator(value)
|
|
138
|
+
)}
|
|
139
|
+
component={CustomField}
|
|
140
|
+
/>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<Button
|
|
144
|
+
type="submit"
|
|
145
|
+
variant="contained"
|
|
146
|
+
className="waiting-list-button"
|
|
147
|
+
>
|
|
148
|
+
{loading ? (
|
|
149
|
+
<CircularProgress size="22px" />
|
|
150
|
+
) : (
|
|
151
|
+
'ADD TO WAITING LIST'
|
|
152
|
+
)}
|
|
153
|
+
</Button>
|
|
154
|
+
</Form>
|
|
155
|
+
</Formik>
|
|
156
|
+
</>
|
|
157
|
+
)}
|
|
158
|
+
</div>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default WaitingList
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.waiting-list {
|
|
2
|
+
padding: 17px 35px 20px;
|
|
3
|
+
}
|
|
4
|
+
.waiting-list .field-item {
|
|
5
|
+
margin-bottom: 30px;
|
|
6
|
+
}
|
|
7
|
+
.waiting-list .waiting-list-button {
|
|
8
|
+
width: 100% !important;
|
|
9
|
+
}
|
|
10
|
+
.waiting-list .waiting-list-button:hover {
|
|
11
|
+
background-color: #505050;
|
|
12
|
+
}
|
|
13
|
+
.waiting-list .success-message h3 {
|
|
14
|
+
margin: 10px 0;
|
|
15
|
+
}
|
|
16
|
+
.waiting-list .success-message p {
|
|
17
|
+
margin: 0;
|
|
18
|
+
}
|
package/src/validators/index.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
2
|
+
|
|
1
3
|
export const combineValidators = (...validators: any) => (...value: any) => {
|
|
2
4
|
for (let i = 0; i < validators.length; ++i) {
|
|
3
5
|
const error_message = validators[i](...value)
|
|
4
|
-
if (error_message
|
|
6
|
+
if (error_message) return error_message
|
|
5
7
|
}
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
export const requiredValidator = (value?: string | number): string => {
|
|
10
|
+
export const requiredValidator = (value?: string | number, message?: string): string => {
|
|
9
11
|
let errorMessage = ''
|
|
10
12
|
if (!value) {
|
|
11
|
-
errorMessage = 'Required'
|
|
13
|
+
errorMessage = message || 'Required'
|
|
12
14
|
}
|
|
13
15
|
return errorMessage
|
|
14
16
|
}
|
|
17
|
+
|
|
18
|
+
export const emailValidator = (email: string) => {
|
|
19
|
+
return !emailRegex.test(email) ? 'Please enter a valid email address' : ''
|
|
20
|
+
}
|