Fixed turnstile
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
'use client'
|
||||
import { useFormFields } from '@payloadcms/ui'
|
||||
|
||||
type Props = {
|
||||
/** Integration name shown in the banner, e.g. 'Turnstile'. */
|
||||
label: string
|
||||
/** Name of the hidden status group (buildIntegrationStatusField). */
|
||||
statusField: string
|
||||
}
|
||||
|
||||
const fmt = (iso: unknown) => {
|
||||
if (typeof iso !== 'string' || !iso) {return ''}
|
||||
const d = new Date(iso)
|
||||
return Number.isNaN(d.getTime()) ? '' : d.toLocaleString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Status banner on an integration's tab (Site Integrations). Shows nothing until
|
||||
* the integration has been used once; a red box while it's failing; a short
|
||||
* green line once it works again.
|
||||
*/
|
||||
export function IntegrationStatusBanner({ label, statusField }: Props) {
|
||||
const state = useFormFields(([f]) => f[`${statusField}.state`]?.value) as string | undefined
|
||||
const message = useFormFields(([f]) => f[`${statusField}.message`]?.value) as string | undefined
|
||||
const code = useFormFields(([f]) => f[`${statusField}.code`]?.value) as string | undefined
|
||||
const since = useFormFields(([f]) => f[`${statusField}.since`]?.value)
|
||||
const checkedAt = useFormFields(([f]) => f[`${statusField}.checkedAt`]?.value)
|
||||
|
||||
if (!state) {return null}
|
||||
|
||||
if (state === 'ok') {
|
||||
return (
|
||||
<div style={{ fontSize: '0.85rem', marginBottom: '1.5rem', opacity: 0.75 }}>
|
||||
✓ {label} working{since ? ` since ${fmt(since)}` : ''}.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="alert"
|
||||
style={{
|
||||
background: 'var(--theme-error-50, rgba(229, 72, 77, 0.08))',
|
||||
border: '1px solid var(--theme-error-400, #e5484d)',
|
||||
borderRadius: 4,
|
||||
marginBottom: '1.5rem',
|
||||
padding: '0.9rem 1rem',
|
||||
}}
|
||||
>
|
||||
<strong>{label} is not working — forms are accepted without this check.</strong>
|
||||
{message ? <div style={{ marginTop: '0.35rem' }}>{message}</div> : null}
|
||||
<div style={{ fontSize: '0.8rem', marginTop: '0.35rem', opacity: 0.75 }}>
|
||||
{code ? `Code: ${code}. ` : ''}
|
||||
{since ? `Since ${fmt(since)}. ` : ''}
|
||||
{checkedAt ? `Last seen ${fmt(checkedAt)}.` : ''}
|
||||
</div>
|
||||
<div style={{ fontSize: '0.8rem', marginTop: '0.35rem', opacity: 0.75 }}>
|
||||
Fix the keys below and save — the status is checked again on the next form submission.
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default IntegrationStatusBanner
|
||||
Reference in New Issue
Block a user