Skip to content

Commit

Permalink
fix: retours demo nouveaux avis et mailing notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannNumericite committed Dec 3, 2024
1 parent 73a31a6 commit 8c058c8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ const useStyles = tss.withName(ProductCard.name).create({
cardSkeleton: {},
productTitle: {
fontSize: '18px',
lineHeight: '1.5rem',
fontWeight: 'bold',
color: fr.colors.decisions.text.title.blueFrance.default,
backgroundImage: 'none',
Expand Down Expand Up @@ -755,7 +756,8 @@ const useStyles = tss.withName(ProductCard.name).create({
gap: fr.spacing('2v')
},
reviewWrapper: {
display: 'flex'
display: 'flex',
justifyContent: 'space-between'
},
notifSpan: {
display: 'block',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const ProductReviewsPage = (props: Props) => {
const [buttonId, setButtonId] = React.useState<number>();
const [newReviewHandled, setNewReviewHandled] =
React.useState<boolean>(false);
const { fromMail } = router.query;
const isFromMail = fromMail === 'true';

const debouncedStartDate = useDebounce<string>(startDate, 500);
const debouncedEndDate = useDebounce<string>(endDate, 500);
Expand Down Expand Up @@ -139,7 +141,8 @@ const ProductReviewsPage = (props: Props) => {
sort: sort,
filters: filters,
newReviews: newReviews,
needLogging: true
needLogging: true,
loggingFromMail: isFromMail
},
{
initialData: {
Expand Down
52 changes: 29 additions & 23 deletions webapp-backoffice/src/server/routers/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,39 +425,40 @@ export const openAPIRouter = router({
});

// Associate users with accessible products and send mails
const userProductAssociations = users.map((user) => {
const userProductAssociations = [];

for (let i = 0; i < users.length; i++) {
const user = users[i];
const accessibleProductIds = [
...user.accessRights.map((ar) => ar.product_id),
...user.adminEntityRights.flatMap((aer) => aer.entity.products.map((p) => p.id))
...user.adminEntityRights.flatMap((aer) => aer.entity.products.map((p) => p.id)),
];

const accessibleProducts = user.role.includes("admin")
? products
.sort((a, b) => b.reviewCount - a.reviewCount)
.slice(0, 10)
.sort((a, b) => b.reviewCount - a.reviewCount)
.slice(0, 10)
: products
.filter((product) => accessibleProductIds.includes(product.productId))
.sort((a, b) => b.reviewCount - a.reviewCount)
.slice(0, 10);
.filter((product) => accessibleProductIds.includes(product.productId))
.sort((a, b) => b.reviewCount - a.reviewCount)
.slice(0, 10);

const totalNewReviews = accessibleProducts.reduce((sum, product) => sum + product.reviewCount, 0);

if(accessibleProducts.length > 0) {
if (accessibleProducts.length > 0) {
const email = getEmailNotificationsHtml(
user.id,
scope,
totalNewReviews,
user.id,
scope,
totalNewReviews,
startDate,
endDate,
accessibleProducts.map((ap) => {
return {
title: ap.title,
id: ap.productId,
nbReviews: ap.reviewCount
}}
)
accessibleProducts.map((ap) => ({
title: ap.title,
id: ap.productId,
nbReviews: ap.reviewCount,
}))
);

sendMail(
'Nouveaux avis JDMA',
user.email,
Expand All @@ -466,12 +467,17 @@ export const openAPIRouter = router({
);
}

return {
userProductAssociations.push({
userEmail: user.email,
userId: user.id,
accessibleProducts
};
});
accessibleProducts,
});

if ((i + 1) % 10 === 0) {
console.log(`Pausing mailing after ${i + 1} users...`);
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}

scopeResult.users = userProductAssociations;
}
Expand Down
3 changes: 2 additions & 1 deletion webapp-backoffice/src/server/routers/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const reviewRouter = router({
end_date: z.string().optional(),
newReviews: z.boolean().optional(),
needLogging: z.boolean().optional().default(false),
loggingFromMail: z.boolean().optional(),
filters: z
.object({
satisfaction: z.array(z.string()).optional(),
Expand Down Expand Up @@ -145,7 +146,7 @@ export const reviewRouter = router({
await ctx.prisma.userEvent.create({
data: {
user_id: parseInt(user.id),
action: 'service_reviews_view',
action: input.loggingFromMail ? 'service_reviews_report_view' : 'service_reviews_view',
product_id: product_id,
metadata: input
}
Expand Down
30 changes: 16 additions & 14 deletions webapp-backoffice/src/utils/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getEmailWithLayout(content: string) {
<body>
<div class="container">
<div class="header">
<img src="https://jdma-develop.cleverapps.io/assets/JDMA_Banner.png"/>
<img src="https://jedonnemonavis.numerique.gouv.fr/assets/JDMA_Banner.png"/>
</div>
${content}
<p>
Expand Down Expand Up @@ -333,19 +333,21 @@ export function getEmailNotificationsHtml(
</div>
<ul style='list-style: none; margin: 0px; padding: 0px;'>
${products.map(p => {
return `<li style='border: 1px solid #e0e0e0; padding: 16px;'>
<div style='display: flex; flex-direction: row; justify-content: space-between; align-items: center;'>
<div style='width: 70%;'>
<p style='color:#000091; font-weight: bold; font-size: 16px; line-height: 24px;'>${p.title}</p>
</div>
<div style='display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; width: 30%;'>
<p style='font-weight: bold; color: #0063CB; font-size: 14px; line-height: 24px; margin-bottom: 4px; text-align: left;'> +${formatNbReviews(p.nbReviews)}</p>
<a style='font-size: 12px; line-height: 20px;' href="${jdmaUrl}/administration/dashboard/product/${p.id.toString()}/reviews" target="_blank">Voir les nouveaux avis</a>
</div>
</div>
</li>`;
})}
</ul>
return `
<li style='border: 1px solid #e0e0e0; padding: 16px; margin-top: 2rem'>
<div style='display: flex; flex-direction: row; justify-content: space-between; align-items: center;'>
<div style='width: 70%;'>
<p style='color:#000091; font-weight: bold; font-size: 16px; line-height: 24px;'>${p.title}</p>
</div>
<div style='display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; width: 30%;'>
<p style='font-weight: bold; color: #0063CB; font-size: 14px; line-height: 24px; margin-bottom: 4px; text-align: left;'> +${formatNbReviews(p.nbReviews)}</p>
<a style='font-size: 12px; line-height: 20px;' href="${jdmaUrl}/administration/dashboard/product/${p.id.toString()}/reviews?fromMail=true" target="_blank">Voir les avis</a>
</div>
</div>
</li>`;
}).join('')}
</ul>
</div>
<a href="${jdmaUrl}/administration/dashboard/products" target="_blank">Voir plus de détails sur votre tableau de bord JDMA</a>
Expand Down

0 comments on commit 8c058c8

Please sign in to comment.