Hi,
I try to send an email with a code, but when I press the “send invite” button (aka button 14),
I got: “try to send suggest”
then: “TypeError: Failed to fetch”.
Here’s my code, any idea how to solve it? (or better- how to send email properly?)
thnx!
import {session} from 'wix-storage';
import wixData from 'wix-data';
import wixCrm from 'wix-crm';
$w.onReady( function () {
//let ravak = session.getItem('ravak_id');
let ravak2 = "cac037f6-6b72-4c04-a821-7cfc5952ff15";
let ravak;
$w("#dataset3").onReady(function () { // filter dataset3 to show up the single details.
filterEq($w("#dataset3"), "_id", ravak2)
})
wixData.query("ravakim").eq("_id", ravak2).find().then((result) =>{ // find this sinlge details
ravak = result.items[0];
console.log(ravak)
$w("#dataset2").onReady( function () { //use to filter the matches repeater (the filter not exist yet).
console.log(ravak);
getItem(ravak)
console.log($w("#dataset2").getTotalCount())
console.log(ravak._id)
});
});
});
function getItem (ravak) {
console.log(ravak);
$w('#listRepeater').forEachItem(($item,itemData,index)=>
{
$item("#button13").onClick(()=>{ // add to match
console.log("try to add")
// $item("#button13").enabled = false;
$item("#button13").hide();
$item("#text96").show();
let match = {
"title" : ravak.title,
"singleId":ravak._id,
"matchId":itemData._id,
"name":itemData.title,
"age":itemData.age,
"haskafa":itemData.pointOfView,
"height":itemData.height,
"image":itemData.image,
"status":itemData.status,
"aboutMe":itemData.aboutmMe,
}
wixData.insert("matchsToTry", match).then((res)=>{
if(res)
console.log("the match add successfully")
console.log(res);
})})
$item("#button14").onClick(()=>{ // add to suggestion
console.log("try to send suggest")
// $item("#button14").enabled = false;
$item("#button14").hide();
$item("#text97").show();
let suggestion = {
"name":itemData.title,
"age":itemData.age,
"singleId":ravak._id,
"haskafa": itemData.pointOfView,
"image": itemData.image,
"height": itemData.height,
"suggestionId":itemData._id,
"matchMakerId": itemData.shadchanId,
"mmName": ravak.mmName,
"reason": " ",
"status": "פתוחה",
"commentMm": "להכניס הערת שדכן",
"title": ravak.title
}
wixData.insert("suggestiondata", suggestion).then((res)=>{
console.log("the suggestion add successfully")
console.log(res);
})
// let a = false
// if(a){
// wixCrm.createContact({
// "firstName":"בדיקה",
// "lastName": "בדיקה",
// "emails": ["roipk123@gmail.com"],
// "phones": ["1521"]
// })
// .then((contactId) => { // check this not working!
// console.log("create contant succeed");
// })
// .catch((err) =>{
// console.log(err);
// });
// }
let userid = "741fc343-e686-4cc0-9168-eb60d8663eb0";
wixCrm.emailContact('suggestionEmail', userid, {
variables: {
name:"דוד",
link:"https://www.zoog4life.com/suggestion"
}}) .then(() =>{
console.log("Triggered email sent");
})
.catch((err) =>{
console.log(err);
});
})})}
async function filterEq (dataset,filerType,item) {
await dataset.setFilter( wixData.filter()
.eq(filerType, item));
//console.log(2);