Skip to content

Commit

Permalink
Merge pull request #672 from openstad/feat/add-fromname-for-email-not…
Browse files Browse the repository at this point in the history
…ifications

feat: Add fromName to notifications
  • Loading branch information
iandebruin98 authored Nov 1, 2024
2 parents 9a3467f + 463de0f commit b37c4bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useForm } from 'react-hook-form';
import { Button } from '@/components/ui/button';
import {
Form,
FormControl,
FormControl, FormDescription,
FormField,
FormItem,
FormLabel,
Expand All @@ -25,6 +25,7 @@ import InfoDialog from '@/components/ui/info-hover';
const formSchema = z.object({
fromAddress: z.string().email(),
projectmanagerAddress: z.string().email(),
fromName: z.string().optional(),
});

export default function ProjectSettingsNotifications() {
Expand All @@ -36,6 +37,7 @@ export default function ProjectSettingsNotifications() {
const defaults = useCallback(
() => ({
fromAddress: data?.emailConfig?.[category]?.fromAddress || null,
fromName: data?.emailConfig?.[category]?.fromName || '',
projectmanagerAddress:
data?.emailConfig?.[category]?.projectmanagerAddress || null,
}),
Expand All @@ -57,6 +59,7 @@ export default function ProjectSettingsNotifications() {
[category]: {
fromAddress: values.fromAddress,
projectmanagerAddress: values.projectmanagerAddress,
fromName: values.fromName,
},
});
if (project) {
Expand Down Expand Up @@ -110,6 +113,23 @@ export default function ProjectSettingsNotifications() {
</FormItem>
)}
/>
<FormField
control={form.control}
name="fromName"
render={({ field }) => (
<FormItem>
<FormLabel>
Wil je een naam toevoegen aan het e-mailadres waarvandaan de notificaties worden verstuurd?
<InfoDialog content={'Let op: dit werkt alleen als de domeininstellingen voor dit e-mailadres correct geconfigureerd zijn. Tip: maak hiervoor gebruik van Flowmailer of Sendgrid.'} />
</FormLabel>
<FormDescription>Als je hier een naam invult komt dit voor het e-mailadres van de afzender te staan, bijvoorbeeld: OpenStad site &#60;[email protected]&#62;</FormDescription>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="projectmanagerAddress"
Expand Down
4 changes: 4 additions & 0 deletions apps/api-server/src/models/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ module.exports = ( db, sequelize, DataTypes ) => {
instance.from = project.emailConfig?.notifications?.fromAddress;
}

if ( project.emailConfig?.notifications?.fromName && !!project.emailConfig?.notifications?.fromName ) {
instance.from = `"${project.emailConfig.notifications.fromName}" <${instance.from}>`;
}

// to
let user;
if (!instance.to) {
Expand Down

0 comments on commit b37c4bd

Please sign in to comment.