* MED-145: send notification to patient when summary completed * MED-145: send notification to patient when summary completed * use aliased imports where possible, revert cart service urls * save language preference to local db * remove unnecessary optional chaning
65 lines
1.3 KiB
TypeScript
65 lines
1.3 KiB
TypeScript
'use server';
|
|
|
|
import { CompanySubmitData } from '@/lib/types/company';
|
|
import { emailSchema } from '@/lib/validations/email.schema';
|
|
|
|
import { renderDoctorSummaryReceivedEmail } from '@kit/email-templates';
|
|
import { getMailer } from '@kit/mailers';
|
|
import { enhanceAction } from '@kit/next/actions';
|
|
|
|
export const sendDoctorSummaryCompletedEmail = async (
|
|
language: string,
|
|
recipientName: string,
|
|
recipientEmail: string,
|
|
orderNr: string,
|
|
orderId: number,
|
|
) => {
|
|
const { html, subject } = await renderDoctorSummaryReceivedEmail({
|
|
language,
|
|
recipientName,
|
|
recipientEmail,
|
|
orderNr,
|
|
orderId,
|
|
});
|
|
|
|
await sendEmail({
|
|
subject,
|
|
html,
|
|
to: recipientEmail,
|
|
});
|
|
};
|
|
|
|
export const sendCompanyOfferEmail = async (
|
|
data: CompanySubmitData,
|
|
language: string,
|
|
) => {
|
|
const { renderCompanyOfferEmail } = await import('@kit/email-templates');
|
|
const { html, subject } = await renderCompanyOfferEmail({
|
|
language,
|
|
companyData: data,
|
|
});
|
|
|
|
await sendEmail({
|
|
subject,
|
|
html,
|
|
to: process.env.CONTACT_EMAIL || '',
|
|
});
|
|
};
|
|
|
|
export const sendEmail = enhanceAction(
|
|
async ({ subject, html, to }) => {
|
|
const mailer = await getMailer();
|
|
await mailer.sendEmail({
|
|
to,
|
|
subject,
|
|
html,
|
|
});
|
|
|
|
return {};
|
|
},
|
|
{
|
|
schema: emailSchema,
|
|
auth: false,
|
|
},
|
|
);
|