0.1.0-alpha.74 • Published 9 days ago

@sawport/react-sdk v0.1.0-alpha.74

Weekly downloads
-
License
-
Repository
-
Last release
9 days ago

Getting Started With Sawport Widget

Web Usage

Pull the Sawport Widget CSS from your HTML head into your web page.

<html>
  <head>
    <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
  ...

Create a div with id of sawport-widget that will contain the widget.

...
  <div id="sawport-widget"></div>
</body>

Pull in the sawport SDK into your website

After pulling the sawport SDK Global variable sawportSDK will be exposed to your webpage which you can access its method and properties.

...
  <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
</body>

Mount the sawport widget when document is fully loaded and with default configurations.

Use the global sawportSDK.mountWidget to mount the widget anytime with the configuration it accepts

...
  <script>function docReady(fn) {
      ['complete', 'interactive'].includes(document.readyState)
        ? setTimeout(fn, 1)
        : document.addEventListener('DOMContentLoaded', fn);
    }

    docReady(() => sawportSDK.mountWidget({
    	baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
	apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
	projectId: XXXXXXXXXXXXXX,
	user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
    }, 'sawport-widget'))
  </script>
</body>

Setting up enterprise credentials

Call the Sawport function setSawportConfig to set the enterprise credential.

docReady(() => sawportSDK.setSawportConfig({
	baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
	apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
	projectId: XXXXXXXXXXXXXX,
	user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}
  })
 )

Usage In REACTJS

Install the SDK

yarn add @sawport/react-sdk

Configuring The Widget

You may configure the widget by passing object of config to the SawportContext.Provider.

import { SawportContext } from '@sawport/react-sdk';

<SawportContext.Provider
      value={{
        config: {
          baseURL: 'https://{DASHBOARD_HOST_DOMAIN}', // required
          apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/', // required
          projectId: 'XXXXXXXXXXXXXX' // required
        }
      }}>
      <YourApp />
</SawportContext.Provider>

Using The Widget

import { Widget } from '@sawport/react-sdk';

<Widget user={{email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}} />

Updating SDK Configuration

import { setSawportConfig } from '@sawport/react-sdk';

setSawportConfig({
	user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'},
	baseURL: 'https://{DASHBOARD_HOST_DOMAIN}', // required
        apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/', // required
        projectId: 'XXXXXXXXXXXXXX' // required
})

Usage In VUEJS

Pull in Sawport SDK from the project's index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vite App</title>
    <!-- ADD SAWPORT SDK CSS	   -->
    <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
  </head>
  <body>
    <div id="app"></div>
    <!-- CREATE A DIV TO HOLD SAWPORT WIDGET	   -->
    <div id="sawport-widget"></div>
    <!-- ADD SAWPORT SDK JS	   -->
    <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

Mounting Sawport SDK From Your Vuejs APP

You need to mount the widget from your vuejs app any time and any where. By pulling the Sawport SDK, sawportSDK variable would be exposed to your vuejs app globally.

<script setup>
import HelloWorld from './components/HelloWorld.vue'

console.log({sawportSDK});

const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/'

// sawportSDK is globally accessible
// Call Once
sawportSDK.mountWidget({
  baseURL: dashboardUrl,
	apiURL: `${dashboardUrl}/api/v1/`,
	projectId: 'XXXXXXXXXXXXXX',
	user: {email: 'example@email.com', mobile: '2348123456789', name: 'Firstname Lastname'}, // optional
}, 'sawport-widget')
</script>

<template>
    <div class="wrapper">
      <!-- YOU MAY ADD DIV WITH ID ANYWHERE TO HOLD THE SAWPORT WIDGET -->
      <!-- <div id="sawport-widget"></div> -->
      <HelloWorld msg="You did it!" />
    </div>
</template>

API References sawportSDK

Widget

Sawport React SDK widget component

Type

  • React Component

Props

SawportContext

Sawport Context for global configuration of the widget

Type

  • React Context Component

Props

value

setSawportConfig

Type

  • Function(config)

Props

sawportConfig

The Sawport configuration object

