Hiding posts that are expired and trigger mails to multiple people

Hi, This is Jo Kurino, a Wix Ambassador in Japan.

I am currently in the interview/questionnaire stages with a potential client that would like to create a event promotion portal in Hiroshima. Their current website is http://skill-migaki.com/hiroshima/ and would like to create something similar with Wix.

1.) The model of the website is for event/seminar promoters to post their events via form on the website.
2.) Visitors are able to view the event postings and sign-up for events.
3.) The event host/promoter and webmaster are notified of sign-ups via trigger mail.
4.) the promoter will then correspond with people whom signed up on a personal level.

I know they I can create search functions with filters on Wix Code. I know I can create a dynamic page + lists and grids to display events. I assume that I can use the dataset that is by the promoters to post information and mirror it to display events.

The challenge I face is:

1.) the client wants event information to be displayed until a date specified by the promoter and want it to disappear once the expiration dates comes. Paid users can post without display date limits and free users may only post for a certain period of time. In regards to paid users, the current site just ask for the poster to choose if they will pay or not via checkbox, and the administrator sends an invoice via e-mail.

2.) Being able to send trigger mails to both the webmaster and event promoter simultaneously when there is an event sign-up.
3.) Allowing the person that signed up for the event to receive a confirmation trigger mail too.

Can you advise on what codes I can use or if there are any workarounds? I would like receive a response no later than sunday, if possible since I have a meeting with the client on monday. I appreciate your assistance in advance!

I guess there is no solution for this?

#brettharalson

There are several things you need to do to accomplish this.

I have prepared a dummy site with the full code that you can explore here:
https://stevendc88.wixsite.com/expiring-events

First of all you need to have an event data collection that has a date value that you use to expire the event. You can use preexisting date values such as _createdDate or _updateDate but creating a special data collection field to filter on is probably the best way forward.

Now to manage event filtering when the page is displayed you will probably want to use the built in setTimeout function and use a recursive function that keeps calling the time out, which fires after a set period, to refresh the event listing display using a filter on the expiration date you created. The filter is straight forward and would look something like:

$w('#dataset1').setFilter(wixData.filter.gt('expirationDate', new Date());

By calling new Date() you get the time now. This can be compared by the wixData gt function with the expirationDate to determine if the event has expired.

Now sending emails requires the use of triggered emails. You need to be aware of whether or not the site visitor is a members (signed in or not). Given the outline you are suggesting that there is no Membership model being used. In this case you can simply use the Wix CRM capabilities to generate the triggeredEmails.

There is an article here that addresses this: Velo Tutorial: Sending a Triggered Email to Contacts | Help Center | Wix.com and there are several youtube videos that describe how to do this also as well as the code I share at the link above.

What you can do is take advantage of the way wix-crm.createContact works. Basically you take some minimal information from the site visitor that you want to send email to, firstName, email and optionally other fields. You then use them in createContact to create a CRM record. If the email already exists in a CRM record then the same record will be used and updated. The key here is that the createContact returns a contactId. It is this that you need to send the triggered email.

Now of course if the site owner is also in the CRM then you can determine their id and hard code it in some backend code to send the notifications you require following a new event being added in the same way as with any visitor.

The simple code for this is:

// Create a contact record in our crm. This will simply update
       // any pre-existing CRM record. The key here is we want the
       // contactId from the then() result.
       wixCrm.createContact({
           'firstName': $w('#firstName').value,
           // Note here we add the email to an email array in the CRM
           'emails':[$w('#promoterEmail').value]})
       .then((contactId) => {
           // We now have a contactId for the triggered email we 
           // want to send.
           // save the event and notify the contact
           // We ALWAYS return a promise function from a then() to 
           // keep the then chain going and allow errors to be 
           // Caught up the chain.
           return $w('#dataset1').save()
           .then(() => {
              // Send our triggered email!
              // The triggered email id is "EventCreatedEmail" and must be
              // Created in the dashboard before it can be used in code.
              // We ALWAYS return a promise function from a then() to 
              // keep the then chain going and allow errors to be 
              // Caught up the chain.
               return wixCrm.emailContact("EventCreatedEmail", contactId, {"variables": {
                   "eventName":$w('#dataset1').getCurrentItem().title,
                   "listingType": $w('#eventListing').value,
                   "expirationDate": expirationDate.toString()}});
           });

The example site and this explanation should help you out.

Cheers
Steve