2
2
3
3
import type { Data , TextFieldClientComponent } from 'payload'
4
4
5
- import { TextField , useLocale , useWatchForm } from '@payloadcms/ui'
5
+ import { TextField , useFieldProps , useLocale , useWatchForm } from '@payloadcms/ui'
6
6
import React , { useEffect , useState } from 'react'
7
7
8
8
type FieldWithID = {
@@ -17,13 +17,15 @@ export const DynamicPriceSelector: TextFieldClientComponent = (props) => {
17
17
18
18
const locale = useLocale ( )
19
19
20
+ const { path } = useFieldProps ( )
21
+
20
22
const [ isNumberField , setIsNumberField ] = useState < boolean > ( )
21
23
const [ valueType , setValueType ] = useState < 'static' | 'valueOfField' > ( )
22
24
23
25
// only number fields can use 'valueOfField`
24
26
useEffect ( ( ) => {
25
- if ( field ?. _path ) {
26
- const parentPath = field . _path . split ( '.' ) . slice ( 0 , - 1 ) . join ( '.' )
27
+ if ( path ) {
28
+ const parentPath = path . split ( '.' ) . slice ( 0 , - 1 ) . join ( '.' )
27
29
const paymentFieldData : any = getDataByPath ( parentPath )
28
30
29
31
if ( paymentFieldData ) {
@@ -40,7 +42,7 @@ export const DynamicPriceSelector: TextFieldClientComponent = (props) => {
40
42
}
41
43
}
42
44
}
43
- } , [ fields , field . _path , getDataByPath , getData ] )
45
+ } , [ fields , getDataByPath , getData , path ] )
44
46
45
47
// TODO: make this a number field, block by Payload
46
48
if ( valueType === 'static' ) {
0 commit comments