Checkpoint: Correction et finalisation du template email attestation : ajout du type 'attestation' dans le frontend, création automatique du template au démarrage de l'application, déploiement réussi sur le VPS. Le template est maintenant visible et modifiable dans l'interface de gestion des templates.
This commit is contained in:
@@ -38,7 +38,7 @@ export default function AdminEmailTemplates() {
|
|||||||
const [selectedType, setSelectedType] = useState<string>("inscription");
|
const [selectedType, setSelectedType] = useState<string>("inscription");
|
||||||
const [showPreviewModal, setShowPreviewModal] = useState(false);
|
const [showPreviewModal, setShowPreviewModal] = useState(false);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
type: "inscription" as "inscription" | "teaser" | "rappel1" | "rappel2" | "rappel3" | "rappel4" | "rappel5" | "rappel6" | "reset_password",
|
type: "inscription" as "inscription" | "teaser" | "rappel1" | "rappel2" | "rappel3" | "rappel4" | "rappel5" | "rappel6" | "reset_password" | "attestation",
|
||||||
titre: "",
|
titre: "",
|
||||||
bodyContent: "",
|
bodyContent: "",
|
||||||
couleurPrincipale: "#283581",
|
couleurPrincipale: "#283581",
|
||||||
@@ -92,7 +92,7 @@ export default function AdminEmailTemplates() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentTemplate) {
|
if (currentTemplate) {
|
||||||
const newData = {
|
const newData = {
|
||||||
type: currentTemplate.type as "inscription" | "teaser" | "rappel1" | "rappel2" | "rappel3" | "rappel4" | "rappel5" | "rappel6" | "reset_password",
|
type: currentTemplate.type as "inscription" | "teaser" | "rappel1" | "rappel2" | "rappel3" | "rappel4" | "rappel5" | "rappel6" | "reset_password" | "attestation",
|
||||||
titre: currentTemplate.titre,
|
titre: currentTemplate.titre,
|
||||||
bodyContent: currentTemplate.bodyContent || "",
|
bodyContent: currentTemplate.bodyContent || "",
|
||||||
couleurPrincipale: currentTemplate.couleurPrincipale,
|
couleurPrincipale: currentTemplate.couleurPrincipale,
|
||||||
@@ -128,7 +128,7 @@ export default function AdminEmailTemplates() {
|
|||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
if (currentTemplate) {
|
if (currentTemplate) {
|
||||||
setFormData({
|
setFormData({
|
||||||
type: currentTemplate.type as "inscription" | "teaser" | "rappel1" | "rappel2" | "rappel3" | "rappel4" | "rappel5" | "rappel6" | "reset_password",
|
type: currentTemplate.type as "inscription" | "teaser" | "rappel1" | "rappel2" | "rappel3" | "rappel4" | "rappel5" | "rappel6" | "reset_password" | "attestation",
|
||||||
titre: currentTemplate.titre,
|
titre: currentTemplate.titre,
|
||||||
bodyContent: currentTemplate.bodyContent || "",
|
bodyContent: currentTemplate.bodyContent || "",
|
||||||
couleurPrincipale: currentTemplate.couleurPrincipale,
|
couleurPrincipale: currentTemplate.couleurPrincipale,
|
||||||
@@ -216,6 +216,7 @@ export default function AdminEmailTemplates() {
|
|||||||
{ value: "rappel5", label: "Rappel 5" },
|
{ value: "rappel5", label: "Rappel 5" },
|
||||||
{ value: "rappel6", label: "Rappel 6" },
|
{ value: "rappel6", label: "Rappel 6" },
|
||||||
{ value: "reset_password", label: "Réinitialisation de mot de passe" },
|
{ value: "reset_password", label: "Réinitialisation de mot de passe" },
|
||||||
|
{ value: "attestation", label: "Attestation de formation" },
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { serveStatic, setupVite } from "./vite";
|
|||||||
import { initRappelScheduler } from "../rappelScheduler";
|
import { initRappelScheduler } from "../rappelScheduler";
|
||||||
import { initRappelRetryScheduler } from "../rappelRetry";
|
import { initRappelRetryScheduler } from "../rappelRetry";
|
||||||
import { initFail2BanAlertSystem } from "../fail2banAlertService";
|
import { initFail2BanAlertSystem } from "../fail2banAlertService";
|
||||||
|
import { initAttestationTemplate } from "../initTemplates";
|
||||||
|
|
||||||
function isPortAvailable(port: number): Promise<boolean> {
|
function isPortAvailable(port: number): Promise<boolean> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
@@ -75,6 +76,9 @@ async function startServer() {
|
|||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`Server running on http://localhost:${port}/`);
|
console.log(`Server running on http://localhost:${port}/`);
|
||||||
|
|
||||||
|
// Initialiser les templates par défaut
|
||||||
|
initAttestationTemplate();
|
||||||
|
|
||||||
// Initialiser le scheduler de rappels automatiques
|
// Initialiser le scheduler de rappels automatiques
|
||||||
initRappelScheduler();
|
initRappelScheduler();
|
||||||
|
|
||||||
|
|||||||
51
server/initTemplates.ts
Normal file
51
server/initTemplates.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { getDb } from './db';
|
||||||
|
import { emailTemplates } from '../drizzle/schema';
|
||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise le template d'email pour les attestations s'il n'existe pas déjà
|
||||||
|
*/
|
||||||
|
export async function initAttestationTemplate() {
|
||||||
|
const db = await getDb();
|
||||||
|
if (!db) {
|
||||||
|
console.warn('[initTemplates] Database not available, skipping template initialization');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Vérifier si le template attestation existe déjà
|
||||||
|
const existing = await db
|
||||||
|
.select()
|
||||||
|
.from(emailTemplates)
|
||||||
|
.where(eq(emailTemplates.type, 'attestation'))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (existing.length > 0) {
|
||||||
|
console.log('[initTemplates] Template attestation already exists');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Créer le template par défaut
|
||||||
|
await db.insert(emailTemplates).values({
|
||||||
|
type: 'attestation',
|
||||||
|
titre: 'Attestation de formation',
|
||||||
|
bodyContent: `<p>Bonjour {{prenomApprenant}} {{nomApprenant}},</p>
|
||||||
|
|
||||||
|
<p>Nous vous remercions d'avoir participé à la formation <strong>{{nomFormation}}</strong>.</p>
|
||||||
|
|
||||||
|
<p>Vous trouverez ci-joint votre attestation de formation.</p>
|
||||||
|
|
||||||
|
<p>Nous espérons que cette formation vous a été bénéfique et nous vous souhaitons beaucoup de succès dans vos projets futurs.</p>
|
||||||
|
|
||||||
|
<p>Cordialement,<br>
|
||||||
|
L'équipe de formation</p>`,
|
||||||
|
couleurPrincipale: '#283581',
|
||||||
|
couleurSecondaire: '#0578BE',
|
||||||
|
piedDePage: 'Cet email a été envoyé automatiquement, merci de ne pas y répondre.',
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('[initTemplates] Template attestation created successfully');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[initTemplates] Error creating attestation template:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user