Skip to content

Commit 24483e4

Browse files
authored
Merge pull request #1 from codee-sh/feat/add-multi-blocks
Feat: Add multi blocks
2 parents 7c9afa0 + bb1fe18 commit 24483e4

58 files changed

Lines changed: 1819 additions & 1430 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.changeset/sunny-houses-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@codee-sh/medusa-plugin-notification-emails": minor
3+
---
4+
5+
Add multi blocks feature

emails-previews/contact-form.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import { renderHTMLReact } from "../src/templates/emails/contact-form/template";
2-
import { ContactFormTemplateDataType } from "../src/templates/emails/contact-form/types";
3-
import { defaultTheme } from "../src/templates/shared/theme"
4-
import { getTranslations } from "../src/templates/shared/i18n";
5-
import { translations as contactFormTranslations } from "../src/templates/emails/contact-form/translations";
1+
import { defaultTheme } from "../src/templates/shared/theme";
2+
import { renderTemplateSync } from "../src/templates/emails";
63

7-
export const contactFormMockData: ContactFormTemplateDataType = {
4+
export const contactFormMockData: any = {
85
name: "Test Name",
96
email: "test@test.com",
107
phone: "1234567890",
118
message: "Test messages",
129
};
1310

1411
export default function ContactForm() {
15-
return renderHTMLReact(contactFormMockData, {
16-
locale: "pl",
17-
theme: defaultTheme,
18-
i18n: getTranslations("pl", contactFormTranslations)
19-
});
20-
}
12+
const renderTemplate = renderTemplateSync(
13+
"contact-form",
14+
contactFormMockData,
15+
{
16+
locale: "pl",
17+
theme: defaultTheme
18+
}
19+
);
20+
21+
return renderTemplate.reactNode;
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defaultTheme } from "../src/templates/shared/theme";
2+
import { renderTemplateSync } from "../src/templates/emails";
3+
4+
export const inventoryLevelMockData: any = {
5+
inventory_level: {
6+
id: "inventory_123",
7+
location_id: "loc_456",
8+
stocked_quantity: "100",
9+
reserved_quantity: "20",
10+
available_quantity: "80",
11+
},
12+
};
13+
14+
export default function InventoryLevel() {
15+
const renderTemplate = renderTemplateSync(
16+
"inventory-level",
17+
inventoryLevelMockData,
18+
{
19+
locale: "pl",
20+
theme: defaultTheme,
21+
}
22+
);
23+
24+
return renderTemplate.reactNode;
25+
}
26+
Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { renderHTMLReact } from "../src/templates/emails/order-completed/template";
2-
import { OrderCompletedTemplateDataType } from "../src/templates/emails/order-completed/types";
3-
import { defaultTheme } from "../src/templates/shared/theme"
4-
import { getTranslations } from "../src/templates/shared/i18n";
5-
import { translations as orderCompletedTranslations } from "../src/templates/emails/order-completed/translations";
1+
import { defaultTheme } from "../src/templates/shared/theme";
2+
import { renderTemplateSync } from "../src/templates/emails";
63

