Skip to content

Commit

Permalink
Merge branch 'main' into larger-invoice-success-text
Browse files Browse the repository at this point in the history
  • Loading branch information
JaaskelainenL committed Oct 24, 2024
2 parents a552112 + b404712 commit 6137770
Show file tree
Hide file tree
Showing 54 changed files with 6,937 additions and 5,140 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
- uses: pnpm/action-setup@v4
with:
version: 9.9.0
version: 9.12.1

- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22.6.0
node-version: 22.8.0
cache: "pnpm"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.6.0
22.8.0
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Base image with Node.js
ARG NODE_VERSION=22.6.0
ARG NODE_VERSION=22.8.0
# Use a specific version of the Node.js Alpine image as the base. Alpine images are minimal and lightweight.
FROM node:${NODE_VERSION}-alpine AS base
# Update the package list and install libc6-compat. This package is often required for binary Node.js modules.
Expand Down
11 changes: 0 additions & 11 deletions apps/cms/.eslintrc.js

This file was deleted.

8 changes: 8 additions & 0 deletions apps/cms/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ts from "typescript-eslint";
import server from "@tietokilta/eslint-config/server";

export default ts.config(...server, {
rules: {
"unicorn/prefer-node-protocol": "off",
},
});
23 changes: 12 additions & 11 deletions apps/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
"email": "email dev --dir src/emails",
"generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema",
"generate:types": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
"lint": "eslint \"./src/**/*.{js,ts}\"",
"lint": "eslint \"./src/**/*.{js,ts,jsx,tsx}\"",
"start": "NODE_ENV=production PAYLOAD_CONFIG_PATH=dist/payload.config.js node dist/server.js",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@azure/storage-blob": "^12.24.0",
"@azure/storage-blob": "^12.25.0",
"@payloadcms/bundler-webpack": "^1.0.7",
"@payloadcms/db-mongodb": "^1.7.2",
"@payloadcms/plugin-cloud-storage": "^1.1.3",
"@payloadcms/db-mongodb": "^1.7.3",
"@payloadcms/plugin-cloud-storage": "^1.2.0",
"@payloadcms/richtext-lexical": "^0.11.3",
"@react-email/components": "0.0.23",
"@react-email/components": "0.0.25",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"form-data": "^4.0.0",
"express": "^4.21.1",
"form-data": "^4.0.1",
"lodash": "^4.17.21",
"mailgun.js": "^10.2.3",
"nanoid": "^3.3.7",
"papaparse": "^5.4.1",
"payload": "^2.28.0",
"payload": "^2.30.1",
"payload-plugin-oauth": "^2.2.0"
},
"devDependencies": {
Expand All @@ -43,14 +43,15 @@
"@tietokilta/ui": "workspace:*",
"@types/express": "^4.17.21",
"@types/express-fileupload": "^1.5.1",
"@types/lodash": "^4.17.7",
"@types/lodash": "^4.17.10",
"@types/papaparse": "^5.3.14",
"@types/react": "catalog:",
"copyfiles": "^2.4.1",
"eslint": "catalog:",
"react": "catalog:",
"react-email": "3.0.1",
"tsx": "^4.19.0",
"typescript": "catalog:"
"tsx": "^4.19.1",
"typescript": "catalog:",
"typescript-eslint": "catalog:"
}
}
60 changes: 60 additions & 0 deletions apps/cms/src/collections/honors/awarded-honors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { CollectionConfig, FieldHook } from "payload/types";
import type { AwardedHonor } from "@tietokilta/cms-types/payload";
import { signedIn } from "../../access/signed-in";
import { guildYearField } from "../../fields/guild-year";

const formatDisplayTitle: FieldHook<AwardedHonor> = ({
data: awardedHonor,
}) => {
if (!awardedHonor?.name) {
return "Untitled member";
}

if (!awardedHonor.guildYear) {
return awardedHonor.name;
}

return `${awardedHonor.name}, ${awardedHonor.guildYear}`;
};

export const AwardedHonors = {
slug: "awarded-honors",
defaultSort: "-guildYear",
admin: {
useAsTitle: "displayTitle",
defaultColumns: ["description", "guildYear"],
},
access: {
read: () => true,
create: signedIn,
update: signedIn,
delete: signedIn,
},
fields: [
{
name: "displayTitle",
type: "text",
admin: {
hidden: true,
},
hooks: {
beforeChange: [formatDisplayTitle],
},
},
guildYearField({
name: "guildYear",
required: true,
}),
{
name: "name",
type: "text",
required: true,
},
{
name: "description",
type: "textarea",
required: false,
localized: true,
},
],
} as const satisfies CollectionConfig;
38 changes: 38 additions & 0 deletions apps/cms/src/collections/honors/honors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { CollectionConfig } from "payload/types";
import { signedIn } from "../../access/signed-in";

