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

sortin-brand-pkg

v1.0.7

Published

Sortin Rewards App for sustainable brands

Downloads

21

Readme

About

Sortin Rewards Package v1.0.7

Installation

Use NPM to install the package in React Project npm install sortin-brand-pkg

Widgets

  • Sortin Banner: <SortinBanner/> tag is used for global banner placed on the bottom left side or the footer element of all pages. The tag is to be implemented at the root component of the react project (main.jsx/ main.tsx) Props: type="banner" for footer element on black background with 100% page width or type="fab" for floating action button on left bottom corner of all pages size="sm" || "md" || "lg" || "xl" (Optional) for different Fab banner sizes on screen size below 480px.
    <SortinBanner type="fab" size="md"/>
    Example:
    //main.jsx
        ReactDOM.createRoot(document.getElementById("root")).render(
        <Provider store={store}>
            <App />
            <SortinBanner type="fab" />
        </Provider>
    );
    For padding issues after placing <SortinBanner/>, add a div with style={{paddingBottom:'50px'}} in Main.jsx or any other css value for bottom padding and wrap <App/> and <SortinBanner/> under it.
  • Sortin Product Widget: <SortinProductWidget/> tag is used for a single product on product description page to display emission data. Props: id:string where id is the productId.

    <SortinProductWidget id={productId}/>

    Example:

    No <div> tag or className is required. (This is just for reference)

    <div className="other-product-info flex flex-col gap-x-2">
        <SortinProductWidget id={productData?.id}/>
        <div className="font-bold text-white p-5 mt-2">
            Brand: {productData?.brandName}
        </div>
    </div>
  • Sortin Cart Widget: <SortinCartWidget/> tag is used for the cart page to display total emission information for the entire cart. Props: cartItems is array of products added to cart with Id, quantity, and price as the necessary props.

    <SortinCartWidget cartItems={cartItems}/>

    Example Format Of cartItems :

    cartItems = [{
        "id": 123,
        "quantity": 2,
        "price": 100
    },
     {
        "id": 124,
        "quantity": 3,
        "price": 150
    }]

    Example Code: No <div> tag or className is required. This is just for reference.

    //cart.jsx
      
    <div className='lg:col-span-4 lg:pl-4'>
          <SortinCartWidget cartItems={cartItems}/>
    </div>
  • Sortin Cart Item Widget: <SortinCartItemWidget id={id} qty={quantity}/> is used to display emission data and sortin coins to be earned by user for every product in cart. This is to be displayed under the cart lines of individual products added by the user. Props: id={product_id}, qty={product_quantity}

    <div className="font-medium sm:ml-auto">
        <SortinCartItemWidget id={product_id} qty={product_qty}/>
    </div>

Discount Code

  • The discount code generated via sortin is dispatched through an event "SORTIN_DISCOUNT_GENERATED". Subscribe to this event and apply the discount code using store's predefined method.
    window.addEventListener("SORTIN_DISCOUNT_GENERATED", (event: Event)=>{
        const discountCode= (event as any).data; // Generated Discount Code
        // Implement Discount Code Apply Function
    })
  • Delete discount code from Local Storage when order is created:
    localStorage.removeItem("sortinDiscountCode")

Create Order API

Send an API request to sortin in order to reward users after order creation, with the following configuration:

  • Embed sortin_user_id in order metadata to be sent to your backend after fetching it from localStorage of your website. "sortinUserData" is the local storage key.
    const sortinUser = JSON.parse(localStorage.get("sortinUserData"))
    const sortinUserId = sortinUser.userId
  • Add discount code used by the user in order metadata. Discount code via sortin will be generated and pasted by user before checkout or can be fetched by the host website from localStorage and pasted directly in the promocode/discount input box.
  • API Payload Schema: (order_metadata)
    type Customer = {
        firstName: string;
        lastName: string;
        email?: string; 
        phone: string; 
    };
    
    type Address = {
        addressLine: string;
        city: string;
        state: string;
        pincode: string;
    }
    
    type Product = {
        productId: string;
        quantity: number;
        price: string;
    };
    
    type Order = {
        userId: string | null; //sortinUserId
        orderId: string; //unique value to be supplied with each order
        productQty: number;
        subtotal: string;
        total: string;
        customer: Customer;
        address: {
            billingAddress?: Address | null;
            shippingAddress: Address;
        };
        products: Product[];
        discount: string | null; 
    };
    Example Payload (order_metadata):
    {
        "orderId": "57sad09fg6h470",
        "productQty": 1,
        "subtotal": "2579.95",
        "total": "3044.34",
        "userId":"717d6b80-dc9f-4b80-bc37-4b723ab84284",
        "customer": {
            "firstName": "sid",
            "lastName": "saxena",
            "email": "[email protected]",
            "phone": "23950207530"
        },
        "address": {
            "billingAddress": {
                "addressLine": "Caunaut Place Hanuman Road Area Connaught Place 231/213",
                "city": "New Delhi",
                "state": "DL",
                "pincode": "110001"
            },
            "shippingAddress": {
                "addressLine": "Caunaut Place Hanuman Road Area Connaught Place 231/213",
                "city": "New Delhi",
                "state": "DL",
                "pincode": "110001"
            }
        },
        "products": [
            {
                "productId": "70dsf6368s454",
                "quantity": 1,
                "price": "2579.95"
            }
        ],
        "discount": "sortin_50_975ac4"
    }
  • API call: endpoint: https://qektcoqosyapxflftmss.supabase.co/functions/v1/custom-brand-app/order/create method:POST headers: x-sortin-key An access key provided by sortin, to be stored in host page environment and supplied with each create order api call body: order_metadata
    const response = await fetch( 'https://qektcoqosyapxflftmss.supabase.co/functions/v1/custom-brand-app/order/create', {
        method: "POST",
        headers:{
            "Content-Type": "application/json",
            "x-sortin-key": process.env.x-sortin-key 
        },
        body: JSON.stringify(order_metadata)
    })