7-
export const orderCompletedMockData: OrderCompletedTemplateDataType = {
4+
export const orderCompletedMockData: any = {
85
sales_channel: {
96
name: "Test Sales Channel",
107
description: "Test Sales Channel Description"
@@ -15,29 +12,42 @@ export const orderCompletedMockData: OrderCompletedTemplateDataType = {
1512
orderDate: "2021-01-01",
1613
completedDate: "2021-01-05",
1714
totalAmount: "100.00",
18-
currency: "PLN",
19-
items: [{
20-
title: "Test Product",
21-
quantity: 1,
22-
price: "100.00"
23-
}],
24-
shippingAddress: "Test Shipping Address",
25-
billingAddress: "Test Billing Address",
15+
currency_code: "pln",
16+
items: [
17+
{
18+
thumbnail: "",
19+
title: "Test Product 1",
20+
quantity: 10,
21+
price: "50.00"
22+
},
23+
{
24+
thumbnail: "https://placehold.co/150",
25+
title: "Test Product 2",
26+
quantity: 1,
27+
price: "100.00"
28+
}
29+
],
30+
shippingAddress: "Test Shipping Address <br />Test Shipping Address 2",
31+
billingAddress: "Test Billing Address<br />Test Billing Address 2",
2632
orderUrl: "https://example.com/order/1234567890",
2733
summary: {
2834
total: "100.00",
2935
paid_total: "100.00",
3036
tax_total: "10.00",
31-
discount_total: "0.00",
32-
currency_code: "PLN"
37+
discount_total: "0.00"
3338
}
3439
};
3540

3641
export default function OrderCompleted() {
37-
return renderHTMLReact(orderCompletedMockData, {
38-
locale: "pl",
39-
theme: defaultTheme,
40-
i18n: getTranslations("pl", orderCompletedTranslations)
41-
});
42+
const renderTemplate = renderTemplateSync(
43+
"order-completed",
44+
orderCompletedMockData,
45+
{
46+
locale: "pl",
47+
theme: defaultTheme,
48+
}
49+
);
50+
51+
return renderTemplate.reactNode;
4252
}
4353

emails-previews/order-placed.tsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { renderHTMLReact } from "../src/templates/emails/order-placed/template";
2-
import { OrderCreatedTemplateDataType } from "../src/templates/emails/order-placed/types";
3-
import { defaultTheme } from "../src/templates/shared/theme"
4-
import { getTranslations } from "../src/templates/shared/i18n";
5-
import { translations as orderPlacedTranslations } from "../src/templates/emails/order-placed/translations";
1+
import { defaultTheme } from "../src/templates/shared/theme";
2+
import { renderTemplateSync } from "../src/templates/emails";
63

7-
export const orderPlacedMockData: OrderCreatedTemplateDataType = {
4+
export const orderPlacedMockData: any = {
85
sales_channel: {
96
name: "Test Sales Channel",
107
description: "Test Sales Channel Description"
@@ -14,28 +11,41 @@ export const orderPlacedMockData: OrderCreatedTemplateDataType = {
1411
customerEmail: "jan@example.com",
1512
orderDate: "2021-01-01",
1613
totalAmount: "100.00",
17-
currency: "PLN",
18-
items: [{
19-
title: "Test Product",
20-
quantity: 1,
21-
price: "100.00"
22-
}],
14+
currency_code: "pln",
15+
items: [
16+
{
17+
thumbnail: "https://placehold.co/150",
18+
title: "Test Product 1",
19+
quantity: 10,
20+
price: "50.00"
21+
},
22+
{
23+
thumbnail: "https://placehold.co/150",
24+
title: "Test Product 2",
25+
quantity: 11,
26+
price: "100.00"
27+
}
28+
],
2329
shippingAddress: "Test Shipping Address",
2430
billingAddress: "Test Billing Address",
2531
orderUrl: "https://example.com/order/1234567890",
2632
summary: {
2733
total: "100.00",
2834
paid_total: "100.00",
2935
tax_total: "10.00",
30-
discount_total: "0.00",
31-
currency_code: "PLN"
36+
discount_total: "0.00"
3237
}
3338
};
3439

3540
export default function OrderPlaced() {
36-
return renderHTMLReact(orderPlacedMockData, {
37-
locale: "pl",
38-
theme: defaultTheme,
39-
i18n: getTranslations("pl", orderPlacedTranslations)
40-
});
41+
const renderTemplate = renderTemplateSync(
42+
"order-placed",
43+
orderPlacedMockData,
44+
{
45+
locale: "pl",
46+
theme: defaultTheme,
47+
}
48+
);
49+
50+
return renderTemplate.reactNode;
4151
}

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@
4949
"release:manual": "npm run build && npm publish --access public"
5050
},
5151
"dependencies": {
52-
"@react-email/components": "^0.3.3",
53-
"@react-email/preview-server": "^4.2.5",
54-
"@react-email/render": "^1.1.4",
55-
"react-email": "^4.2.5"
52+
"@react-email/components": "^0.5.7",
53+
"@react-email/preview-server": "^4.3.1",
54+
"@react-email/render": "^1.4.0",
55+
"react-email": "^4.3.1"
5656
},
5757
"devDependencies": {
58+
"@changesets/cli": "^2.29.8",
5859
"@medusajs/admin-sdk": "2.8.8",
5960
"@medusajs/cli": "2.8.8",
6061
"@medusajs/framework": "2.8.8",
@@ -66,20 +67,20 @@
6667
"@mikro-orm/knex": "6.4.3",
6768
"@mikro-orm/migrations": "6.4.3",
6869
"@mikro-orm/postgresql": "6.4.3",
69-
"@react-email/components": "^0.3.3",
70-
"@react-email/preview-server": "^4.2.5",
71-
"@react-email/render": "^1.1.4",
70+
"@react-email/components": "^0.5.7",
71+
"@react-email/preview-server": "^4.3.1",
72+
"@react-email/render": "^1.4.0",
7273
"@swc/core": "1.5.7",
7374
"@types/node": "^20.0.0",
7475
"@types/react": "^18.3.2",
7576
"@types/react-dom": "^18.2.25",
76-
"react-i18next": "^15.0.0",
7777
"awilix": "^8.0.1",
7878
"dotenv": "^17.2.3",
7979
"prop-types": "^15.8.1",
8080
"react": "^18.2.0",
8181
"react-dom": "^18.2.0",
82-
"react-email": "^4.2.5",
82+
"react-email": "^4.3.1",
83+
"react-i18next": "^15.0.0",
8384
"ts-node": "^10.9.2",
8485
"typescript": "^5.6.2",
8586
"vite": "^5.2.11",

src/admin/notifications-templates/groups/order/order-placed.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ export const OrderPlacedTemplate = ({ orderId }: { orderId: string }) => {
1818
if (order?.display_id) {
1919
const shippingAddressText = getFormattedAddress({ address: order.shipping_address }).join("<br/>");
2020
const billingAddressText = getFormattedAddress({ address: order.billing_address }).join("<br/>");
21-
const templateData = {
22-
// subject: `#${order.display_id} - Zamówienie zostało złożone`,
21+
const templateData: any = {
2322
orderNumber: `#${order.display_id}`,
2423
customerName: order.email,
2524
customerEmail: order.email,
2625
orderDate: formatDate({ date: order.created_at, includeTime: true, localeCode: "pl" }),
2726
totalAmount: order.items.reduce((acc, item) => acc + (item.variant?.prices?.[0]?.amount || 0) * item.quantity, 0),
28-
currency: order.currency_code,
27+
currency_code: order.currency_code,
2928
items: order.items.map((item) => ({
30-
thumbnail: item.thumbnail,
29+
thumbnail: item.thumbnail == null ? "" : item.thumbnail,
3130
title: item.title,
3231
quantity: item.quantity,
3332
price: getLocaleAmount(item.unit_price, order.currency_code),
@@ -38,8 +37,7 @@ export const OrderPlacedTemplate = ({ orderId }: { orderId: string }) => {
3837
total: getLocaleAmount(order.summary.original_order_total, order.currency_code),
3938
paid_total: getLocaleAmount(getTotalCaptured(order.payment_collections || []), order.currency_code),
4039
tax_total: getLocaleAmount(order.tax_total, order.currency_code),
41-
discount_total: getLocaleAmount(order.discount_total, order.currency_code),
42-
currency: order.currency_code,
40+
discount_total: getLocaleAmount(order.discount_total, order.currency_code)
4341
},
4442
sales_channel: {
4543
name: order?.sales_channel?.name,

src/api/admin/notification-plugin/render-template/route.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
22
import { MedusaError } from "@medusajs/framework/utils"
3-
import { renderTemplate } from "../../../../templates/emails"
43
import { getPluginOptions } from "../../../../utils/plugins"
54
import { defaultTheme } from "../../../../templates/shared/theme"
6-
import { TemplateName } from "../../../../templates/emails"
5+
import { renderTemplate, TemplateName, TemplateData } from "../../../../templates/emails"
76

87
export async function POST(
98
req: MedusaRequest<{ templateName: string, templateData: any, locale: string }>,
@@ -12,7 +11,7 @@ export async function POST(
1211
const pluginOptions = getPluginOptions(req.scope, "@codee-sh/medusa-plugin-notification")
1312

1413
const templateName = req.body?.templateName as TemplateName
15-
const templateData = req.body?.templateData as any
14+
const templateData = req.body?.templateData as TemplateData
1615
const locale = req.body?.locale || "pl"
1716

1817
if (!templateName || !templateData || !locale) {
@@ -22,7 +21,7 @@ export async function POST(
2221
const { html, text } = await renderTemplate(
2322
templateName,
2423
templateData,
25-
{
24+
{
2625
locale: locale,
2726
theme: pluginOptions?.theme || defaultTheme,
2827
customTranslations: pluginOptions?.customTranslations?.[templateName]

0 commit comments

Comments
 (0)