<html>
<head>
<link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
...
...
<div id="sawport-widget"></div>
</body>
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>
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>
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'}
})
)
yarn add @sawport/react-sdk
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>
import { Widget } from '@sawport/react-sdk';
<Widget user={{email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}} />
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
})
<!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>
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>
Sawport React SDK widget component
- React Component
Sawport Context for global configuration of the widget
- React Context Component
- Function(config)
The Sawport configuration object
- Object
- 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
The Enterprise's ID from the Dashboard
The React hook to get access to the Sawport configuration object
- React Hook - Function()
React hook for Sawport Context for global configuration of the widget
- React Context Hook - Function()
Method to mount the Sawport SDK widget in HTML element with id of sawport-widget
- Function(config)