- admin-i18n module: AdminText { en, pl }, component texts under the ipal
namespace (project translations win), en + pl admin languages when the
project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
messages, Privacy group, Search engines, Maintenance, Spam protection,
E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
env var names out of editor messages; stats numbers/dates in the admin
language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words
Co-Authored-By: Claude Opus 5.5 <[email protected]>
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
'use client'
|
|
|
|
import type { TextFieldClientComponent } from 'payload'
|
|
|
|
import { FieldDescription, FieldLabel, useField, useTranslation } from '@payloadcms/ui'
|
|
import { useState } from 'react'
|
|
|
|
import { ipalT } from '../../../modules/admin-i18n/t.js'
|
|
|
|
/**
|
|
* Masked text input for sensitive values (SMTP password, R2 secret key,
|
|
* Turnstile secret key, etc.).
|
|
*
|
|
* Renders the value as a password field (••••) so secrets aren't shown in
|
|
* plaintext on screen — protecting against shoulder-surfing and accidental
|
|
* exposure when the panel is open. The value is still stored and returned
|
|
* normally (UI masking, NOT hashing or encryption), because the plugin must
|
|
* read it back to authenticate with SMTP/R2/Turnstile. A toggle reveals the
|
|
* value when an authorised editor genuinely needs to check it.
|
|
*
|
|
* Uses a raw <input> driven by useField rather than @payloadcms/ui's TextInput,
|
|
* because TextInput doesn't expose inputProps, so there's no way to switch its
|
|
* inner input to type="password".
|
|
*
|
|
* Assigned via a field's admin.components.Field. Works on any `text` field.
|
|
*/
|
|
export const MaskedField: TextFieldClientComponent = ({ field, path }) => {
|
|
const { t } = useTranslation()
|
|
const { setValue, value } = useField<string>({ path })
|
|
const [revealed, setRevealed] = useState(false)
|
|
|
|
// A string or one string per language — FieldLabel / FieldDescription translate it.
|
|
const label = field?.label || field?.name || path
|
|
const description = field?.admin?.description
|
|
|
|
return (
|
|
<div className="field-type text masked-field">
|
|
<FieldLabel htmlFor={`field-${path}`} label={label} />
|
|
|
|
<div className="field-type__wrap" style={{ alignItems: 'center', display: 'flex', gap: '.5rem' }}>
|
|
{/* Labelled by <FieldLabel htmlFor> above — the rule can't see through the component. */}
|
|
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
|
|
<input
|
|
autoComplete="off"
|
|
className="field-type__input"
|
|
id={`field-${path}`}
|
|
onChange={(e) => setValue(e.target.value)}
|
|
style={{ flex: 1 }}
|
|
type={revealed ? 'text' : 'password'}
|
|
value={value ?? ''}
|
|
/>
|
|
<button
|
|
onClick={() => setRevealed((r) => !r)}
|
|
style={{
|
|
background: 'none',
|
|
border: 'none',
|
|
cursor: 'pointer',
|
|
font: 'inherit',
|
|
opacity: 0.75,
|
|
padding: '.25rem .5rem',
|
|
textDecoration: 'underline',
|
|
whiteSpace: 'nowrap',
|
|
}}
|
|
type="button"
|
|
>
|
|
{ipalT(t as never, revealed ? 'maskedHide' : 'maskedShow')}
|
|
</button>
|
|
</div>
|
|
|
|
{description && typeof description !== 'function' ? (
|
|
<FieldDescription description={description} path={path} />
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default MaskedField
|