189 lines
6.9 KiB
Markdown
189 lines
6.9 KiB
Markdown
# 📧 Email de réponse support - Template amélioré
|
|
|
|
## ✨ Modifications appliquées
|
|
|
|
### 1. InfoCard standardisée
|
|
|
|
L'email de réponse au ticket support utilise maintenant la même structure que les autres notifications :
|
|
|
|
**Première card (InfoCard) :**
|
|
- **Votre structure** : Nom de l'organisation
|
|
- **Votre code employeur** : Code depuis `organization_details.code_employeur`
|
|
- **Votre gestionnaire** : Renaud BREVIERE-ABRAHAM (forcé)
|
|
|
|
### 2. DetailsCard enrichie
|
|
|
|
**Deuxième card (Message) :**
|
|
- **Répondant** : Prénom du staff avec majuscule automatique + "[Staff Odentas]"
|
|
- **Sujet** : Sujet du ticket
|
|
- **Réponse** : Message du staff
|
|
|
|
### 3. Formatage automatique du nom du staff
|
|
|
|
```typescript
|
|
// Exemple : "renaud" devient "Renaud [Staff Odentas]"
|
|
const formattedStaffName = data.staffName.charAt(0).toUpperCase() +
|
|
data.staffName.slice(1) +
|
|
' [Staff Odentas]';
|
|
```
|
|
|
|
## 📊 Structure du template
|
|
|
|
```
|
|
┌─────────────────────────────────────────────────────┐
|
|
│ Bonjour Jean, │
|
|
│ │
|
|
│ Vous avez reçu une nouvelle réponse │
|
|
│ à votre ticket support. │
|
|
│ │
|
|
│ ┌──────────────────────────────────────────────┐ │
|
|
│ │ Informations │ │
|
|
│ │ │ │
|
|
│ │ Votre structure: Entreprise ABC │ │
|
|
│ │ Votre code employeur: 12345 │ │
|
|
│ │ Votre gestionnaire: Renaud BREVIERE-ABRAHAM │ │
|
|
│ └──────────────────────────────────────────────┘ │
|
|
│ │
|
|
│ ┌──────────────────────────────────────────────┐ │
|
|
│ │ Message │ │
|
|
│ │ │ │
|
|
│ │ Répondant: Renaud [Staff Odentas] │ │
|
|
│ │ Sujet: Mon problème de paie │ │
|
|
│ │ Réponse: Bonjour, voici la solution... │ │
|
|
│ └──────────────────────────────────────────────┘ │
|
|
│ │
|
|
│ ┌──────────────────────┐ │
|
|
│ │ Voir le ticket │ │
|
|
│ └──────────────────────┘ │
|
|
└─────────────────────────────────────────────────────┘
|
|
```
|
|
|
|
## 🗂️ Sources de données
|
|
|
|
| Donnée | Source | Champ |
|
|
|--------|--------|-------|
|
|
| **Nom organisation** | `organizations` | `name` |
|
|
| **Code employeur** | `organization_details` | `code_employeur` |
|
|
| **Gestionnaire** | Forcé | `"Renaud BREVIERE-ABRAHAM"` |
|
|
| **Prénom staff** | `auth.users.user_metadata` | `display_name` ou `first_name` |
|
|
| **Sujet ticket** | `tickets` | `subject` |
|
|
| **Message** | Corps du message | POST body |
|
|
|
|
## 💻 Code modifié
|
|
|
|
### 1. `/lib/emailTemplateService.ts`
|
|
|
|
```typescript
|
|
infoCard: {
|
|
title: 'Informations',
|
|
items: [
|
|
{ label: 'Votre structure', value: 'organizationName' },
|
|
{ label: 'Votre code employeur', value: 'employerCode' },
|
|
{ label: 'Votre gestionnaire', value: 'handlerName' },
|
|
],
|
|
},
|
|
detailsCard: {
|
|
title: 'Message',
|
|
items: [
|
|
{ label: 'Répondant', value: 'staffName' },
|
|
{ label: 'Sujet', value: 'ticketSubject' },
|
|
{ label: 'Réponse', value: 'staffMessage' },
|
|
],
|
|
},
|
|
```
|
|
|
|
### 2. `/lib/emailMigrationHelpers.ts`
|
|
|
|
```typescript
|
|
export async function sendSupportReplyEmail(
|
|
toEmail: string,
|
|
data: {
|
|
firstName?: string;
|
|
ticketId: string;
|
|
ticketSubject: string;
|
|
staffName: string;
|
|
staffMessage: string;
|
|
organizationName?: string;
|
|
employerCode?: string; // ⭐ Nouveau : code depuis organization_details
|
|
}
|
|
) {
|
|
// ⭐ Formatage automatique : majuscule + [Staff Odentas]
|
|
const formattedStaffName = data.staffName.charAt(0).toUpperCase() +
|
|
data.staffName.slice(1) +
|
|
' [Staff Odentas]';
|
|
|
|
const emailData: EmailDataV2 = {
|
|
firstName: data.firstName,
|
|
ticketId: data.ticketId,
|
|
ticketSubject: data.ticketSubject,
|
|
staffName: formattedStaffName,
|
|
staffMessage: data.staffMessage,
|
|
organizationName: data.organizationName || 'Non définie',
|
|
employerCode: data.employerCode || 'Non défini', // ⭐ Nouveau
|
|
handlerName: 'Renaud BREVIERE-ABRAHAM', // ⭐ Forcé
|
|
ctaUrl: `${process.env.NEXT_PUBLIC_BASE_URL}/support/${data.ticketId}`,
|
|
};
|
|
|
|
await sendUniversalEmailV2({
|
|
type: 'support-reply',
|
|
toEmail,
|
|
subject: `Nouvelle réponse à votre ticket: ${data.ticketSubject}`,
|
|
data: emailData,
|
|
});
|
|
}
|
|
```
|
|
|
|
### 3. `/app/api/tickets/[id]/messages/route.ts`
|
|
|
|
```typescript
|
|
// ⭐ Récupération du code employeur
|
|
const { data: orgDetails } = await sb
|
|
.from("organization_details")
|
|
.select("code_employeur")
|
|
.eq("org_id", ticket.org_id)
|
|
.maybeSingle();
|
|
|
|
// Envoi de l'email avec les nouvelles données
|
|
await sendSupportReplyEmail(creatorUser.user.email, {
|
|
firstName,
|
|
ticketId: ticket.id,
|
|
ticketSubject: ticket.subject,
|
|
staffName,
|
|
staffMessage: text,
|
|
organizationName: organization?.name,
|
|
employerCode: orgDetails?.code_employeur, // ⭐ Code employeur
|
|
});
|
|
```
|
|
|
|
## 📋 Logs de debug
|
|
|
|
Dans le terminal, vous verrez :
|
|
|
|
```
|
|
📧 [POST messages] Organization: { name: 'Entreprise ABC', structure_api: 'abc' }
|
|
📧 [POST messages] Org details: { code_employeur: '12345' }
|
|
📧 [POST messages] Données email: {
|
|
firstName: 'Jean',
|
|
staffName: 'renaud',
|
|
ticketId: 'xxx-xxx-xxx',
|
|
ticketSubject: 'Mon problème',
|
|
organizationName: 'Entreprise ABC',
|
|
employerCode: '12345'
|
|
}
|
|
```
|
|
|
|
Le nom du staff sera automatiquement formaté en : `Renaud [Staff Odentas]`
|
|
|
|
## ✅ Résultat
|
|
|
|
Les emails de réponse au ticket support ont maintenant :
|
|
- ✅ La même structure que les autres notifications
|
|
- ✅ Le code employeur correct depuis `organization_details`
|
|
- ✅ Le gestionnaire forcé à "Renaud BREVIERE-ABRAHAM"
|
|
- ✅ Le nom du staff formaté avec majuscule + badge "[Staff Odentas]"
|
|
- ✅ Toutes les informations importantes dans la première card
|
|
- ✅ Les détails du message dans la deuxième card
|
|
|
|
---
|
|
|
|
*Améliorations appliquées le 14 octobre 2025*
|