From 162b0e77448ebe02594949d2c9023ca57723f524 Mon Sep 17 00:00:00 2001 From: Alex Prudencio Date: Wed, 7 Aug 2024 08:01:39 -0400 Subject: [PATCH] fix assessment link --- .../service/AssessmentService.java | 6 ++-- .../views/AssessmentsListView.java | 30 ++++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/AssessmentService.java b/src/main/java/com/primefactorsolutions/service/AssessmentService.java index 87fceb4..826ba24 100644 --- a/src/main/java/com/primefactorsolutions/service/AssessmentService.java +++ b/src/main/java/com/primefactorsolutions/service/AssessmentService.java @@ -6,12 +6,10 @@ import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.checkerframework.checker.units.qual.A; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Service; -import javax.swing.text.html.Option; import java.time.Instant; import java.util.List; import java.util.Map; @@ -39,6 +37,7 @@ public class AssessmentService { final String evaluationLink = String.format("https://careers.primefactorsolutions.com/evaluation/%s", assessment.getId()); final SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("no-reply@primefactorsolutions.com"); + message.setBcc("no-reply@primefactorsolutions.com"); message.setTo(assessment.getAppUser().getEmail()); message.setSubject("PFS - Evaluacion Tecnica"); message.setText(String.format("Estimado candidato,\n\nGracias por su candidatura. En esta etapa del proceso de seleccion, usted debe completar " @@ -48,8 +47,9 @@ public class AssessmentService { + "Exito!")); emailSender.send(message); + log.info("Sent email to {}", assessment.getAppUser().getEmail()); } catch (Exception e) { - log.error("Error sending email", e); + log.error("Error sending email to {}", assessment.getAppUser().getEmail(), e); throw e; } } diff --git a/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java b/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java index fcac787..6246bb7 100644 --- a/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java +++ b/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java @@ -3,7 +3,9 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Assessment; import com.primefactorsolutions.service.AssessmentService; import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.ComponentEventListener; import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.confirmdialog.ConfirmDialog; import com.vaadin.flow.component.html.Main; import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.data.provider.DataProvider; @@ -31,15 +33,27 @@ public class AssessmentsListView extends Main { public AssessmentsListView(final AssessmentService assessmentService) { final VGrid grid = new VGrid<>(Assessment.class); grid.setColumns("id", "appUser.email"); - grid.addComponentColumn((ValueProvider) assessment -> new Button("Copy", event -> - ClientsideClipboard.writeToClipboard(String.format("https://localhost:8080/evaluation/%s", assessment.getId())) + grid.addComponentColumn((ValueProvider) assessment -> new Button("Copy Link", event -> + ClientsideClipboard.writeToClipboard( + String.format("email: %s link: https://careers.primefactorsolutions.com/evaluation/%s", + assessment.getAppUser().getEmail(), + assessment.getId())) )); - grid.addComponentColumn((ValueProvider) assessment -> new Button("Send", event -> { - try { - assessmentService.sendEmail(assessment); - } catch (Exception e) { - Notification.show("Error sending email: " + e.getMessage(), 10_000, Notification.Position.TOP_CENTER); - } + grid.addComponentColumn((ValueProvider) assessment -> new Button("Send Email", event -> { + ConfirmDialog dialog = new ConfirmDialog(); + dialog.setHeader("Send Link Email"); + dialog.setText(String.format("Enviar link por email al candidato %s?", assessment.getAppUser().getEmail())); + dialog.setCancelable(true); + dialog.setConfirmText("Enviar"); + dialog.setConfirmButtonTheme("primary"); + dialog.addConfirmListener((ComponentEventListener) confirmEvent -> { + try { + assessmentService.sendEmail(assessment); + } catch (Exception e) { + Notification.show("Error sending email: " + e.getMessage(), 10_000, Notification.Position.TOP_CENTER); + } + }); + dialog.open(); })); grid.setDataProvider(new DataProvider<>() {