tf-checkout-react 1.3.46 → 1.3.47-beta.2
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/.DS_Store +0 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/components/addonsContainer/utils/index.d.ts +1 -4
- package/dist/components/billing-info-container/utils.d.ts +20 -1
- package/dist/components/myTicketsContainer/tableConfig.d.ts +1 -4
- package/dist/components/ticketsContainer/TicketRow.d.ts +6 -1
- package/dist/components/ticketsContainer/TicketsSection.d.ts +6 -1
- package/dist/components/ticketsContainer/crypto.d.ts +24 -0
- package/dist/tf-checkout-react.cjs.development.js +4701 -1324
- 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 +4702 -1324
- package/dist/tf-checkout-react.esm.js.map +1 -1
- package/dist/tf-checkout-styles.css +1 -1
- package/dist/types/billing-info-data.d.ts +5 -0
- package/dist/utils/getWalletName.d.ts +1 -0
- package/dist/utils/loadProfile.d.ts +32 -0
- package/package.json +3 -1
- package/src/.DS_Store +0 -0
- package/src/api/index.ts +42 -1
- package/src/assets/.DS_Store +0 -0
- package/src/components/addonsContainer/utils/index.tsx +1 -1
- package/src/components/billing-info-container/index.tsx +271 -11
- package/src/components/billing-info-container/style.css +1 -1
- package/src/components/billing-info-container/utils.ts +98 -5
- package/src/components/loginModal/index.tsx +70 -5
- package/src/components/loginModal/style.css +2 -2
- package/src/components/ticketsContainer/TicketRow.tsx +55 -5
- package/src/components/ticketsContainer/TicketsSection.tsx +15 -1
- package/src/components/ticketsContainer/crypto.js +528 -0
- package/src/components/ticketsContainer/index.tsx +216 -2
- package/src/components/waitingList/index.tsx +1 -1
- package/src/env.ts +2 -2
- package/src/types/billing-info-data.ts +6 -0
- package/src/utils/getWalletName.tsx +10 -0
- package/src/utils/loadProfile.tsx +47 -0
- package/src/components/common/dist/PhoneNumberField.js +0 -96
|
@@ -17,12 +17,16 @@ import Button from 'react-bootstrap/Button'
|
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
19
|
addToCart,
|
|
20
|
+
confirmMetamask,
|
|
21
|
+
connectMetamask,
|
|
22
|
+
getCart,
|
|
20
23
|
getCheckoutPageConfigs,
|
|
21
24
|
getEvent,
|
|
22
25
|
getProfileData,
|
|
23
26
|
getTickets,
|
|
24
27
|
logout,
|
|
25
28
|
postOnCheckout,
|
|
29
|
+
temporalNonce,
|
|
26
30
|
} from '../../api'
|
|
27
31
|
import { X_TF_ECOMMERCE } from '../../constants'
|
|
28
32
|
import { useCookieListener } from '../../hooks/useCookieListener'
|
|
@@ -34,6 +38,7 @@ import {
|
|
|
34
38
|
getQueryVariable,
|
|
35
39
|
setLoggedUserData,
|
|
36
40
|
} from '../../utils'
|
|
41
|
+
import { returnSelectedBlockchain, signSubmit } from '../billing-info-container/utils'
|
|
37
42
|
import { Loader } from '../common/index'
|
|
38
43
|
import { PoweredBy } from '../common/PoweredBy'
|
|
39
44
|
import ConfirmModal from '../confirmModal'
|
|
@@ -41,6 +46,7 @@ import Countdown from '../countdown'
|
|
|
41
46
|
import { LoginModal } from '../loginModal'
|
|
42
47
|
import WaitingList from '../waitingList'
|
|
43
48
|
import { AccessCodeSection } from './AccessCodeSection'
|
|
49
|
+
import { CryptoIntegration } from './crypto.js'
|
|
44
50
|
import { PromoCodeSection } from './PromoCodeSection'
|
|
45
51
|
import { ReferralLogic } from './ReferralLogic'
|
|
46
52
|
import { TicketsSection } from './TicketsSection'
|
|
@@ -174,7 +180,17 @@ export const TicketsContainer = ({
|
|
|
174
180
|
const [showPromoCodeSection, setShowPromoCodeSection] = useState(
|
|
175
181
|
isPromotionsEnabled
|
|
176
182
|
)
|
|
177
|
-
const [error, setError] = useState(null)
|
|
183
|
+
const [error, setError] = useState<string | null>(null)
|
|
184
|
+
const cryptoEventIdentifier = (
|
|
185
|
+
event?.cryptoEventIdentifiers &&
|
|
186
|
+
event.cryptoEventIdentifiers?.length &&
|
|
187
|
+
event.cryptoEventIdentifiers[0]
|
|
188
|
+
)
|
|
189
|
+
const isSolanaEvent = cryptoEventIdentifier === 'solana'
|
|
190
|
+
const isEthereumEvent = cryptoEventIdentifier === 'ethereum'
|
|
191
|
+
const isCryptoEvent = event?.isCryptoEvent
|
|
192
|
+
const [cryptoWrapper, setCryptoWrapper] = useState<any>(undefined)
|
|
193
|
+
const [cryptoIdentifier, setCryptoIdentifier] = useState<string[]>([])
|
|
178
194
|
const [isNotInvitedError, setIsNotInvitedError] = useState('')
|
|
179
195
|
const [isInvalidLinkError, setIsInvalidLinkError] = useState('')
|
|
180
196
|
|
|
@@ -200,6 +216,8 @@ export const TicketsContainer = ({
|
|
|
200
216
|
!!eventId && getTicketsApi()
|
|
201
217
|
}, [eventId])
|
|
202
218
|
|
|
219
|
+
const [walletNotVerified, setWalletNotVerified] = useState(true)
|
|
220
|
+
const [noWalletConnected, setNoWalletConnected] = useState(true)
|
|
203
221
|
useEffect(() => {
|
|
204
222
|
if (isLogged) {
|
|
205
223
|
fetchUserData()
|
|
@@ -226,6 +244,8 @@ export const TicketsContainer = ({
|
|
|
226
244
|
const event = new window.CustomEvent('tf-logout')
|
|
227
245
|
deleteCookieByName('X-TF-ECOMMERCE')
|
|
228
246
|
window.document.dispatchEvent(event)
|
|
247
|
+
setWalletNotVerified(true)
|
|
248
|
+
setNoWalletConnected(true)
|
|
229
249
|
}
|
|
230
250
|
} catch (e) {
|
|
231
251
|
onLogoutError(e)
|
|
@@ -268,6 +288,20 @@ export const TicketsContainer = ({
|
|
|
268
288
|
if (eventResponse.data.success) {
|
|
269
289
|
const event = _get(eventResponse, 'data.data.attributes')
|
|
270
290
|
setEvent(event)
|
|
291
|
+
setWalletNotVerified(event?.walletNotVerified ?? true)
|
|
292
|
+
setNoWalletConnected(event?.noWalletConnected ?? true)
|
|
293
|
+
if (response?.data?.data?.attributes?.tickets) {
|
|
294
|
+
const { tickets } = response.data.data.attributes
|
|
295
|
+
for (const ticketKey in tickets) {
|
|
296
|
+
const ticket = tickets[ticketKey]
|
|
297
|
+
if (ticket?.walletNotVerified !== undefined) {
|
|
298
|
+
setWalletNotVerified(ticket?.walletNotVerified ?? true)
|
|
299
|
+
}
|
|
300
|
+
if (ticket?.noWalletConnected !== undefined) {
|
|
301
|
+
setNoWalletConnected(ticket?.noWalletConnected ?? true)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
271
305
|
|
|
272
306
|
if (event.country && isWindowDefined) {
|
|
273
307
|
window.localStorage.setItem('eventCountry', event.country)
|
|
@@ -381,6 +415,27 @@ export const TicketsContainer = ({
|
|
|
381
415
|
userData
|
|
382
416
|
)
|
|
383
417
|
|
|
418
|
+
if (isCryptoEvent) {
|
|
419
|
+
const res = await getCart()
|
|
420
|
+
const cartInfo = _get(res, 'data.data.attributes')
|
|
421
|
+
const { selectedBlockchain } = returnSelectedBlockchain(cartInfo?.permittedBlockchains, cryptoIdentifier)
|
|
422
|
+
cryptoWrapper.setBlockchain(selectedBlockchain)
|
|
423
|
+
const { signature, override_crypto_address, usedAddress } = await signSubmit({
|
|
424
|
+
hasAccount: cartInfo?.hasAccount,
|
|
425
|
+
ethNonce: cartInfo?.ethNonce,
|
|
426
|
+
permittedBlockchains: cartInfo?.permittedBlockchains,
|
|
427
|
+
cryptoWrapper,
|
|
428
|
+
selectedBlockchain
|
|
429
|
+
})
|
|
430
|
+
checkoutBody.attributes.blockchain = selectedBlockchain
|
|
431
|
+
if (override_crypto_address) {
|
|
432
|
+
checkoutBody.attributes.crypto_address = usedAddress
|
|
433
|
+
checkoutBody.attributes.crypto_signature = signature
|
|
434
|
+
} else {
|
|
435
|
+
checkoutBody.attributes.crypto_confirmation_signature = signature
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
384
439
|
const checkoutResult = enableBillingInfoAutoCreate
|
|
385
440
|
? await postOnCheckout(checkoutBody, access_token, freeTicket)
|
|
386
441
|
: null
|
|
@@ -512,6 +567,130 @@ export const TicketsContainer = ({
|
|
|
512
567
|
!event?.salesStarted && event?.salesStart && !isTicketAvailable
|
|
513
568
|
const influencers = event?.referralsEnabled ? event?.referrals : []
|
|
514
569
|
|
|
570
|
+
const [cryptoButtonDisabled, setCryptoButtonDisabled] = useState(false)
|
|
571
|
+
useEffect(() => {
|
|
572
|
+
setCryptoWrapper(CryptoIntegration())
|
|
573
|
+
window.addEventListener('ttf.crypto.new-wallet', (event: any) => {
|
|
574
|
+
if (event?.detail?.identifier) {
|
|
575
|
+
setCryptoIdentifier(state => [...state, event.detail.identifier])
|
|
576
|
+
}
|
|
577
|
+
})
|
|
578
|
+
}, [])
|
|
579
|
+
|
|
580
|
+
const walletConnect = async (blockchain: string, tempNonce: string) => {
|
|
581
|
+
try {
|
|
582
|
+
cryptoWrapper.setBlockchain(blockchain)
|
|
583
|
+
const accountInformation = await cryptoWrapper.getAuthenticatedUserAddress()
|
|
584
|
+
const crypto_address = accountInformation.address
|
|
585
|
+
const nonce = accountInformation?.nonce
|
|
586
|
+
const message = 'Confirm you are the owner of ' + crypto_address + '. Nonce: '
|
|
587
|
+
setCryptoButtonDisabled(true)
|
|
588
|
+
let usedAddress = undefined
|
|
589
|
+
try {
|
|
590
|
+
await cryptoWrapper.enable()
|
|
591
|
+
const address = await cryptoWrapper.getAddress()
|
|
592
|
+
usedAddress = address
|
|
593
|
+
const signature = await cryptoWrapper.getSignature(usedAddress, nonce, message)
|
|
594
|
+
try {
|
|
595
|
+
const form = new FormData()
|
|
596
|
+
form.append('crypto_signature', signature)
|
|
597
|
+
await confirmMetamask(blockchain, form)
|
|
598
|
+
setCryptoButtonDisabled(false)
|
|
599
|
+
setWalletNotVerified(false)
|
|
600
|
+
setNoWalletConnected(false)
|
|
601
|
+
} catch(e) {
|
|
602
|
+
setCryptoButtonDisabled(false)
|
|
603
|
+
}
|
|
604
|
+
} catch(e) {
|
|
605
|
+
const error: any = e
|
|
606
|
+
setCryptoButtonDisabled(false)
|
|
607
|
+
if (error?.errorCode !== cryptoWrapper.ERRORS.CONNECTION_REJECTED &&
|
|
608
|
+
error?.errorCode !== cryptoWrapper.ERRORS.SIGNATURE_REJECTED) {
|
|
609
|
+
return setError('Something went wrong, Try again later or contact our support team.')
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
} catch(e) {
|
|
613
|
+
const error: any = e
|
|
614
|
+
let userIsLoggedIn = false
|
|
615
|
+
if (error.errorCode === cryptoWrapper.ERRORS.ACCOUNT_NOT_FOUND) {
|
|
616
|
+
userIsLoggedIn = true
|
|
617
|
+
} else if (error.errorCode !== cryptoWrapper.ERRORS.NOT_AUTHENTICATED) {
|
|
618
|
+
return setError('Something went wrong, Try again later or contact our support team.')
|
|
619
|
+
}
|
|
620
|
+
setCryptoButtonDisabled(true)
|
|
621
|
+
let usedAddress = undefined
|
|
622
|
+
try {
|
|
623
|
+
await cryptoWrapper.enable()
|
|
624
|
+
const address = await cryptoWrapper.getAddress()
|
|
625
|
+
usedAddress = address
|
|
626
|
+
const nonce = await cryptoWrapper.getNonceFromAddress(address)
|
|
627
|
+
if (userIsLoggedIn) {
|
|
628
|
+
setCryptoButtonDisabled(false)
|
|
629
|
+
return setError(
|
|
630
|
+
'This wallet is already connected to an existing account. ' +
|
|
631
|
+
'Please log out of this account and log back in using this wallet.'
|
|
632
|
+
)
|
|
633
|
+
}
|
|
634
|
+
const signature = await cryptoWrapper.getSignature(usedAddress, nonce, 'Welcome back, we missed you! Nonce: ')
|
|
635
|
+
try {
|
|
636
|
+
await cryptoWrapper.authAddress(usedAddress, signature)
|
|
637
|
+
window.location.reload()
|
|
638
|
+
} catch(e) {
|
|
639
|
+
const error: any = e
|
|
640
|
+
setCryptoButtonDisabled(false)
|
|
641
|
+
if (error.errorCode !== cryptoWrapper.ERRORS.CONNECTION_REJECTED &&
|
|
642
|
+
error.errorCode !== cryptoWrapper.ERRORS.SIGNATURE_REJECTED) {
|
|
643
|
+
return setError('Something went wrong, Try again later or contact our support team.')
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
} catch(e) {
|
|
647
|
+
const error: any = e
|
|
648
|
+
if (error.errorCode === cryptoWrapper.ERRORS.ACCOUNT_NOT_FOUND) {
|
|
649
|
+
const nonce = tempNonce
|
|
650
|
+
let message = 'Welcome to The Ticket Fairy! Nonce: '
|
|
651
|
+
if (userIsLoggedIn) {
|
|
652
|
+
message = 'You are connecting your wallet with The Ticket Fairy. Nonce: '
|
|
653
|
+
}
|
|
654
|
+
try {
|
|
655
|
+
const signature = await cryptoWrapper.getSignature(usedAddress, nonce, message)
|
|
656
|
+
const form = new FormData()
|
|
657
|
+
form.append('crypto_address', String(usedAddress))
|
|
658
|
+
form.append('crypto_signature', signature)
|
|
659
|
+
form.append('product_id', String(eventId))
|
|
660
|
+
form.append('ticket_type_id', '')
|
|
661
|
+
try {
|
|
662
|
+
await connectMetamask(blockchain, form)
|
|
663
|
+
setCryptoButtonDisabled(false)
|
|
664
|
+
setWalletNotVerified(false)
|
|
665
|
+
setNoWalletConnected(false)
|
|
666
|
+
return
|
|
667
|
+
} catch(e) {
|
|
668
|
+
const errorMessage = _get(e, 'response.data.message')
|
|
669
|
+
setCryptoButtonDisabled(false)
|
|
670
|
+
if (errorMessage) {
|
|
671
|
+
return setError(errorMessage)
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
} catch(e) {
|
|
675
|
+
const error: any = e
|
|
676
|
+
setCryptoButtonDisabled(false)
|
|
677
|
+
if (error.errorCode !== cryptoWrapper.ERRORS.CONNECTION_REJECTED &&
|
|
678
|
+
error.errorCode !== cryptoWrapper.ERRORS.SIGNATURE_REJECTED) {
|
|
679
|
+
return setError('Something went wrong, Try again later or contact our support team.')
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
setCryptoButtonDisabled(false)
|
|
684
|
+
if (error.errorCode !== cryptoWrapper.ERRORS.CONNECTION_REJECTED &&
|
|
685
|
+
error.errorCode !== cryptoWrapper.ERRORS.SIGNATURE_REJECTED) {
|
|
686
|
+
return setError('Something went wrong, Try again later or contact our support team.')
|
|
687
|
+
}
|
|
688
|
+
if (error?.message) {
|
|
689
|
+
return setError(error?.message)
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
515
694
|
const canShowGetTicketBtn = () => {
|
|
516
695
|
if (
|
|
517
696
|
!wrappedActionsSectionComponent &&
|
|
@@ -573,7 +752,7 @@ export const TicketsContainer = ({
|
|
|
573
752
|
<Loader />
|
|
574
753
|
) : (
|
|
575
754
|
<div ref={ticketsContainerRef}>
|
|
576
|
-
{!isSalesClosed && (
|
|
755
|
+
{!isSalesClosed && (isCryptoEvent ? !(noWalletConnected || walletNotVerified) : true) && (
|
|
577
756
|
<TicketsSection
|
|
578
757
|
event={event}
|
|
579
758
|
ticketsList={tickets}
|
|
@@ -584,8 +763,43 @@ export const TicketsContainer = ({
|
|
|
584
763
|
hideTicketsHeader={hideTicketsHeader || _isEmpty(tickets)}
|
|
585
764
|
showGroupNameBlock={showGroupNameBlock}
|
|
586
765
|
currencySybmol={currencySybmol}
|
|
766
|
+
cryptoIdentifier={cryptoIdentifier}
|
|
767
|
+
cryptoButtonDisabled={cryptoButtonDisabled}
|
|
768
|
+
walletConnect={walletConnect}
|
|
769
|
+
noWalletConnected={noWalletConnected}
|
|
770
|
+
walletNotVerified={walletNotVerified}
|
|
587
771
|
/>
|
|
588
772
|
)}
|
|
773
|
+
{isCryptoEvent && (noWalletConnected || walletNotVerified) ?
|
|
774
|
+
cryptoIdentifier.length > 0 ?
|
|
775
|
+
(
|
|
776
|
+
<div className='nft-container-connect'>
|
|
777
|
+
<div>Please connect your wallet<br/> to view available tickets</div>
|
|
778
|
+
{isSolanaEvent && !cryptoIdentifier.includes('solana') ? (
|
|
779
|
+
<strong className='phatom enable-wallet'>Phantom-enabled browser required.</strong>
|
|
780
|
+
) : isEthereumEvent && !cryptoIdentifier.includes('ethereum') ? (
|
|
781
|
+
<strong className='metamask enable-wallet'>Metamask-enabled browser required.</strong>
|
|
782
|
+
) : (
|
|
783
|
+
(isSolanaEvent && cryptoIdentifier.includes('solana')) ||
|
|
784
|
+
(isEthereumEvent && cryptoIdentifier.includes('ethereum'))
|
|
785
|
+
) ? (
|
|
786
|
+
<button
|
|
787
|
+
disabled={cryptoButtonDisabled}
|
|
788
|
+
className='ntf-button-connect'
|
|
789
|
+
type='button'
|
|
790
|
+
onClick={async () => {
|
|
791
|
+
const response = await temporalNonce()
|
|
792
|
+
const ethNonce = _get(response, 'data.data.attributes.ethNonce')
|
|
793
|
+
walletConnect(cryptoEventIdentifier, ethNonce)
|
|
794
|
+
}}
|
|
795
|
+
>
|
|
796
|
+
<strong>Connect </strong><br />with {isSolanaEvent ? 'Phantom' : 'MetaMask'}
|
|
797
|
+
</button>
|
|
798
|
+
) : null}
|
|
799
|
+
</div>
|
|
800
|
+
) :
|
|
801
|
+
<strong>Crypto-enabled browser required.</strong>
|
|
802
|
+
: null}
|
|
589
803
|
{externalUrl ? null : isSalesClosed ? (
|
|
590
804
|
<p
|
|
591
805
|
className={`event-closed-message ${
|
package/src/env.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// preview
|
|
2
2
|
export const ENV = {
|
|
3
|
-
EVENT_ID:
|
|
4
|
-
BASE_URL: 'https://
|
|
3
|
+
EVENT_ID: 6306,
|
|
4
|
+
BASE_URL: 'https://ttf.localhost',
|
|
5
5
|
CLIENT_ID: 'e9d8f8922797b4621e562255afe90dbf',
|
|
6
6
|
CLIENT_SECRET: 'b89c191eff22fdcf84ac9bfd88d005355a151ec2c83b26b9',
|
|
7
7
|
STRIPE_PUBLISHABLE_KEY:
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {getProfileData} from "../api";
|
|
2
|
+
import _get from "lodash/get";
|
|
3
|
+
|
|
4
|
+
export const loadProfile = async (token?: string) => {
|
|
5
|
+
const profileResponse = await getProfileData(token)
|
|
6
|
+
const profileSpecifiedData = _get(profileResponse, 'data.data')
|
|
7
|
+
const profileData = setLoggedUserData(profileSpecifiedData)
|
|
8
|
+
if (typeof window !== 'undefined') {
|
|
9
|
+
window.localStorage.setItem(
|
|
10
|
+
'user_data',
|
|
11
|
+
JSON.stringify(profileData)
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
return profileResponse?.data
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const setLoggedUserData = (data: IUserData) => ({
|
|
18
|
+
id: data.id,
|
|
19
|
+
first_name: data.firstName,
|
|
20
|
+
last_name: data.lastName,
|
|
21
|
+
email: data.email,
|
|
22
|
+
confirmEmail: data.email,
|
|
23
|
+
city: data?.city || '',
|
|
24
|
+
country: data?.countryId || data?.country || '',
|
|
25
|
+
phone: data?.phone || '',
|
|
26
|
+
street_address: data?.streetAddress || '',
|
|
27
|
+
state: data?.stateId || '',
|
|
28
|
+
zip: data?.zip || data?.zipCode || '',
|
|
29
|
+
linkedCryptoWallets: data?.linkedCryptoWallets || []
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
interface IUserData {
|
|
33
|
+
id: string;
|
|
34
|
+
firstName: string;
|
|
35
|
+
lastName: string;
|
|
36
|
+
email: string;
|
|
37
|
+
city?: string;
|
|
38
|
+
country?: string;
|
|
39
|
+
countryId?: string;
|
|
40
|
+
phone?: string;
|
|
41
|
+
streetAddress?: string;
|
|
42
|
+
state?: string;
|
|
43
|
+
zip?: string;
|
|
44
|
+
zipCode?: string;
|
|
45
|
+
stateId?: string;
|
|
46
|
+
linkedCryptoWallets?: string[];
|
|
47
|
+
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
exports.__esModule = true;
|
|
50
|
-
exports.PhoneNumberField = void 0;
|
|
51
|
-
var TextField_1 = require("@mui/material/TextField");
|
|
52
|
-
var debounce_1 = require("lodash/debounce");
|
|
53
|
-
var get_1 = require("lodash/get");
|
|
54
|
-
var react_1 = require("react");
|
|
55
|
-
var api_1 = require("../../api");
|
|
56
|
-
exports.PhoneNumberField = function (_a) {
|
|
57
|
-
var label = _a.label, _b = _a.type, type = _b === void 0 ? 'text' : _b, field = _a.field, _c = _a.form, errors = _c.errors, setFieldError = _c.setFieldError, setStatus = _c.setStatus;
|
|
58
|
-
var error = get_1["default"](errors, field.name);
|
|
59
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
-
var debounceCb = react_1.useCallback(debounce_1["default"](function (cb) { return void cb(); }, 1000), []);
|
|
61
|
-
react_1.useEffect(function () {
|
|
62
|
-
var _a;
|
|
63
|
-
if (field.value) {
|
|
64
|
-
setStatus((_a = {}, _a[field.name] = true, _a));
|
|
65
|
-
}
|
|
66
|
-
debounceCb(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
-
var error_1, message;
|
|
68
|
-
var _a;
|
|
69
|
-
return __generator(this, function (_b) {
|
|
70
|
-
switch (_b.label) {
|
|
71
|
-
case 0:
|
|
72
|
-
_b.trys.push([0, 3, 4, 5]);
|
|
73
|
-
if (!field.value) return [3 /*break*/, 2];
|
|
74
|
-
return [4 /*yield*/, api_1.validatePhoneNumber(field.value)];
|
|
75
|
-
case 1:
|
|
76
|
-
_b.sent();
|
|
77
|
-
_b.label = 2;
|
|
78
|
-
case 2:
|
|
79
|
-
setFieldError(field.name, '');
|
|
80
|
-
return [3 /*break*/, 5];
|
|
81
|
-
case 3:
|
|
82
|
-
error_1 = _b.sent();
|
|
83
|
-
message = get_1["default"](error_1, 'response.data.message', 'Invalid phone number');
|
|
84
|
-
setFieldError(field.name, message);
|
|
85
|
-
return [3 /*break*/, 5];
|
|
86
|
-
case 4:
|
|
87
|
-
setStatus((_a = {}, _a[field.name] = false, _a));
|
|
88
|
-
return [7 /*endfinally*/];
|
|
89
|
-
case 5: return [2 /*return*/];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}); });
|
|
93
|
-
// eslint-disable-next-line
|
|
94
|
-
}, [field.value]);
|
|
95
|
-
return (react_1["default"].createElement(TextField_1["default"], __assign({}, field, { id: field.name, label: label, type: type, fullWidth: true, error: !!error, helperText: error, value: field.value || '', inputProps: { pattern: '[+0-9]/d+' } })));
|
|
96
|
-
};
|