1
1
import { gql } from '@apollo/client'
2
2
import { InputAdornment } from '@mui/material'
3
3
import { useFormik } from 'formik'
4
+ import { useParams } from 'react-router-dom'
4
5
import { number , object } from 'yup'
5
6
6
7
import useCustomerPortalNavigation from '~/components/customerPortal/common/hooks/useCustomerPortalNavigation'
@@ -13,11 +14,20 @@ import { AmountInputField } from '~/components/form'
13
14
import { intlFormatNumber } from '~/core/formats/intlFormatNumber'
14
15
import {
15
16
CurrencyEnum ,
16
- useGetPortalWalletsQuery ,
17
+ useCustomerPortalWalletQuery ,
17
18
useTopUpPortalWalletMutation ,
18
19
} from '~/generated/graphql'
19
20
20
21
gql `
22
+ query customerPortalWallet($id: ID!) {
23
+ customerPortalWallet(id: $id) {
24
+ id
25
+ currency
26
+ name
27
+ rateAmount
28
+ }
29
+ }
30
+
21
31
mutation TopUpPortalWallet($input: CreateCustomerPortalWalletTransactionInput!) {
22
32
createCustomerPortalWalletTransaction(input: $input) {
23
33
collection {
28
38
`
29
39
30
40
const WalletPage = ( ) => {
41
+ const { walletId = '' } = useParams ( )
31
42
const { goHome } = useCustomerPortalNavigation ( )
32
43
const { translate, documentLocale } = useCustomerPortalTranslate ( )
33
44
@@ -36,7 +47,11 @@ const WalletPage = () => {
36
47
loading : customerWalletLoading ,
37
48
error : customerWalletError ,
38
49
refetch : customerWalletRefetch ,
39
- } = useGetPortalWalletsQuery ( )
50
+ } = useCustomerPortalWalletQuery ( {
51
+ variables : {
52
+ id : walletId ,
53
+ } ,
54
+ } )
40
55
41
56
const [ topUpPortalWallet , { loading : loadingTopUpPortalWallet , error : errorTopUpPortalWallet } ] =
42
57
useTopUpPortalWalletMutation ( {
@@ -49,7 +64,7 @@ const WalletPage = () => {
49
64
} ,
50
65
} )
51
66
52
- const wallet = customerWalletData ?. customerPortalWallets ?. collection ?. [ 0 ]
67
+ const wallet = customerWalletData ?. customerPortalWallet
53
68
54
69
const formikProps = useFormik ( {
55
70
initialValues : {
@@ -75,8 +90,7 @@ const WalletPage = () => {
75
90
const submitButtonDisabled =
76
91
! formikProps ?. values ?. amount || loadingTopUpPortalWallet || formikProps ?. values ?. amount <= 0
77
92
78
- const isLoading = customerWalletLoading
79
- const isError = ! isLoading && customerWalletError
93
+ const isError = ! customerWalletLoading && customerWalletError
80
94
81
95
if ( isError ) {
82
96
return (
@@ -92,9 +106,9 @@ const WalletPage = () => {
92
106
< div >
93
107
< PageTitle title = { translate ( 'text_1728498418253nyv3qmz9k5k' ) } goHome = { goHome } />
94
108
95
- { isLoading && < LoaderWalletPage /> }
109
+ { customerWalletLoading && < LoaderWalletPage /> }
96
110
97
- { ! isLoading && (
111
+ { ! customerWalletLoading && (
98
112
< div >
99
113
< AmountInputField
100
114
name = "amount"
0 commit comments