feat(MED-48): improvements

This commit is contained in:
2025-07-24 08:52:59 +03:00
parent d7499fbc13
commit 3341dbd306
6 changed files with 1671 additions and 113 deletions

View File

@@ -1,8 +1,9 @@
import { MontonioOrderToken } from "@/app/home/(user)/_components/cart/types";
import { loadCurrentUserAccount } from "@/app/home/(user)/_lib/server/load-user-account";
import { placeOrder } from "@lib/data/cart";
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import { z } from "zod"; import { z } from "zod";
import { MontonioOrderToken } from "@/app/home/(user)/_components/cart/types";
import { loadCurrentUserAccount } from "@/app/home/(user)/_lib/server/load-user-account";
import { listProductTypes } from "@lib/data/products";
import { placeOrder } from "@lib/data/cart";
import { createI18nServerInstance } from "~/lib/i18n/i18n.server"; import { createI18nServerInstance } from "~/lib/i18n/i18n.server";
const emailSender = process.env.EMAIL_SENDER; const emailSender = process.env.EMAIL_SENDER;
@@ -70,11 +71,13 @@ const handleOrderToken = async (orderToken: string) => {
if (!cartId) { if (!cartId) {
throw new Error("Cart ID not found"); throw new Error("Cart ID not found");
} }
const { productTypes } = await listProductTypes();
const analysisPackagesType = productTypes.find(({ metadata }) => metadata?.handle === 'analysis-packages');
const { order } = await placeOrder(cartId, { revalidateCacheTags: true }); const { order } = await placeOrder(cartId, { revalidateCacheTags: true });
return { return {
email: order.email, email: order.email,
partnerLocationName: order.metadata?.partner_location_name as string ?? '', partnerLocationName: order.metadata?.partner_location_name as string ?? '',
analysisPackageName: order.items?.[0]?.title ?? '', analysisPackageName: order.items?.find(item => item.product_type_id === analysisPackagesType?.id)?.title ?? '',
}; };
} catch (error) { } catch (error) {
throw new Error(`Failed to place order, message=${error}`); throw new Error(`Failed to place order, message=${error}`);
@@ -102,7 +105,7 @@ export async function GET(request: Request) {
const { email, partnerLocationName, analysisPackageName } = orderResult; const { email, partnerLocationName, analysisPackageName } = orderResult;
const personName = account.name; const personName = account.name;
if (email) { if (email && analysisPackageName && partnerLocationName) {
await sendEmail({ email, analysisPackageName, personName, partnerLocationName, language }); await sendEmail({ email, analysisPackageName, personName, partnerLocationName, language });
} }
return Response.redirect(new URL('/home/order', baseUrl)) return Response.redirect(new URL('/home/order', baseUrl))

View File

@@ -68,6 +68,7 @@
"clsx": "^2.1.1", "clsx": "^2.1.1",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"fast-xml-parser": "^5.2.5", "fast-xml-parser": "^5.2.5",
"isikukood": "3.1.7",
"jsonwebtoken": "9.0.2", "jsonwebtoken": "9.0.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"lucide-react": "^0.510.0", "lucide-react": "^0.510.0",

View File

@@ -32,7 +32,9 @@ export async function renderSynlabAnalysisPackageEmail(props: Props) {
}); });
const previewText = t(`${namespace}:previewText`); const previewText = t(`${namespace}:previewText`);
const subject = t(`${namespace}:subject`); const subject = t(`${namespace}:subject`, {
analysisPackageName: props.analysisPackageName,
});
const heading = t(`${namespace}:heading`, { const heading = t(`${namespace}:heading`, {
analysisPackageName: props.analysisPackageName, analysisPackageName: props.analysisPackageName,

View File

@@ -1,7 +1,7 @@
{ {
"subject": "Your Synlab order has been placed", "subject": "Your Synlab order has been placed - {{analysisPackageName}}",
"previewText": "Your Synlab order has been placed", "previewText": "Your Synlab order has been placed - {{analysisPackageName}}",
"heading": "Your Synlab order has been placed", "heading": "Your Synlab order has been placed - {{analysisPackageName}}",
"hello": "Hello {{personName}},", "hello": "Hello {{personName}},",
"lines1": "The order for {{analysisPackageName}} analysis package has been sent to the lab. Please go to the lab to collect the sample: SYNLAB - {{partnerLocationName}}", "lines1": "The order for {{analysisPackageName}} analysis package has been sent to the lab. Please go to the lab to collect the sample: SYNLAB - {{partnerLocationName}}",
"lines2": "<i>If you are unable to go to the lab to collect the sample, you can go to any other suitable collection point - <a href=\"https://medreport.ee/et/verevotupunktid\">view locations and opening hours</a>.</i>", "lines2": "<i>If you are unable to go to the lab to collect the sample, you can go to any other suitable collection point - <a href=\"https://medreport.ee/et/verevotupunktid\">view locations and opening hours</a>.</i>",

View File

@@ -1,5 +1,5 @@
{ {
"subject": "Teie SYNLAB tellimus on kinnitatud", "subject": "Teie SYNLAB tellimus on kinnitatud - {{analysisPackageName}}",
"previewText": "Teie SYNLAB tellimus on kinnitatud - {{analysisPackageName}}", "previewText": "Teie SYNLAB tellimus on kinnitatud - {{analysisPackageName}}",
"heading": "Teie SYNLAB tellimus on kinnitatud - {{analysisPackageName}}", "heading": "Teie SYNLAB tellimus on kinnitatud - {{analysisPackageName}}",
"hello": "Tere {{personName}},", "hello": "Tere {{personName}},",

1758
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff