Forked from mackenziechild/No Code Membership Demo Mark As Complete
Last active
August 31, 2022 19:36
-
-
Save johnematias/db961d0033a9d96f8deaf9e67a275f90 to your computer and use it in GitHub Desktop.
This will add meta data to the member profile in Memberstack which allows us to hide or show the mark as complete form.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://api.memberstack.io/static/memberstack.js?webflow" data-memberstack-id="GET_FROM_MEMBERSTACK"></script> | |
<script> | |
MemberStack.onReady.then(async function(member) { | |
// Checks if member is logged in | |
if(member.loggedIn){ | |
const metadata = await member.getMetaData(); | |
// If no metadata.liked_topics exists, create it in MemberStack. | |
metadata.liked_topics = metadata.liked_topics || []; | |
// If no metadata.completed_topics exists, create it in MemberStack. | |
metadata.completed_topics = metadata.completed_topics || []; | |
// Defines the webflow ID to a const of itemID (Pull this from the CMS) | |
const itemID = "GET_FROM_CMS"; | |
// If they have the item ID in their profile, hide the form, show the appropriate button | |
if(metadata.liked_topics.includes(itemID)){ | |
document.getElementById('like-topic').style.display = 'none'; | |
document.getElementById('unlike-topic').style.display = 'block'; | |
}; | |
if(metadata.completed_topics.includes(itemID)){ | |
document.getElementById('complete-topic').style.display = 'none'; | |
document.getElementById('uncomplete-topic').style.display = 'block'; | |
}; | |
// When the like-topic button is clicked, if the itemID doesn't exist on their profile | |
// add it, then push the metadata to MemberStack. | |
$('#like-topic').click(function(){ | |
if(metadata.liked_topics.indexOf(itemID) === -1){ | |
metadata.liked_topics.push(itemID); | |
member.updateMetaData(metadata); | |
setTimeout(function(){ location.reload(); }, 3000); | |
} | |
}); | |
// When the complete-topic button is clicked, if the itemID doesn't exist on their profile | |
// add it, then push the metadata to MemberStack. | |
$('#complete-topic').click(function(){ | |
if(metadata.completed_topics.indexOf(itemID) === -1){ | |
metadata.completed_topics.push(itemID); | |
member.updateMetaData(metadata); | |
setTimeout(function(){ location.reload(); }, 3000); | |
} | |
}); | |
// When the unlike-topic button is clicked, if the itemID exists on their profile | |
// remove it, then push the metadata to MemberStack. | |
$('#unlike-topic').click(function(){ | |
if(metadata.liked_topics.includes(itemID)){ | |
const itemIndex = metadata.liked_topics.indexOf(itemID); | |
metadata.liked_topics.splice(itemIndex); | |
member.updateMetaData(metadata); | |
setTimeout(function(){ location.reload(); }, 3000); | |
} | |
}); | |
// When the uncomplete-topic button is clicked, if the itemID exists on their profile | |
// remove it, then push the metadata to MemberStack. | |
$('#uncomplete-topic').click(function(){ | |
if(metadata.completed_topics.includes(itemID)){ | |
const itemIndex = metadata.completed_topics.indexOf(itemID); | |
metadata.completed_topics.splice(itemIndex); | |
member.updateMetaData(metadata); | |
setTimeout(function(){ location.reload(); }, 3000); | |
} | |
}); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setting up to add and remove items from metadata.