npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@amityco/ulta-ui-kit

v1.1.1-beta05

Published

React Ui-Kit for Amity Social Cloud

Downloads

442

Readme

Ulta-Social-Cloud-Ui-Kit for Web

Getting started

The AmityUIKit provides a comprehensive user interface toolkit to quickly integrate Amity Social features into new or existing websites. This toolkit simplifies the incorporation of social interactions within your projects through an iframe-based integration.

Prerequisites

Before you begin, ensure you have the following installed:

• Node.js (>= 20.x) • React.js (>= 18.x)

Installation

With npm: npm install --save @amityco/ulta-ui-kit

With yarn: yarn add @amityco/ulta-ui-kit

Basic Usage

import { AmityUiKitProvider, AmityUiKitSocial } from "@amityco/ulta-ui-kit";

import "@amityco/ulta-ui-kit/dist/index.css";

export default function App() {
  // Retrieve userId from query parameters
  const urlParams = new URLSearchParams(window.location.search);
  const userId = urlParams.get("userId");
  const apiKey = "<your API key here>";
  const apiRegion = "<your API region here>";

  return (
    <div style={{ width: '100dvw', height: '100dvh' }}>
          <AmityUiKitProvider
            key={userId}
            apiKey={apiKey}
            userId={userId}
            apiRegion={apiRegion}
            ultaConfig={{
              newsCommunityId: 'newsCommunityId', // To configure the news communityId used to navigate from `Ulta Beuty News` banner
              faqCommunityId: 'faqCommunityId', // To configure the FAQs communityId used to navigate from `FAQs & Best Practices` banner
              defaultTab: 'explore', // To configure the default tab. The available default tabs are 'newfeeds', and 'explore'
              termsAndConditionsUrl: 'https://www.ulta.com/foo', // To configure the terms and conditions link on the nickname dialog
              privacyAndPolicyUrl: 'https://www.ulta.com/bar', // To configure the privacy and policy link on the nickname dialog
            }}
          >
            <AmityUiKitSocial />
          </AmityUiKitProvider>
    </div>
  );
}

Iframe Post Message Integration

In React, the component’s state dictates the behavior and rendering of the component. When the state changes, React automatically triggers a re-render of the component, updating the DOM where necessary. In your application, the userId is stored in the component’s state using the useState hook. This state determines the URL of the iframe where the Amity UIKit is loaded. When the userId state changes, React recognizes this change and re-renders the component, including the iframe, with the updated URL.

When an anonymous user click on any buttons to interact within community, the UIKit will emit a ‘anonymousNeedsLogin’ postMessage event. Below is a code example demonstrating how to receive this postMessage event from the UIKit Iframe:

import React, { useState, useEffect } from 'react';

export default function App() {
  // `userId` is managed as a state variable and will be updated post-login
  const [userId, setUserId] = useState('public-xxxx');

  // Handle the postMessage event from the iframe
  useEffect(() => {
    const handleIframeMessage = event => {
      if (event.data === 'anonymousNeedsLogin') {
        // Prompt user to log in
        // Logic to display login dialog should be implemented here
      }

      if (event.data ==== 'uikitRendered') {
        // Logic to handle after uikit has been rendered
      }

      if (event.data ==== 'explorePageLoaded') {
        // Logic to handle after Explore page has been loaded
      }


      if (event.data ==== 'parentNeedsScrollToTop') {
        // `parentNeedsScrollToTop` will be posted from iFrame when the Nickname dialog is opened
        window.scrollTo(0,0);
      }

    };

    // Listen for messages from the iframe
    window.addEventListener('message', handleIframeMessage);

    // Cleanup the event listener on component unmount
    return () => {
      window.removeEventListener('message', handleIframeMessage);
    };
  }, []);

  // Function to handle setting a new `userId` after the user logs in
  const handleSetUserId = newValue => {
    setUserId(newValue);
  };

  return (
    <div>
      // Assume that this is Ulta login prompt
      <input
        type="text"
        id="name"
        placeholder="Enter new User ID"
        onChange={(e) => handleSetUserId(e.target.value)}
      />
      <button onClick={() => handleSetUserId(document.getElementById('name').value)}>
        Set User ID
      </button>
      <iframe
        style={{ width: '100%', height: '80vh' }}
        title="Communities"
        src={`https://urlToUikit.com?userId=${userId}`}
      />
    </div>
  );
}

Anonymous User Flow

Authenticated Users

  1. Access and Authentication:
  • Users enter Ulta Web and navigate to the community tab.
  • Ulta Web contacts Ulta Authentication Service to verify if the user is logged in.
  1. Token Handling:
  • If authenticated, Ulta Web requests an Amity authentication token from Ulta Server.
  • Ulta Server forwards this request to Amity Server, which returns the token.
  1. UIKit Initialization:
  • Ulta Web instructs Ulta Iframe to initialize Amity UIKit using the authenticated Ulta User ID and token.
  • Amity UIKit is then presented to the user, allowing continued interaction under their Ulta ID.

Anonymous Users

  1. Access as Anonymous:
  • If not logged in, the same token request is made to handle session management.
  • Amity UIKit is initialized as ‘public’, allowing limited interaction.
  1. Exceeded Interaction Limit:
  • If anonymous interactions exceed limits, Amity UIKit informs Ulta Iframe, triggering a notification to Ulta Web.
  • A login dialogue is presented to the user.
  1. Login Decision:
  • If the user logs in, Ulta Authentication Service authenticates the user, and the token process repeats to reinitialize Amity UIKit with the Ulta User ID.

Diagram Sept 4 from Mermaid Chart (1)