Type

  • Object

user

  • name: customer name to populate in the widget
  • mobile: customer phone number to populate in the widget
  • email: customer email to populate in the widget

projectId

The Enterprise's ID from the Dashboard

useSawportConfig

The React hook to get access to the Sawport configuration object

Type

  • React Hook - Function()

Return

useSawportContext

React hook for Sawport Context for global configuration of the widget

Type

  • React Context Hook - Function()

Return

mountWidget

Method to mount the Sawport SDK widget in HTML element with id of sawport-widget

Type

  • Function(config)

Props

0.1.0-alpha.74

9 days ago

0.1.0-alpha.72

1 month ago

0.1.0-alpha.73

1 month ago

0.1.0-alpha.71

2 months ago

0.1.0-alpha.70

4 months ago

0.1.0-alpha.69

4 months ago

0.1.0-alpha.59

10 months ago

0.1.0-alpha.61

10 months ago

0.1.0-alpha.60

10 months ago

0.1.0-alpha.63

10 months ago

0.1.0-alpha.62

10 months ago

0.1.0-alpha.65

10 months ago

0.1.0-alpha.64

10 months ago

0.1.0-alpha.67

9 months ago

0.1.0-alpha.66

10 months ago

0.1.0-alpha.68

6 months ago

0.1.0-alpha.52

12 months ago

0.1.0-alpha.51

12 months ago

0.1.0-alpha.54

12 months ago

0.1.0-alpha.53

12 months ago

0.1.0-alpha.56

11 months ago

0.1.0-alpha.55

11 months ago

0.1.0-alpha.58

11 months ago

0.1.0-alpha.57

11 months ago

0.1.0-alpha.57.1

11 months ago

0.1.0-alpha.56.1

11 months ago

0.1.0-alpha.56.2

11 months ago

0.1.0-alpha.50

1 year ago

0.1.0-alpha.47

1 year ago

0.1.0-alpha.49

1 year ago

0.1.0-alpha.48

1 year ago

0.1.0-alpha.45

1 year ago

0.1.0-alpha.46

1 year ago

0.1.0-alpha.41

1 year ago

0.1.0-alpha.43

1 year ago

0.1.0-alpha.42

1 year ago

0.1.0-alpha.44

1 year ago

0.1.0-alpha.30

2 years ago

0.1.0-alpha.32

2 years ago

0.1.0-alpha.31

2 years ago

0.1.0-alpha.34

2 years ago

0.1.0-alpha.33

2 years ago

0.1.0-alpha.36

2 years ago

0.1.0-alpha.35

2 years ago

0.1.0-alpha.38

1 year ago

0.1.0-alpha.18

2 years ago

0.1.0-alpha.39

1 year ago

0.1.0-alpha.19

2 years ago

0.1.0-alpha.40

1 year ago

0.1.0-alpha.21

2 years ago

0.1.0-alpha.20

2 years ago

0.1.0-alpha.23

2 years ago

0.1.0-alpha.22

2 years ago

0.1.0-alpha.25

2 years ago

0.1.0-alpha.24

2 years ago

0.1.0-alpha.27

2 years ago

0.1.0-alpha.26

2 years ago

0.1.0-alpha.29

2 years ago

0.1.0-alpha.28

2 years ago

0.1.0-alpha.17

2 years ago

0.1.0-alpha.16

2 years ago

0.1.0-alpha.15

2 years ago

0.1.0-alpha.14

2 years ago

0.1.0-alpha.13

2 years ago

0.1.0-alpha.12

2 years ago

0.1.0-alpha.11

2 years ago

0.1.0-alpha.10

2 years ago

0.1.0-alpha.9

2 years ago

0.1.0-alpha.8

2 years ago

0.1.0-alpha.7

2 years ago

0.1.0-alpha.6

2 years ago

0.1.0-alpha.5

2 years ago

0.1.0-alpha.4

2 years ago

0.1.0-alpha.3

2 years ago

0.1.0-alpha.2

2 years ago

0.1.0-alpha.1

2 years ago

0.1.0-alpha.0

2 years ago