Skip to content

Commit

Permalink
fix: #8903, form-builder payment static value field
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikrut committed Oct 28, 2024
1 parent aea1b41 commit c9a5a57
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { Data, TextFieldClientComponent } from 'payload'

import { TextField, useLocale, useWatchForm } from '@payloadcms/ui'
import { TextField, useFieldProps, useLocale, useWatchForm } from '@payloadcms/ui'
import React, { useEffect, useState } from 'react'

type FieldWithID = {
Expand All @@ -17,13 +17,15 @@ export const DynamicPriceSelector: TextFieldClientComponent = (props) => {

const locale = useLocale()

const { path } = useFieldProps()

const [isNumberField, setIsNumberField] = useState<boolean>()
const [valueType, setValueType] = useState<'static' | 'valueOfField'>()

// only number fields can use 'valueOfField`
useEffect(() => {
if (field?._path) {
const parentPath = field._path.split('.').slice(0, -1).join('.')
if (path) {
const parentPath = path.split('.').slice(0, -1).join('.')
const paymentFieldData: any = getDataByPath(parentPath)

if (paymentFieldData) {
Expand All @@ -40,7 +42,7 @@ export const DynamicPriceSelector: TextFieldClientComponent = (props) => {
}
}
}
}, [fields, field._path, getDataByPath, getData])
}, [fields, getDataByPath, getData, path])

// TODO: make this a number field, block by Payload
if (valueType === 'static') {
Expand Down

0 comments on commit c9a5a57

Please sign in to comment.