I pre-apologize for the long winded post, but I figure it’s better to be as specific as possible!
My goals for app functionality are:
- User can add as many people as they want
- User can remove people
- When user clicks submit button, all participants are randomly matched up and then emailed who they are supposed to get a gift for
- User receives confirmation of all who were matched
- User receives any errors that happened while sending emails
- User can reset page once they are done and submit a new batch of people for a different secret santa
Currently almost everything works! The only thing that is giving me an issue is that even if someone is not successfully emailed, they are still shown as having been emailed. I have commented on this in the code.
The first handles adding and deleting additional inputs for participants in the form. This mainly relies on jQuery.
The second is the trickier part that stores the information from the form and then matches people together. This is where I would love to get feedback if possible; especially if there is a better, simpler way to do it! Essentially how it works right now is that the name and email of each individual is stored in an object. An array is created from the names in the object. We then “shuffle” the array so it is in random order.
We then iterate through the array using a for loop. The assign the next name in the array to the current person in the array by pushing the next name to the current person’s object. Next we utilize emailjs.com’s handy API to send an email to each person with the name of who they need to get a gift for.
Once this is all done a results section appears with the names of everyone who was successfully emailed (currently not working properly).