Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“g is not defined” error when using the ListControls component with a custom component in Payload beta version 121 #9019

Open
andyLyon-212 opened this issue Nov 4, 2024 · 0 comments
Labels
invalid-reproduction status: needs-triage Possible bug which hasn't been reproduced yet v3

Comments

@andyLyon-212
Copy link

andyLyon-212 commented Nov 4, 2024

Describe the Bug

After cloning the repository and installing Payload beta version 121, I created a custom component called Search and used it within a ui field. When utilizing the ListControls component inside this custom component and passing it a collection of type ClientCollectionConfig, I encounter the error “g is not defined”. Here’s the relevant code from my Search component:

'use client'

import React from 'react'
import { useField, TextField, Button, ListControls, useConfig } from '@payloadcms/ui'
import { TextFieldValidation, TextFieldClientProps } from 'payload'
import { text } from 'payload/shared'
import type { ClientCollectionConfig } from 'payload'

const colorMissingOctothorpRegex = new RegExp("^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{3})$");

export const Search: React.FC = ({ ...props }) => {
const { value, setValue } = useField({})

const validateText: TextFieldValidation = (value, options) => {
if (value && colorMissingOctothorpRegex.test(value)) {
value = #${value}
setValue(value)
}
return text(value, options)
}

const collectionSlug = 'pages';
const { getEntityConfig } = useConfig()
const collectionConfig = getEntityConfig({ collectionSlug }) as ClientCollectionConfig
console.log('collectionConfig', collectionConfig);
console.log('collectionConfig', collectionConfig.fields);

return (
<div className={'flex items-center gap-6'}>
<div
className={'color-swatch w-32 h-32'}
style={{ backgroundColor: value || '#00000000' }}
/>
<TextField {...props} validate={validateText} />
<Button
aria-label='Create New'
buttonStyle="pill"
onClick={() => { console.log('hello') }}
size="small"
>
Create New



)
}

Link to the code that reproduces this issue

https://github.com/andyLyon-212/payload-component-list-control

Reproduction Steps

Steps to reproduce:
1. Clone the repository and install Payload beta version 121.
2. Create the Search component as shown in the code and use it within a ui field.
3. Pass a collection configuration to ListControls.
4. Run the project and observe the console error.

Which area(s) are affected? (Select all that apply)

Not sure

Environment Info

Added by Payload

Database connection string

DATABASE_URI=mongodb://127.0.0.1/web

Used to encrypt JWT tokens

PAYLOAD_SECRET=b286822e58537e73583baa3c

Used to format links and URLs

PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
NEXT_PUBLIC_SERVER_URL=http://localhost:3000

Allow robots to index the site (optional)

NEXT_PUBLIC_IS_LIVE=

Used to preview drafts

PAYLOAD_PUBLIC_DRAFT_SECRET=demo-draft-secret
NEXT_PRIVATE_DRAFT_SECRET=demo-draft-secret

Used to revalidate static pages

REVALIDATION_KEY=demo-revalation-key
NEXT_PRIVATE_REVALIDATION_KEY=demo-revalation-key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid-reproduction status: needs-triage Possible bug which hasn't been reproduced yet v3
Projects
None yet
Development

No branches or pull requests

1 participant