refactor: replace baseUrl prop with env.BASE_URL in email components

This commit is contained in:
Marco Pedone 2025-10-20 17:27:32 +02:00
parent f2ee374e32
commit b84c98c334
10 changed files with 22 additions and 52 deletions

View file

@ -1,4 +1,5 @@
import { Button, Heading, Row, Section, Text } from "@react-email/components"; import { Button, Heading, Row, Section, Text } from "@react-email/components";
import { env } from "~/env";
import Base from "./base"; import Base from "./base";
export type VerificaEmail_NewMail = { export type VerificaEmail_NewMail = {
mailType: "verificaEmail"; mailType: "verificaEmail";
@ -6,18 +7,12 @@ export type VerificaEmail_NewMail = {
}; };
type VerificaEmailProps = { type VerificaEmailProps = {
baseUrl: string;
token: string; token: string;
userId: string; userId: string;
redirect?: string; redirect?: string;
}; };
const VerificaEmail = ({ const VerificaEmail = ({ token, userId, redirect }: VerificaEmailProps) => {
baseUrl,
token,
userId,
redirect,
}: VerificaEmailProps) => {
return ( return (
<Base noreply preview="Verifica la tua email"> <Base noreply preview="Verifica la tua email">
<> <>
@ -33,7 +28,7 @@ const VerificaEmail = ({
<Button <Button
className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900" className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900"
href={`${baseUrl}/auth/verifica-email-action?t=${token}&u=${userId}${redirect ? `&r=${redirect}` : ""}`} href={`${env.BASE_URL}/auth/verifica-email-action?t=${token}&u=${userId}${redirect ? `&r=${redirect}` : ""}`}
> >
Clicca qui per verificare Clicca qui per verificare
</Button> </Button>

View file

@ -22,11 +22,6 @@ const Base = ({
preview: string; preview: string;
noreply?: boolean; noreply?: boolean;
}) => { }) => {
console.log("BASE_URL:", env.BASE_URL);
console.log("INTERNAL_BASE_URL:", env.INTERNAL_BASE_URL);
console.log("NEXT_PUBLIC_BASE_URL:", env.NEXT_PUBLIC_BASE_URL);
console.log("process.env.BASE_URL:", process.env.BASE_URL);
const baseUrl = process.env.BASE_URL;
return ( return (
<Tailwind <Tailwind
config={{ config={{
@ -52,7 +47,7 @@ const Base = ({
className="mx-auto my-2 scale-80" className="mx-auto my-2 scale-80"
height={44.25} height={44.25}
referrerPolicy="no-referrer" referrerPolicy="no-referrer"
src={`${baseUrl}/Infoalloggi.png`} src={`${env.BASE_URL}/Infoalloggi.png`}
width={230.5} width={230.5}
/> />

View file

@ -1,4 +1,5 @@
import { Button, Heading, Row, Section, Text } from "@react-email/components"; import { Button, Heading, Row, Section, Text } from "@react-email/components";
import { env } from "~/env";
import Base from "./base"; import Base from "./base";
export type ContattoAnnuncio_NewMail = { export type ContattoAnnuncio_NewMail = {
@ -12,7 +13,6 @@ type ContattoAnnuncioEmailProps = {
email: string; email: string;
telefono: string; telefono: string;
messaggio: string; messaggio: string;
baseUrl: string;
}; };
const ContattoAnnuncioEmail = ({ const ContattoAnnuncioEmail = ({
nome, nome,
@ -20,7 +20,6 @@ const ContattoAnnuncioEmail = ({
email, email,
telefono, telefono,
messaggio, messaggio,
baseUrl,
}: ContattoAnnuncioEmailProps) => { }: ContattoAnnuncioEmailProps) => {
return ( return (
<Base preview="Contatto Email"> <Base preview="Contatto Email">
@ -42,7 +41,7 @@ const ContattoAnnuncioEmail = ({
<Section className="mb-5"> <Section className="mb-5">
<Button <Button
className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900" className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900"
href={`${baseUrl}/annuncio/${codice}`} href={`${env.BASE_URL}/annuncio/${codice}`}
> >
Vai all&apos;annuncio Vai all&apos;annuncio
</Button> </Button>

View file

@ -7,6 +7,7 @@ import {
Section, Section,
Text, Text,
} from "@react-email/components"; } from "@react-email/components";
import { env } from "~/env";
import Base from "./base"; import Base from "./base";
export type OnboardingServizio_NewMail = { export type OnboardingServizio_NewMail = {
mailType: "onboardingServizio"; mailType: "onboardingServizio";
@ -22,14 +23,12 @@ type OnboardingServizioProps = {
codice: string; codice: string;
prezzo: number; prezzo: number;
}[]; }[];
baseUrl: string;
}; };
const OnboardingServizio = ({ const OnboardingServizio = ({
token, token,
nome, nome,
annunci, annunci,
baseUrl,
}: OnboardingServizioProps) => { }: OnboardingServizioProps) => {
return ( return (
<Base preview="Procedi ora su Infoalloggi.it"> <Base preview="Procedi ora su Infoalloggi.it">
@ -49,7 +48,7 @@ const OnboardingServizio = ({
<Section className="mb-5"> <Section className="mb-5">
<Button <Button
className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900" className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900"
href={`${baseUrl}/servizio/pre-onboard/${token}`} href={`${env.BASE_URL}/servizio/pre-onboard/${token}`}
> >
Vai al servizio Vai al servizio
</Button> </Button>
@ -66,7 +65,7 @@ const OnboardingServizio = ({
alt={`Annuncio image - ${annuncio.codice}`} alt={`Annuncio image - ${annuncio.codice}`}
className="block w-[240px] rounded-[4px] object-cover object-center" className="block w-[240px] rounded-[4px] object-cover object-center"
height="140px" height="140px"
src={`${baseUrl}/go-api/images/get/${annuncio.immagine}`} src={`${env.BASE_URL}/go-api/images/get/${annuncio.immagine}`}
width="100%" width="100%"
/> />
</Row> </Row>
@ -86,7 +85,7 @@ const OnboardingServizio = ({
</Text> </Text>
<Link <Link
className="block font-semibold text-[14px] text-indigo-600 no-underline" className="block font-semibold text-[14px] text-indigo-600 no-underline"
href={`${baseUrl}/annuncio/${annuncio.codice}`} href={`${env.BASE_URL}/annuncio/${annuncio.codice}`}
> >
Scheda dell&apos;annuncio Scheda dell&apos;annuncio
</Link> </Link>

View file

@ -1,14 +1,11 @@
import { Button, Heading, Row, Section, Text } from "@react-email/components"; import { Button, Heading, Row, Section, Text } from "@react-email/components";
import { env } from "~/env";
import Base from "./base"; import Base from "./base";
export type PagamentoErrore_NewMail = { export type PagamentoErrore_NewMail = {
mailType: "pagamentoErrore"; mailType: "pagamentoErrore";
props: PagamentoErroreProps;
}; };
type PagamentoErroreProps = { const PagamentoErrore = () => {
baseUrl: string;
};
const PagamentoErrore = ({ baseUrl }: PagamentoErroreProps) => {
return ( return (
<Base preview="Errore Pagamento"> <Base preview="Errore Pagamento">
<> <>
@ -26,7 +23,7 @@ const PagamentoErrore = ({ baseUrl }: PagamentoErroreProps) => {
<Section className="mb-5"> <Section className="mb-5">
<Button <Button
className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900" className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900"
href={`${baseUrl}/area-riservata/dashboard`} href={`${env.BASE_URL}/area-riservata/dashboard`}
> >
Vai al tuo account Vai al tuo account
</Button> </Button>

View file

@ -1,14 +1,11 @@
import { Button, Heading, Row, Section, Text } from "@react-email/components"; import { Button, Heading, Row, Section, Text } from "@react-email/components";
import { env } from "~/env";
import Base from "./base"; import Base from "./base";
export type PagamentoRicezione_NewMail = { export type PagamentoRicezione_NewMail = {
mailType: "pagamentoRicezione"; mailType: "pagamentoRicezione";
props: PagamentoRicezioneProps;
}; };
type PagamentoRicezioneProps = { const PagamentoRicezione = () => {
baseUrl: string;
};
const PagamentoRicezione = ({ baseUrl }: PagamentoRicezioneProps) => {
return ( return (
<Base preview="Ricezione Pagamento"> <Base preview="Ricezione Pagamento">
<> <>
@ -26,7 +23,7 @@ const PagamentoRicezione = ({ baseUrl }: PagamentoRicezioneProps) => {
<Section className="mb-5"> <Section className="mb-5">
<Button <Button
className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900" className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900"
href={`${baseUrl}/area-riservata/dashboard`} href={`${env.BASE_URL}/area-riservata/dashboard`}
> >
Vai al tuo account Vai al tuo account
</Button> </Button>

View file

@ -1,14 +1,11 @@
import { Button, Heading, Row, Section, Text } from "@react-email/components"; import { Button, Heading, Row, Section, Text } from "@react-email/components";
import { env } from "~/env";
import Base from "./base"; import Base from "./base";
export type RegistrazioneAvvenuta_NewMail = { export type RegistrazioneAvvenuta_NewMail = {
mailType: "registrazioneAvvenuta"; mailType: "registrazioneAvvenuta";
props: RegistrazioneAvvenutaProps;
};
type RegistrazioneAvvenutaProps = {
baseUrl: string;
}; };
const RegistrazioneAvvenuta = ({ baseUrl }: RegistrazioneAvvenutaProps) => { const RegistrazioneAvvenuta = () => {
return ( return (
<Base preview="Registrazione Avvenuta"> <Base preview="Registrazione Avvenuta">
<> <>
@ -25,7 +22,7 @@ const RegistrazioneAvvenuta = ({ baseUrl }: RegistrazioneAvvenutaProps) => {
<Section className="mb-5"> <Section className="mb-5">
<Button <Button
className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900" className="mx-auto box-border inline-flex h-10 items-center justify-center whitespace-nowrap rounded-md bg-neutral-100 px-4 py-2 text-center align-middle font-semibold text-neutral-900"
href={`${baseUrl}/area-riservata/dashboard`} href={`${env.BASE_URL}/area-riservata/dashboard`}
> >
Vai al tuo account Vai al tuo account
</Button> </Button>

View file

@ -1169,7 +1169,6 @@ export const sendServizioEmail = async ({
})), })),
nome, nome,
token: servizioId, token: servizioId,
baseUrl: env.BASE_URL,
}, },
subject: "Procedi ora su Infoalloggi.it", subject: "Procedi ora su Infoalloggi.it",
to: email, to: email,
@ -1448,7 +1447,6 @@ export const SendContactEmail = async ({
messaggio, messaggio,
nome, nome,
telefono, telefono,
baseUrl: env.BASE_URL,
}, },
subject: "Contatto per annuncio", subject: "Contatto per annuncio",
to: "web@infoalloggi.it", to: "web@infoalloggi.it",

View file

@ -250,9 +250,6 @@ export const whIntentFailedHandler = async ({
subject: "Pagamento Fallito", subject: "Pagamento Fallito",
to: utente.email, to: utente.email,
userId: utente.id, userId: utente.id,
props: {
baseUrl: env.BASE_URL,
},
}); });
} }
return true; return true;

View file

@ -129,14 +129,12 @@ export const genMail = async ({ ...mail }: MailsTemplates) => {
break; break;
case "pagamentoErrore": case "pagamentoErrore":
mailComponent = PagamentoErrore({ mailComponent = PagamentoErrore();
...mail.props,
});
title = "Errore pagamento"; title = "Errore pagamento";
break; break;
case "pagamentoRicezione": case "pagamentoRicezione":
mailComponent = PagamentoRicezione({ ...mail.props }); mailComponent = PagamentoRicezione();
title = "Ricezione pagamento"; title = "Ricezione pagamento";
break; break;
@ -153,9 +151,7 @@ export const genMail = async ({ ...mail }: MailsTemplates) => {
break; break;
case "registrazioneAvvenuta": case "registrazioneAvvenuta":
mailComponent = RegistrazioneAvvenuta({ mailComponent = RegistrazioneAvvenuta();
...mail.props,
});
title = "Registrazione avvenuta"; title = "Registrazione avvenuta";
break; break;