Show message to users in organization only (or registred)

Answered

1 Comments

  • Diziana
    Comment actions Permalink

    Hi

    I think, you can do this. I am sharing an example where you can show a message to signed-in users, override that message for users who belong to at least one organization, and further override that for user who belongs to any special organization (from predefined list).

    {{#if signed_in}}
    <div id="org_message"></div>
    <script>
    //List of organizations you want to check for
    var allowedOrganizations = ["Organization 1", "ORG2"];

    function userBelongsToAllowedOrgnizations(allowedOrganizations, userOrganziations) {
    var userOrgs = userOrganziations || [];
    var found = userOrgs.find(function (userOrg) {
    return allowedOrganizations.some(function (ao) {
    return ao === userOrg.name
    });
    });
    console.log(found);

    return found || false;
    }

    function userBelongsToAtleastOneOrganization(userOrganziations) {
    return userOrganziations.length >= 1;
    }

    $(document).ready(function () {
    var message = "Default message shown to all signed-in users.";
    //Use an internal API; if it's gone tomorrow, this can be pulled via API
    var userOrganziations = HelpCenter.user.organizations;
    //check and show message to user belonging to at least one organization;
    if (userBelongsToAtleastOneOrganization(userOrganziations)) {
    message = "Yay! You belong to at least one organization.";
    }

    //check and show message to user belonging to one of organization from allowedOrganizations;
    if (userBelongsToAllowedOrgnizations(allowedOrganizations, userOrganziations)) {
    //Update the message (above) to something else for user belongs to listed organizations.
    message = "Yay! You belong to one of organziations we love most.";
    }

    $("#org_message").html("<p>" + message + "</p>");
    });
    </script>
    {{else}}
    {{!-- Not signed-in; won't show message --}}
    {{/if}}

     

    Thank you

    Team Diziana

    0

Please sign in to leave a comment.

Powered by Zendesk