import type { Condition, Field } from 'payload' import { buildIntegrationStatusBanner, buildIntegrationStatusField } from '../../../modules/integrations/status.js' /** * E-mail sending settings (SMTP, or Microsoft Graph set up on the server). * * Protected at the global level (SiteIntegrations requires an authenticated * user), so all fields — including the password — stay editable in the admin * panel while remaining inaccessible to anonymous API requests. */ // SMTP fields only matter with the SMTP transport — hidden while Graph is selected. const usesSmtp: Condition = (_, siblingData) => siblingData?.emailTransport !== 'graph' export const smtpFields: Field[] = [ // Status written by mailAdapter on every send (throttled) — banner on this tab. buildIntegrationStatusBanner( 'emailStatus', { en: 'E-mail sending', pl: 'Wysyłka e-mail' }, { failing: 'statusEmailFailing', hint: 'statusEmailHint' }, ), { name: 'emailTransport', type: 'select', admin: { description: { en: 'Microsoft Graph works only when your administrator has set it up on the server.', pl: 'Microsoft Graph działa tylko wtedy, gdy administrator skonfiguruje go na serwerze.', }, // The Graph option only makes sense when agency credentials exist in env. // We can't read process.env in the admin UI directly, so a client project // that hasn't set up Graph should filter this option via integrationsFields // override, or simply leave it on 'smtp'. The adapter enforces the real // availability at send time regardless of what's selected here. }, defaultValue: 'smtp', label: { en: 'Sending method', pl: 'Sposób wysyłki' }, options: [ { label: { en: 'SMTP server', pl: 'Serwer SMTP' }, value: 'smtp' }, { label: { en: 'Microsoft Graph (Exchange)', pl: 'Microsoft Graph (Exchange)' }, value: 'graph' }, ], }, { type: 'row', fields: [ { name: 'smtpFromAddress', type: 'email', admin: { description: { en: 'E-mails are sent from this address; with Microsoft Graph, replies go to it.', pl: 'Z tego adresu wychodzą e-maile; przy Microsoft Graph trafiają na niego odpowiedzi.', }, placeholder: 'info@example.com', width: '50%', }, label: { en: 'Sender address', pl: 'Adres nadawcy' }, }, { name: 'smtpFromName', type: 'text', admin: { description: { en: 'The name recipients see, e.g. the company name.', pl: 'Nazwa widoczna dla odbiorcy, np. nazwa firmy.', }, width: '50%', }, label: { en: 'Sender name', pl: 'Nazwa nadawcy' }, }, ], }, { type: 'row', admin: { condition: usesSmtp }, fields: [ { name: 'smtpHost', type: 'text', admin: { placeholder: 'smtp.example.com', width: '70%' }, label: { en: 'Server', pl: 'Serwer' }, }, { name: 'smtpPort', type: 'number', admin: { description: { en: 'Usually 587, or 465.', pl: 'Zwykle 587 lub 465.' }, width: '30%', }, defaultValue: 587, label: { en: 'Port', pl: 'Port' }, }, ], }, { name: 'smtpUser', type: 'text', admin: { condition: usesSmtp }, label: { en: 'User name', pl: 'Nazwa użytkownika' }, }, { name: 'smtpPassword', type: 'text', admin: { // Masked in the UI (••••) — stored plaintext, readable for SMTP auth. components: { Field: '@intecion/ipal-kit/admin#MaskedField', }, condition: usesSmtp, }, label: { en: 'Password', pl: 'Hasło' }, }, { name: 'emailTest', type: 'ui', admin: { components: { Field: '@intecion/ipal-kit/admin#TestEmailButton', }, }, }, buildIntegrationStatusField('emailStatus'), ]