Skip to content

Commit

Permalink
chore(templates): fix eslint errors in website template (#10752)
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanJablo authored Jan 23, 2025
1 parent 2d8ff72 commit 5689c65
Show file tree
Hide file tree
Showing 31 changed files with 49 additions and 96 deletions.
3 changes: 3 additions & 0 deletions templates/website/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const eslintConfig = [
],
},
},
{
ignores: ['.next/'],
},
]

export default eslintConfig
4 changes: 3 additions & 1 deletion templates/website/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export default {
const config = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

export default config
2 changes: 1 addition & 1 deletion templates/website/src/Footer/RowLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Header } from '@/payload-types'
import { RowLabelProps, useRowLabel } from '@payloadcms/ui'

export const RowLabel: React.FC<RowLabelProps> = (props) => {
export const RowLabel: React.FC<RowLabelProps> = () => {
const data = useRowLabel<NonNullable<Header['navItems']>[number]>()

const label = data?.data?.link?.label
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/Header/RowLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Header } from '@/payload-types'
import { RowLabelProps, useRowLabel } from '@payloadcms/ui'

export const RowLabel: React.FC<RowLabelProps> = (props) => {
export const RowLabel: React.FC<RowLabelProps> = () => {
const data = useRowLabel<NonNullable<Header['navItems']>[number]>()

const label = data?.data?.link?.label
Expand Down
3 changes: 0 additions & 3 deletions templates/website/src/app/(frontend)/next/preview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { getPayload, type PayloadRequest } from 'payload'
import configPromise from '@payload-config'
import { CollectionSlug } from 'payload'

const payloadToken = 'payload-token'

export async function GET(
req: Request & {
cookies: {
Expand All @@ -16,7 +14,6 @@ export async function GET(
},
): Promise<Response> {
const payload = await getPayload({ config: configPromise })
const token = req.cookies.get(payloadToken)?.value
const { searchParams } = new URL(req.url)
const path = searchParams.get('path')
const collection = searchParams.get('collection') as CollectionSlug
Expand Down
10 changes: 1 addition & 9 deletions templates/website/src/app/(frontend)/next/seed/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ import { headers } from 'next/headers'

export const maxDuration = 60 // This function can run for a maximum of 60 seconds

export async function POST(
req: Request & {
cookies: {
get: (name: string) => {
value: string
}
}
},
): Promise<Response> {
export async function POST(): Promise<Response> {
const payload = await getPayload({ config })
const requestHeaders = await headers()

Expand Down
1 change: 0 additions & 1 deletion templates/website/src/app/(frontend)/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CollectionArchive } from '@/components/CollectionArchive'
import configPromise from '@payload-config'
import { getPayload } from 'payload'
import React from 'react'
import { Post } from '@/payload-types'
import { Search } from '@/search/Component'
import PageClient from './page.client'
import { CardPostData } from '@/components/Card'
Expand Down
8 changes: 1 addition & 7 deletions templates/website/src/blocks/Form/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ import { Width } from '../Width'

export const Checkbox: React.FC<
CheckboxField & {
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
getValues: any
errors: Partial<FieldErrorsImpl>
register: UseFormRegister<FieldValues>
setValue: any
}
> = ({ name, defaultValue, errors, label, register, required, width }) => {
const props = register(name, { required: required })
Expand Down
1 change: 1 addition & 0 deletions templates/website/src/blocks/Form/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const FormBlock: React.FC<
{formFromProps &&
formFromProps.fields &&
formFromProps.fields?.map((field, index) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const Field: React.FC<any> = fields?.[field.blockType as keyof typeof fields]
if (Field) {
return (
Expand Down
10 changes: 3 additions & 7 deletions templates/website/src/blocks/Form/Country/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CountryField } from '@payloadcms/plugin-form-builder/types'
import type { Control, FieldErrorsImpl, FieldValues } from 'react-hook-form'
import type { Control, FieldErrorsImpl } from 'react-hook-form'

import { Label } from '@/components/ui/label'
import {
Expand All @@ -18,12 +18,8 @@ import { countryOptions } from './options'

export const Country: React.FC<
CountryField & {
control: Control<FieldValues, any>
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
control: Control
errors: Partial<FieldErrorsImpl>
}
> = ({ name, control, errors, label, required, width }) => {
return (
Expand Down
6 changes: 1 addition & 5 deletions templates/website/src/blocks/Form/Email/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import { Width } from '../Width'

export const Email: React.FC<
EmailField & {
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
errors: Partial<FieldErrorsImpl>
register: UseFormRegister<FieldValues>
}
> = ({ name, defaultValue, errors, label, register, required, width }) => {
Expand Down
6 changes: 1 addition & 5 deletions templates/website/src/blocks/Form/Number/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { Error } from '../Error'
import { Width } from '../Width'
export const Number: React.FC<
TextField & {
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
errors: Partial<FieldErrorsImpl>
register: UseFormRegister<FieldValues>
}
> = ({ name, defaultValue, errors, label, register, required, width }) => {
Expand Down
10 changes: 3 additions & 7 deletions templates/website/src/blocks/Form/Select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SelectField } from '@payloadcms/plugin-form-builder/types'
import type { Control, FieldErrorsImpl, FieldValues } from 'react-hook-form'
import type { Control, FieldErrorsImpl } from 'react-hook-form'

import { Label } from '@/components/ui/label'
import {
Expand All @@ -17,12 +17,8 @@ import { Width } from '../Width'

export const Select: React.FC<
SelectField & {
control: Control<FieldValues, any>
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
control: Control
errors: Partial<FieldErrorsImpl>
}
> = ({ name, control, errors, label, options, required, width }) => {
return (
Expand Down
10 changes: 3 additions & 7 deletions templates/website/src/blocks/Form/State/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StateField } from '@payloadcms/plugin-form-builder/types'
import type { Control, FieldErrorsImpl, FieldValues } from 'react-hook-form'
import type { Control, FieldErrorsImpl } from 'react-hook-form'

import { Label } from '@/components/ui/label'
import {
Expand All @@ -18,12 +18,8 @@ import { stateOptions } from './options'

export const State: React.FC<
StateField & {
control: Control<FieldValues, any>
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
control: Control
errors: Partial<FieldErrorsImpl>
}
> = ({ name, control, errors, label, required, width }) => {
return (
Expand Down
6 changes: 1 addition & 5 deletions templates/website/src/blocks/Form/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import { Width } from '../Width'

export const Text: React.FC<
TextField & {
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
errors: Partial<FieldErrorsImpl>
register: UseFormRegister<FieldValues>
}
> = ({ name, defaultValue, errors, label, register, required, width }) => {
Expand Down
6 changes: 1 addition & 5 deletions templates/website/src/blocks/Form/Textarea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import { Width } from '../Width'

export const Textarea: React.FC<
TextField & {
errors: Partial<
FieldErrorsImpl<{
[x: string]: any
}>
>
errors: Partial<FieldErrorsImpl>
register: UseFormRegister<FieldValues>
rows?: number
}
Expand Down
3 changes: 2 additions & 1 deletion templates/website/src/blocks/RelatedPosts/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import RichText from '@/components/RichText'
import type { Post } from '@/payload-types'

import { Card } from '../../components/Card'
import { SerializedEditorState } from '@payloadcms/richtext-lexical/lexical'

export type RelatedPostsProps = {
className?: string
docs?: Post[]
introContent?: any
introContent?: SerializedEditorState
}

export const RelatedPosts: React.FC<RelatedPostsProps> = (props) => {
Expand Down
1 change: 0 additions & 1 deletion templates/website/src/blocks/RenderBlocks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { cn } from '@/utilities/ui'
import React, { Fragment } from 'react'

import type { Page } from '@/payload-types'
Expand Down
2 changes: 0 additions & 2 deletions templates/website/src/components/CollectionArchive/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { cn } from '@/utilities/ui'
import React from 'react'

import type { Post } from '@/payload-types'

import { Card, CardPostData } from '@/components/Card'

export type Props = {
Expand Down
8 changes: 1 addition & 7 deletions templates/website/src/components/Media/ImageMedia/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ export const ImageMedia: React.FC<MediaProps> = (props) => {
let src: StaticImageData | string = srcFromProps || ''

if (!src && resource && typeof resource === 'object') {
const {
alt: altFromResource,
filename: fullFilename,
height: fullHeight,
url,
width: fullWidth,
} = resource
const { alt: altFromResource, height: fullHeight, url, width: fullWidth } = resource

width = fullWidth!
height = fullHeight!
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/components/Media/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Media: React.FC<Props> = (props) => {
const { className, htmlElement = 'div', resource } = props

const isVideo = typeof resource === 'object' && resource?.mimeType?.includes('video')
const Tag = (htmlElement as any) || Fragment
const Tag = htmlElement || Fragment

return (
<Tag
Expand Down
1 change: 0 additions & 1 deletion templates/website/src/endpoints/seed/contact-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const contact: Partial<Page> = {
{
blockType: 'formBlock',
enableIntro: true,
// @ts-ignore
form: '{{CONTACT_FORM_ID}}',
introContent: {
root: {
Expand Down
5 changes: 4 additions & 1 deletion templates/website/src/endpoints/seed/home-static.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Page } from '@/payload-types'

// Used for pre-seeded content so that the homepage is not empty
// @ts-expect-error
export const homeStatic: Page = {
slug: 'home',
_status: 'published',
Expand Down Expand Up @@ -85,4 +84,8 @@ export const homeStatic: Page = {
title: 'Payload Website Template',
},
title: 'Home',
id: '',
layout: [],
updatedAt: '',
createdAt: '',
}
3 changes: 0 additions & 3 deletions templates/website/src/endpoints/seed/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const home: RequiredDataFromCollectionSlug<'pages'> = {
},
},
],
// @ts-ignore
media: '{{IMAGE_1}}',
richText: {
root: {
Expand Down Expand Up @@ -502,7 +501,6 @@ export const home: RequiredDataFromCollectionSlug<'pages'> = {
{
blockName: 'Media Block',
blockType: 'mediaBlock',
// @ts-ignore
media: '{{IMAGE_2}}',
},
{
Expand Down Expand Up @@ -659,7 +657,6 @@ export const home: RequiredDataFromCollectionSlug<'pages'> = {
],
meta: {
description: 'An open-source website built with Payload and Next.js.',
// @ts-ignore
image: '{{IMAGE_1}}',
title: 'Payload Website Template',
},
Expand Down
3 changes: 0 additions & 3 deletions templates/website/src/endpoints/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ export const seed = async ({
technologyCategory,
newsCategory,
financeCategory,
designCategory,
softwareCategory,
engineeringCategory,
] = await Promise.all([
payload.create({
collection: 'users',
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/fields/slug/formatSlug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const formatSlug = (val: string): string =>

export const formatSlugHook =
(fallback: string): FieldHook =>
({ data, operation, originalDoc, value }) => {
({ data, operation, value }) => {
if (typeof value === 'string') {
return formatSlug(value)
}
Expand Down
3 changes: 1 addition & 2 deletions templates/website/src/fields/slug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const slugField: Slug = (fieldToUse = 'title', overrides = {}) => {
...checkboxOverrides,
}

// Expect ts error here because of typescript mismatching Partial<TextField> with TextField
// @ts-expect-error
// @ts-expect-error - ts mismatch Partial<TextField> with TextField
const slugField: TextField = {
name: 'slug',
type: 'text',
Expand Down
2 changes: 1 addition & 1 deletion templates/website/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1645,4 +1645,4 @@ export interface Auth {

declare module 'payload' {
export interface GeneratedTypes extends Config {}
}
}
6 changes: 3 additions & 3 deletions templates/website/src/search/beforeSync.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BeforeSync, DocToSync } from '@payloadcms/plugin-search/types'

export const beforeSyncWithSearch: BeforeSync = async ({ originalDoc, searchDoc, payload }) => {
export const beforeSyncWithSearch: BeforeSync = async ({ originalDoc, searchDoc }) => {
const {
doc: { relationTo: collection },
} = searchDoc

const { slug, id, categories, title, meta, excerpt } = originalDoc
const { slug, id, categories, title, meta } = originalDoc

const modifiedDoc: DocToSync = {
...searchDoc,
Expand Down Expand Up @@ -33,7 +33,7 @@ export const beforeSyncWithSearch: BeforeSync = async ({ originalDoc, searchDoc,
})

modifiedDoc.categories = mappedCategories
} catch (err) {
} catch (_err) {
console.error(
`Failed. Category not found when syncing collection '${collection}' with id: '${id}' to search.`,
)
Expand Down
5 changes: 3 additions & 2 deletions templates/website/src/utilities/deepMerge.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

/**
* Simple object check.
* @param item
* @returns {boolean}
*/
export function isObject(item: unknown): boolean {
return item && typeof item === 'object' && !Array.isArray(item)
export function isObject(item: unknown): item is object {
return typeof item === 'object' && !Array.isArray(item)
}

/**
Expand Down
Loading

0 comments on commit 5689c65

Please # to comment.