Skip to content
Snippets Groups Projects
Commit edb6a7c1 authored by Zahdi's avatar Zahdi
Browse files

[Progress] adding the invite a co author link generation

parent 840f7fad
No related branches found
No related tags found
No related merge requests found
...@@ -31,12 +31,19 @@ final class InvitationController extends AbstractController ...@@ -31,12 +31,19 @@ final class InvitationController extends AbstractController
$user = $this->getUser() ; $user = $this->getUser() ;
$data = json_decode($request->getContent(),true) ;
$wishlist_id = $data["wishlist_id"] ?? null ;
if (!$wishlist_id) {
return new JsonResponse(["error"=>"Missing wishlist_id"] , Response::HTTP_BAD_REQUEST) ;
}
if (!$user) { if (!$user) {
return $this->createAccessDeniedException('User is not connected'); return $this->createAccessDeniedException('User is not connected');
} }
$invitation->setInviter($user); $invitation->setInviter($user);
$invitation->setWishlist($entityManager->find(Wishlist::class, $request->get(key: 'wishlist_id'))); $invitation->setWishlist($entityManager->find(Wishlist::class, $wishlist_id));
$entityManager->persist($invitation); $entityManager->persist($invitation);
$entityManager->flush(); $entityManager->flush();
......
...@@ -21,7 +21,7 @@ class RegistrationController extends AbstractController ...@@ -21,7 +21,7 @@ class RegistrationController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() ) { if ($form->isSubmitted() ) {
dump($form->isValid()) ;
if ($form->isValid()){ if ($form->isValid()){
// Hacher le mot de passe // Hacher le mot de passe
$hashedPassword = $passwordHasher->hashPassword($user, plainPassword: $form->get('password')->getData()); $hashedPassword = $passwordHasher->hashPassword($user, plainPassword: $form->get('password')->getData());
...@@ -36,10 +36,12 @@ class RegistrationController extends AbstractController ...@@ -36,10 +36,12 @@ class RegistrationController extends AbstractController
} }
if (!$form->isValid()) { if (!$form->isValid()) {
dump("I am here ") ;
$errors = []; $errors = [];
foreach ($form->getErrors(true) as $error) { foreach ($form->getErrors(true) as $error) {
$errors[] = $error->getMessage(); $errors[] = $error->getMessage();
} }
dump($errors);
return $this->render('registration/register.html.twig', [ return $this->render('registration/register.html.twig', [
'registrationForm' => $form->createView(), 'registrationForm' => $form->createView(),
'formErrors' => $errors, 'formErrors' => $errors,
......
...@@ -4,33 +4,34 @@ ...@@ -4,33 +4,34 @@
{% block body %} {% block body %}
<style> <style>
.modal { /* Popup box styling */
display: none; /* Hide by default */ .popup-box {
position: fixed; display: none; /* Hidden by default */
position: fixed; /* Fixed relative to the viewport */
z-index: 1000; z-index: 1000;
left: 50%; background-color: #fff;
top: 50%; padding: 15px;
transform: translate(-50%, -50%); border: 1px solid #ccc;
background-color: white; border-radius: 6px;
padding: 20px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
border-radius: 8px; width: 220px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
.modal-content {
text-align: center;
} }
.close { /* Close button styling */
.popup-box .close {
position: absolute; position: absolute;
top: 10px; top: 5px;
right: 20px; right: 8px;
font-size: 24px; font-size: 18px;
cursor: pointer; cursor: pointer;
} }
/* Center content inside the popup */
.popup-box .content {
text-align: center;
margin-top: 20px;
}
</style> </style>
<header> <header>
...@@ -44,7 +45,9 @@ ...@@ -44,7 +45,9 @@
<div class="container"> <div class="container">
{% for wishlist in wishlists %} {% for wishlist in wishlists %}
<div class="wishlist"> <div class="wishlist">
<h2>{{ wishlist.name }}</h2> <a href="{{ path('app_wishlist_show', { 'id': wishlist.id }) }}">
{{ wishlist.name }}
</a>
<div class="wishlist-items"> <div class="wishlist-items">
{% for item in wishlist.items %} {% for item in wishlist.items %}
<div class="wishlist-item">📷</div> <div class="wishlist-item">📷</div>
...@@ -61,76 +64,106 @@ ...@@ -61,76 +64,106 @@
{% endfor %} {% endfor %}
</div> </div>
<!-- Modal Popup --> <!-- Popup Box -->
<div id="share-modal" class="modal"> <div id="popup-box" class="popup-box">
<div class="modal-content"> <span class="close">&times;</span>
<span class="close">&times;</span> <h4>Share Wishlist</h4>
<h3>Share Wishlist</h3> <div class="content">
<button id="invite-co-worker">Invite a Co-Worker</button> <button id="invite-co-worker">Invite a Co-Worker</button>
<br><br>
<button id="share-wishes">Share Your Wishes!</button> <button id="share-wishes">Share Your Wishes!</button>
</div> </div>
</div> </div>
<script> <script>
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
const shareButtons = document.querySelectorAll(".share-btn"); const shareButtons = document.querySelectorAll(".share-btn");
const modal = document.getElementById("share-modal"); const popupBox = document.getElementById("popup-box");
const closeBtn = document.querySelector(".close"); const closeBtn = popupBox.querySelector(".close");
let selectedWishlistId = null;
let selectedWishlistId = null; // Store the selected wishlist ID
// When a share button is clicked, position and show the popup.
shareButtons.forEach(button => { shareButtons.forEach(button => {
button.addEventListener("click", function () { button.addEventListener("click", function () {
selectedWishlistId = this.dataset.wishlistId; selectedWishlistId = this.dataset.wishlistId;
modal.style.display = "block"; // Reset invite button text and stored URL.
const inviteButton = document.getElementById("invite-co-worker");
inviteButton.textContent = "Invite a Co-Worker";
inviteButton.removeAttribute("data-invite-url");
const rect = this.getBoundingClientRect();
// Adjust popup position as needed.
popupBox.style.left = `${rect.left}px`;
popupBox.style.top = `${rect.top + rect.height + 8}px`;
popupBox.style.display = "block";
}); });
}); });
// Close popup when the close button is clicked.
closeBtn.addEventListener("click", function () { closeBtn.addEventListener("click", function () {
modal.style.display = "none"; popupBox.style.display = "none";
}); });
// Optionally close the popup if clicking outside.
window.addEventListener("click", function (event) { window.addEventListener("click", function (event) {
if (event.target === modal) { if (!popupBox.contains(event.target) && !event.target.classList.contains("share-btn")) {
modal.style.display = "none"; popupBox.style.display = "none";
} }
}); });
// Handle Invite a Co-Worker Click // Invite button click: first click fetches URL, second click copies it.
document.getElementById("invite-co-worker").addEventListener("click", async function () { document.getElementById("invite-co-worker").addEventListener("click", function () {
try { const inviteButton = this;
const response = await fetch("{{path('app_invitation_new')}}", { // Check if URL is already generated.
if (inviteButton.hasAttribute("data-invite-url")) {
// URL exists, copy it.
const url = inviteButton.getAttribute("data-invite-url");
navigator.clipboard.writeText(url)
.then(() => {
alert("URL was copied to clipboard successfully!");
popupBox.style.display = "none";
})
.catch(error => {
console.error("Clipboard write failed:", error);
alert("Failed to copy URL to clipboard.");
});
} else {
// Fetch the invite URL.
fetch("{{ path('app_invitation_new') }}", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
body: JSON.stringify({ wishlist_id: selectedWishlistId }) body: JSON.stringify({ wishlist_id: selectedWishlistId })
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
})
.then(responseData => {
if (responseData.joint_creation_URL) {
// Save URL in a data attribute and change button text.
inviteButton.setAttribute("data-invite-url", responseData.joint_creation_URL);
inviteButton.textContent = "Copy Invite URL";
alert("Invite URL generated. Click the button again to copy it.");
} else {
alert("Failed to generate invite link.");
}
})
.catch(error => {
console.error("Error:", error);
alert("Failed to send invitation.");
}); });
if (!response.ok) {
throw new Error("Network response was not ok");
}
const responseData = await response.json();
navigator.clipboard.writeText(responseData.url).then(() => {
alert("URL was copied to clipboard successfully!");
}).catch(err => {
alert("Error copying URL to clipboard: " + err);
});
} catch (error) {
console.error("Error:", error);
alert("Failed to send invitation.");
} }
}); });
// Handle Share Your Wishes Click // Share Your Wishes action placeholder.
document.getElementById("share-wishes").addEventListener("click", function () { document.getElementById("share-wishes").addEventListener("click", function () {
alert("Sharing your wishes! (Implement your sharing logic here)"); alert("Sharing your wishes! (Implement your sharing logic here)");
}); });
}); });
</script> </script>
{% endblock %} {% endblock %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment