SmtpForm.utils.ts31 lines · main
| 1 | import type { components } from '@/data/api' |
| 2 | |
| 3 | type AuthConfig = components['schemas']['GoTrueConfigResponse'] |
| 4 | |
| 5 | interface AuthConfigForm extends AuthConfig { |
| 6 | ENABLE_SMTP: boolean |
| 7 | } |
| 8 | |
| 9 | export const isSmtpEnabled = (config?: Partial<AuthConfig>): boolean => { |
| 10 | return !!( |
| 11 | config?.SMTP_ADMIN_EMAIL && |
| 12 | config?.SMTP_SENDER_NAME && |
| 13 | config?.SMTP_USER && |
| 14 | config?.SMTP_HOST && |
| 15 | config?.SMTP_PORT && |
| 16 | (config?.SMTP_MAX_FREQUENCY ?? 0) >= 0 |
| 17 | ) |
| 18 | } |
| 19 | |
| 20 | export const generateFormValues = (config?: Partial<AuthConfig>): Partial<AuthConfigForm> => { |
| 21 | return { |
| 22 | ENABLE_SMTP: isSmtpEnabled(config), |
| 23 | SMTP_ADMIN_EMAIL: config?.SMTP_ADMIN_EMAIL ?? '', |
| 24 | SMTP_SENDER_NAME: config?.SMTP_SENDER_NAME ?? '', |
| 25 | SMTP_USER: config?.SMTP_USER ?? '', |
| 26 | SMTP_HOST: config?.SMTP_HOST ?? '', |
| 27 | SMTP_PASS: '', |
| 28 | SMTP_PORT: config?.SMTP_PORT ?? '465', |
| 29 | SMTP_MAX_FREQUENCY: config?.SMTP_MAX_FREQUENCY ?? 60, |
| 30 | } |
| 31 | } |