export const Honors = {
slug: "honors",
defaultSort: "-name",
admin: {
useAsTitle: "name",
defaultColumns: ["name", "awardedHonors"],
},
access: {
read: () => true,
create: signedIn,
update: signedIn,
delete: signedIn,
},
fields: [
{
name: "name",
type: "text",
required: true,
localized: true,
},
{
name: "awardedHonors",
type: "array",
required: true,
minRows: 1,
fields: [
{
name: "awardedHonor",
type: "relationship",
relationTo: "awarded-honors",
},
],
},
],
} as const satisfies CollectionConfig;
22 changes: 22 additions & 0 deletions apps/cms/src/collections/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export const News: CollectionConfig = {
label: "PageLink",
value: "page",
},
{
label: "ExternalLink",
value: "external",
},
],
},
{
Expand All @@ -65,6 +69,24 @@ export const News: CollectionConfig = {
relationTo: "pages",
required: true,
},
{
name: "externalLink",
type: "text",
admin: {
condition: (_, siblingData) => siblingData.ctaType === "external",
},
validate: (value: unknown) => {
try {
// eslint-disable-next-line no-new -- we want to throw an error if the URL is invalid
new URL(value as string);
} catch {
return "Invalid URL";
}

return true;
},
required: true,
},
{
name: "type",
type: "select",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ const getIdFromUrl = (): string => {
const id = pathArray[pathArray.length - 1];
return id;
};
const getEmail = async (): Promise<{
html: string;
subject: string;
}> => {
const newsletterId = getIdFromUrl();
const response = await fetch(`/api/weekly-newsletters/mail/${newsletterId}`);
return (await response.json()) as { html: string; subject: string };
};

const getTelegramMessage = async (
locale: string,
Expand All @@ -39,13 +31,11 @@ const NewsletterButton = (): React.ReactElement => {
`Are you sure you want to send email? Remember to publish changes before.`,
);
if (!confirmed) return;
const email = await getEmail();
await fetch("/api/weekly-newsletters/mail", {
await fetch(`/api/weekly-newsletters/mail/${newsletterId}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(email),
});
};
const buttonStyle = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const WeeklyNewsletters: CollectionConfig = {
},
endpoints: [
{
path: "/mail",
path: "/mail/:newsletterId",
method: "post",
handler: newsletterSenderController as PayloadHandler,
},
Expand Down
46 changes: 34 additions & 12 deletions apps/cms/src/controllers/newsletter-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,43 @@ export const newsletterSenderController = async (
return;
}
try {
const { subject, html } = req.body as {
subject: string | undefined;
html: string | undefined;
};

if (!subject || !html) {
return res
.status(400)
.json({ error: "Missing required fields: subject, html" });
}
const { newsletterId } = req.params;

// Fetch the English version of the newsletter
const englishNewsletter = (await req.payload.findByID({
collection: "weekly-newsletters",
id: newsletterId,
depth: 2,
locale: "en",
})) as unknown as WeeklyNewsletter;

// Fetch the Finnish version of the newsletter
const finnishNewsletter = (await req.payload.findByID({
collection: "weekly-newsletters",
id: newsletterId,
depth: 2,
locale: "fi",
})) as unknown as WeeklyNewsletter;

const { PUBLIC_LEGACY_URL, PUBLIC_FRONTEND_URL } = process.env;

// Render the HTML content
const html = await render(
NewsletterEmail({
finnishNewsletter,
englishNewsletter,
PUBLIC_LEGACY_URL: PUBLIC_LEGACY_URL ?? "",
PUBLIC_FRONTEND_URL: PUBLIC_FRONTEND_URL ?? "",
}),
);

await sendEmail({ subject, html });
await sendEmail({
subject: `${finnishNewsletter.title}/${englishNewsletter.title}`,
html,
});

return res.status(200).json({ message: "Email sent successfully" });
} catch (error) {
} catch (_) {
return res.status(500).json({ error: "Internal Server Error" });
}
};
Expand Down
Loading

0 comments on commit 6137770

Please sign in to comment.