Skip to content

Commit

Permalink
Merge pull request #22 from rohitkumbhar/21-ux-allow-setting-sender-n…
Browse files Browse the repository at this point in the history
…ame-and-address-in-the-smtp-settings

#21 Adds Sender Name and address to the smtp settings
  • Loading branch information
rohitkumbhar authored Jan 12, 2025
2 parents e682c89 + 4d858ee commit ead8774
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
33 changes: 32 additions & 1 deletion src/components/settings/SmtpSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type SmtpSettings = {
tls?: boolean;
localName?: string;
authMethod?: 'PLAIN' | 'LOGIN';
senderName?: string,
senderAddress?: string
};

export const SmtpSettingsForm = () => {
Expand All @@ -38,6 +40,8 @@ export const SmtpSettingsForm = () => {
const { t } = useTranslation();

const initialValues: SmtpSettings = {
senderName: settings?.senderName,
senderAddress: settings?.senderAddress,
enabled: settings?.enabled,
host: settings?.host,
localName: settings?.localName || (window.location.hostname !== 'localhost' ? window.location.hostname : undefined),
Expand All @@ -61,6 +65,12 @@ export const SmtpSettingsForm = () => {
message: t('smtp_settings_updated', 'SMTP Settings updated'),
position: 'top-right',
});
}).catch(() => {
notifications.show({
title: t('smtp_settings', 'SMTP Settings'),
message: t('smtp_settings_update_failed', 'SMTP Settings could not be updated'),
position: 'top-right',
});
});
}
};
Expand Down Expand Up @@ -100,7 +110,27 @@ export const SmtpSettingsForm = () => {
{...form.getInputProps('enabled', { type: 'checkbox' })}
/>
</Group>
<Group>
<Group mt={'sm'}>
<TextInput
name={'senderName'}
label={t('smtp_sender_name', 'Sender Name')}
description={t('smtp_sender_name_description', 'Name of the sender')}
required
key={form.key('senderName')}
{...form.getInputProps('senderName')}
/>

<TextInput
name={'senderAddress'}
label={t('smtp_sender_address', 'Sender Address')}
description={t('smtp_sender_name_description', 'Email address of the sender')}
required
type={'email'}
key={form.key('senderAddress')}
{...form.getInputProps('senderAddress')}
/>
</Group>
<Group mt={'sm'}>
<TextInput
name={'host'}
label={t('smtp_host', 'Host')}
Expand All @@ -124,6 +154,7 @@ export const SmtpSettingsForm = () => {
label={t('smtp_local_name', 'Local Server Name')}
description={t('smtp_local_name', 'Local domain name. Default is localhost')}
required
type={'domain'}
key={form.key('localName')}
{...form.getInputProps('localName')}
/>
Expand Down
20 changes: 18 additions & 2 deletions src/lib/pocketbase/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@ import { pbAdmin } from './pocketbase.ts';
import { SmtpSettings } from '../../components/settings/SmtpSettingsForm.tsx';

export const getSmtpSettings = (): Promise<SmtpSettings | undefined> => {
return pbAdmin.settings.getAll({ fields: 'smtp' }).then((settings) => settings.smtp as SmtpSettings);
return pbAdmin.settings.getAll().then((settings) => {
return {
senderName: settings.meta.senderName,
senderAddress: settings.meta.senderAddress,
...settings.smtp,
} as SmtpSettings;
});
};

export const updateSmtpSettings = (settings: SmtpSettings) => {
return pbAdmin.settings.update({ smtp: settings }).then((settings) => settings.smtp as SmtpSettings);

const { senderName, senderAddress, ...smtpsettings } = settings;

const payload = {
meta: {
senderName: senderName,
senderAddress: senderAddress,
},
smtp: { ...smtpsettings },
};
return pbAdmin.settings.update(payload).then((settings) => settings.smtp as SmtpSettings);
};

0 comments on commit ead8774

Please sign in to comment.