Implement holding template

This commit is contained in:
Ondřej 2024-02-23 16:54:14 +01:00
parent 8ecccd39f0
commit e9638f3632
7 changed files with 89 additions and 67 deletions

View file

@ -1,23 +0,0 @@
import { Kysely } from "kysely";
export async function up(db: Kysely<any>) {
await db.schema.createTable("branches")
.addColumn("id", "integer", (c) => c.primaryKey())
.addColumn("country", "text", (c) => c.notNull())
.addColumn("language", "text", (c) => c.notNull())
.addColumn("name", "text", (c) => c.notNull())
.addColumn("ceo", "text")
.addColumn("ceoEmail", "text").execute();
db.insertInto("branches").values({
country: "at",
language: "de",
name: "VIG (Holding)",
ceo: "Hartwig Löger",
ceoEmail: "hartwig.loeger@vig.com",
}).execute();
}
export async function down(db: Kysely<any>) {
await db.schema.dropTable("branches").execute();
}

View file

@ -0,0 +1,4 @@
name: VIG (Holding english)
language: all
messageTemplate: vigHolding
ceo: Hartwig Löger

View file

@ -1,5 +1,16 @@
import { z, defineCollection } from "astro:content";
const branches = defineCollection({
type: "data",
schema: z.object({
name: z.string(),
language: z.string(),
messageTemplate: z.string(),
ceo: z.string(),
ceoEmail: z.string().optional(),
}),
});
const intro = defineCollection({
type: "content",
schema: z.object({
@ -22,6 +33,7 @@ const emailConfirmed = defineCollection({
});
export const collections = {
branches,
intro,
confirmEmail,
emailConfirmed,

View file

@ -7,21 +7,30 @@ import Label from "../ui/Label.astro";
import Select from "../ui/Select.astro";
import type { Lang } from "../lang";
import Checkbox from "../ui/Checkbox.astro";
import { getCollection } from "astro:content";
interface Props {
lang: Lang;
branches: Array<{ id: number; name: string }>;
}
const branches = [{ id: 1, name: "Branch 1" }];
const { lang } = Astro.props;
const branches = await getCollection(
"branches",
(branch) => branch.data.language === "all" || branch.data.language === lang,
);
const { t } = makeT(lang);
const genderOptions: Partial<Record<Lang, Array<"f" | "n" | "m">>> = {
const genderOptions: Record<Lang, Array<"f" | "n" | "m">> = {
en: [],
cs: ["f", "m", "m"],
cs: ["f", "m", "n"],
sk: ["m", "f"],
pl: ["m", "f"],
hu: ["m", "f", "n"],
ro: [], // TODO,
lt: ["m", "f"],
de: ["m", "f", "n"],
};
const genders = genderOptions[lang];
@ -61,7 +70,7 @@ const genders = genderOptions[lang];
{t("form.branch")}
</Label>
<Select name="branch" id="branch-input">
{branches.map((branch) => <option value={branch.id}>{branch.name}</option>)}
{branches.map((branch) => <option value={branch.id}>{branch.data.name}</option>)}
</Select>
</div>
<Checkbox name="isClient">

View file

@ -1,34 +0,0 @@
import type { TemplateFn } from "./types";
/**
* @status done
*/
export const en: TemplateFn = (c) => {
// prettier-ignore
return (
`${{
1: `"I recently learned that the Vienna Insurance Group does not have any policies against insuring oil and gas businesses.
I believe you are well aware that continuing with oil and gas accelerates climate change, and keeps our economy dependent on dirty fuels that wont be useful for long.
It is unclear to me why VIG still considers working with oil and gas companies, when this industry threatens our health, homes, businesses - everything you, as an insurer, try to keep safe."`,
2: `"I am contacting you to raise my concerns about the coal policy of the Vienna Insurance Group.
As of today, your policy (thresholds 30%/20Mt/10GWh in countries with a coal exit strategy, no threshold in the others) still allows you to give insurance to coal companies.
I am sure you perfectly know that burning coal emits greenhouse gases that contribute to the unprecedented current climate crisis, so I dont understand why you still support this industry that threatens our health, homes, businesses - everything you, as an insurer, try to keep safe."`,
3: `I am writing to you because I am deeply concerned about the Neptun Deep project, a gas extraction plan in the Romanian Black Sea scheduled to start drilling this year. This project would have devastating consequences for the climate, biodiversity, landscape, and local communities. Vienna Insurance Group has important power in helping to stop this project: by refusing to insure it and by publicly speaking out against it.`,
}[c.variant]}
According to the values you defend as a company, it seems that you should be taking environmental and social concerns seriously. As the top insurer in Central and Eastern Europe, your group has the responsibility to set a positive example and truly protect what matters as you promise to do.
${{
1: `Therefore, I ask you, VIG, and all of your branches, to publicly commit to stop insuring oil and gas projects or companies.`,
2: `I am consequently urging you, VIG and all of your branches, to improve your coal insurance policy (thresholds 20%/10Mt /5GWh for all countries).`,
3: `This is why I would like you, VIG, to make a public statement declaring that you do not insure the Neptun Deep project.`,
}[c.variant]}${c.isClient ? `
As a client of your company, Ill have to reconsider staying with you if you do not take on more responsibility. ` : ""}
I would appreciate it if you could respond as soon as possible.
Sincerely,
${c.name}
`);
};

View file

@ -6,8 +6,11 @@ import { en } from "./en";
import { cs } from "./cs";
import { sk } from "./sk";
import { lt } from "./lt";
import { getEntry } from "astro:content";
import { vigHolding } from "./vig-holding";
const templates: Partial<Record<Lang, TemplateFn>> = {
const templates: Record<string, TemplateFn> = {
vigHolding,
en,
cs,
sk,
@ -18,18 +21,30 @@ function getName({ firstName, lastName }: { firstName?: string; lastName?: strin
return [firstName, lastName].filter(Boolean).join(" ");
}
export function renderText(
export async function renderText(
lang: Lang,
{
firstName,
lastName,
variant = "1",
gender = "f",
branch = "",
branch: branchId = "vig-holding",
isClient = false,
}: Partial<LetterOptions>
) {
const branch = await getEntry("branches", branchId);
if (!branch) {
throw new Error(`Unknown branch of id ${branchId}`);
}
const name = getName({ firstName, lastName });
const template = templates[lang] ?? en;
return template({ name, variant, branch, gender, isClient });
const template = templates[branch.data.messageTemplate] ?? en;
return template({
name,
variant,
branch: branch.data.name,
gender,
isClient,
});
}

View file

@ -0,0 +1,39 @@
import type { TemplateFn } from "./types";
/**
* @status done
*/
export const vigHolding: TemplateFn = (c) => {
// prettier-ignore
return (
`${{
1: `I recently learned that the Vienna Insurance Group does not have any policies against insuring oil and gas businesses.
I believe you are well aware that continuing with oil and gas accelerates climate change, and keeps our economy dependent on dirty fuels that wont be useful for long.
It is unclear to me why VIG still considers working with oil and gas companies, when this industry threatens our health, homes, businesses - everything you, as an insurer, try to keep safe.`,
2: `I am contacting you to raise my concerns about the coal policy of the Vienna Insurance Group.
As of today, your policy (thresholds 30%/20Mt/10GWh in countries with a coal exit strategy, no threshold in the others) still allows you to give insurance to coal companies.
I am sure you perfectly know that burning coal emits greenhouse gases that contribute to the unprecedented current climate crisis, so I dont understand why you still support this industry that threatens our health, homes, businesses - everything you, as an insurer, try to keep safe.`,
3: `I am writing to you because I am deeply concerned about the Neptun Deep project, a gas extraction plan in the Romanian Black Sea scheduled to start drilling this year. This project would have devastating consequences for the climate, biodiversity, landscape, and local communities. Vienna Insurance Group has important power in helping to stop this project: by refusing to insure it and by publicly speaking out against it.`,
}[c.variant]}
According to the values you defend as a company, it seems that you should be taking environmental and social concerns seriously. As the top insurer in Central and Eastern Europe, your group has the responsibility to set a positive example and truly protect what matters as you promise to do.
${{
1: `Therefore, I ask you, VIG, and all of your branches, to publicly commit to stop insuring oil and gas projects or companies.`,
2: `I am consequently urging you, VIG and all of your branches, to improve your coal insurance policy (thresholds 20%/10Mt /5GWh for all countries).`,
3: `This is why I would like you, VIG, to make a public statement declaring that you do not insure the Neptun Deep project.`,
}[c.variant]}${c.isClient ? `
As a client of your company, Ill have to reconsider staying with you if you do not take on more responsibility. ` : ``}
I would appreciate it if you could respond as soon as possible.
Sincerely,
${c.name}
`);
};