Initial release of Moniki paid services site and CMS (v1.0.0).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import type { UIFieldServerComponent } from 'payload'
|
||||
|
||||
export const ResendStatus: UIFieldServerComponent = () => {
|
||||
const hasEnvKey = Boolean(process.env.RESEND_API_KEY)
|
||||
|
||||
return (
|
||||
<div className="field-type" style={{ marginBottom: 16 }}>
|
||||
<p style={{ margin: 0, color: 'var(--theme-elevation-600)' }}>
|
||||
Ключ в окружении <code>RESEND_API_KEY</code>: {hasEnvKey ? 'задан' : 'не задан'}.
|
||||
Админский ключ из формы имеет приоритет, если заполнен.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
'use client'
|
||||
|
||||
import type { TextFieldClientComponent } from 'payload'
|
||||
import { FieldDescription, FieldError, FieldLabel, useField } from '@payloadcms/ui'
|
||||
|
||||
export const SecretField: TextFieldClientComponent = ({ field, path, readOnly }) => {
|
||||
const { errorMessage, showError, value, setValue } = useField<string>({ path })
|
||||
const label = typeof field.label === 'string' ? field.label : 'API-ключ Resend'
|
||||
|
||||
return (
|
||||
<div className="field-type text">
|
||||
<FieldLabel htmlFor={`field-${path}`} label={label} path={path} required={field.required} />
|
||||
<input
|
||||
autoComplete="new-password"
|
||||
disabled={Boolean(readOnly)}
|
||||
id={`field-${path}`}
|
||||
name={path}
|
||||
onChange={(event) => setValue(event.target.value)}
|
||||
type="password"
|
||||
value={value || ''}
|
||||
/>
|
||||
<FieldError message={errorMessage} path={path} showError={showError} />
|
||||
{field.admin?.description ? (
|
||||
<FieldDescription description={field.admin.description} path={path} />
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
'use client'
|
||||
|
||||
import { Button, toast, useFormFields } from '@payloadcms/ui'
|
||||
import { useState } from 'react'
|
||||
|
||||
export function SendTestEmail() {
|
||||
const testEmail = useFormFields(([fields]) => fields.testEmail?.value as string | undefined)
|
||||
const [pending, setPending] = useState(false)
|
||||
|
||||
async function sendTest() {
|
||||
setPending(true)
|
||||
try {
|
||||
const res = await fetch('/api/custom/email/test', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ to: testEmail }),
|
||||
})
|
||||
const data = (await res.json()) as { error?: string; skipped?: boolean }
|
||||
if (!res.ok) {
|
||||
throw new Error(data.error || 'Не удалось отправить письмо')
|
||||
}
|
||||
if (data.skipped) {
|
||||
toast.info('Рассылка выключена — включите её и сохраните настройки.')
|
||||
return
|
||||
}
|
||||
toast.success('Тестовое письмо отправлено')
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : 'Ошибка отправки')
|
||||
} finally {
|
||||
setPending(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="field-type" style={{ marginBottom: 24 }}>
|
||||
<Button buttonStyle="secondary" disabled={pending} onClick={sendTest} type="button">
|
||||
{pending ? 'Отправка…' : 'Отправить тестовое письмо'}
|
||||
</Button>
|
||||
<p style={{ margin: '8px 0 0', color: 'var(--theme-elevation-500)', fontSize: 13 }}>
|
||||
Сначала сохраните настройки. Письмо уйдёт на адрес выше или на email текущего пользователя.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user