Lint: fix all ESLint errors (391 -> 0), lint and typecheck tests
Mostly perfectionist import/key sorting and curly braces from --fix, plus: - spread instead of .apply() in the Meta Pixel stub - non-capturing group in the locale-code pattern - React 19 use(Context) / <Context value> in TurnstileProvider - email regex rewritten without super-linear backtracking (covered by a test) - console.warn/error allowed (deliberate server diagnostics) - test/tsconfig.json so the project service and tsc see test files Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
'use client'
|
||||
|
||||
import { useField, FieldLabel, FieldDescription } from '@payloadcms/ui'
|
||||
import { useState } from 'react'
|
||||
import type { TextFieldClientComponent } from 'payload'
|
||||
|
||||
import { FieldDescription, FieldLabel, useField } from '@payloadcms/ui'
|
||||
import { useState } from 'react'
|
||||
|
||||
/**
|
||||
* Masked text input for sensitive values (SMTP password, R2 secret key,
|
||||
* Turnstile secret key, etc.).
|
||||
@@ -22,7 +23,7 @@ import type { TextFieldClientComponent } from 'payload'
|
||||
* Assigned via a field's admin.components.Field. Works on any `text` field.
|
||||
*/
|
||||
export const MaskedField: TextFieldClientComponent = ({ field, path }) => {
|
||||
const { value, setValue } = useField<string>({ path })
|
||||
const { setValue, value } = useField<string>({ path })
|
||||
const [revealed, setRevealed] = useState(false)
|
||||
|
||||
const label =
|
||||
@@ -31,38 +32,38 @@ export const MaskedField: TextFieldClientComponent = ({ field, path }) => {
|
||||
|
||||
return (
|
||||
<div className="field-type text masked-field">
|
||||
<FieldLabel label={label} htmlFor={`field-${path}`} />
|
||||
<FieldLabel htmlFor={`field-${path}`} label={label} />
|
||||
|
||||
<div className="field-type__wrap" style={{ display: 'flex', gap: '.5rem', alignItems: 'center' }}>
|
||||
<div className="field-type__wrap" style={{ alignItems: 'center', display: 'flex', gap: '.5rem' }}>
|
||||
<input
|
||||
id={`field-${path}`}
|
||||
type={revealed ? 'text' : 'password'}
|
||||
autoComplete="off"
|
||||
className="field-type__input"
|
||||
value={value ?? ''}
|
||||
id={`field-${path}`}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
style={{ flex: 1 }}
|
||||
type={revealed ? 'text' : 'password'}
|
||||
value={value ?? ''}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setRevealed((r) => !r)}
|
||||
style={{
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
padding: '.25rem .5rem',
|
||||
cursor: 'pointer',
|
||||
font: 'inherit',
|
||||
textDecoration: 'underline',
|
||||
opacity: 0.75,
|
||||
padding: '.25rem .5rem',
|
||||
textDecoration: 'underline',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
type="button"
|
||||
>
|
||||
{revealed ? 'Hide' : 'Reveal'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{description && typeof description === 'string' ? (
|
||||
<FieldDescription path={path} description={description} />
|
||||
<FieldDescription description={description} path={path} />
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@ import { useState } from 'react'
|
||||
export const TestEmailButton = () => {
|
||||
const [to, setTo] = useState('')
|
||||
const [status, setStatus] = useState<
|
||||
{ kind: 'idle' } | { kind: 'sending' } | { kind: 'ok'; msg: string } | { kind: 'error'; msg: string }
|
||||
{ kind: 'error'; msg: string } | { kind: 'idle' } | { kind: 'ok'; msg: string } | { kind: 'sending' }
|
||||
>({ kind: 'idle' })
|
||||
|
||||
const send = async () => {
|
||||
@@ -25,10 +25,10 @@ export const TestEmailButton = () => {
|
||||
setStatus({ kind: 'sending' })
|
||||
try {
|
||||
const res = await fetch('/api/ipal/test-email', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ to: to.trim() }),
|
||||
credentials: 'include',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
method: 'POST',
|
||||
})
|
||||
const data = await res.json()
|
||||
if (data.ok) {
|
||||
@@ -44,23 +44,23 @@ export const TestEmailButton = () => {
|
||||
return (
|
||||
<div className="field-type" style={{ marginTop: '1rem' }}>
|
||||
<label className="field-label">Send a test email</label>
|
||||
<p style={{ opacity: 0.7, fontSize: '.85rem', marginTop: 0 }}>
|
||||
<p style={{ fontSize: '.85rem', marginTop: 0, opacity: 0.7 }}>
|
||||
Sends through the transport selected above. Save your changes first.
|
||||
</p>
|
||||
<div style={{ display: 'flex', gap: '.5rem', alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
<div style={{ alignItems: 'center', display: 'flex', flexWrap: 'wrap', gap: '.5rem' }}>
|
||||
<input
|
||||
type="email"
|
||||
placeholder="[email protected]"
|
||||
value={to}
|
||||
onChange={(e) => setTo(e.target.value)}
|
||||
placeholder="[email protected]"
|
||||
style={{ flex: 1, minWidth: '220px' }}
|
||||
type="email"
|
||||
value={to}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={send}
|
||||
disabled={status.kind === 'sending'}
|
||||
className="btn btn--style-secondary"
|
||||
disabled={status.kind === 'sending'}
|
||||
onClick={send}
|
||||
style={{ whiteSpace: 'nowrap' }}
|
||||
type="button"
|
||||
>
|
||||
{status.kind === 'sending' ? 'Sending…' : 'Send test'}
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user