@sawport/react-sdk 0.1.0-alpha.7 → 0.1.0-alpha.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,57 +1,212 @@
1
- # Getting Started Sawport Widget
1
+ # Getting Started With Sawport Widget
2
2
 
3
- This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4
-
5
- ## Usage
6
- ### Pull the javascript and css into your webpage.
3
+ ## Web Usage
4
+ ### Pull the Sawport Widget CSS from your HTML head into your web page.
7
5
  ```html
8
6
  <html>
9
7
  <head>
10
- <link href="https://{WIDGET_HOST_DOMAIN}/widget/index.css" rel="stylesheet" />
11
- <script src="https://{WIDGET_HOST_DOMAIN}/widget/index.js"></script>
8
+ <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
12
9
  ...
13
10
  ```
14
- ### Put the widget into a container class of `sawport-widget`
11
+
12
+ ### Create a div with id of `sawport-widget` that will contain the widget.
13
+ ```html
14
+ ...
15
+ <div id="sawport-widget"></div>
16
+ </body>
17
+ ```
18
+
19
+ ### Pull in the sawport SDK into your website
20
+ After pulling the sawport SDK
21
+ Global variable `sawportSDK` will be exposed to your webpage which you can access its method and properties.
15
22
  ```html
16
23
  ...
17
- <div class='sawport-widget' />
24
+ <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
25
+ </body>
26
+ ```
27
+
28
+ ### Mount the sawport widget when document is fully loaded and with default configurations.
29
+ Use the global `sawportSDK.mountWidget` to mount the widget anytime with the configuration it accepts
30
+ ```html
31
+ ...
32
+ <script>function docReady(fn) {
33
+ ['complete', 'interactive'].includes(document.readyState)
34
+ ? setTimeout(fn, 1)
35
+ : document.addEventListener('DOMContentLoaded', fn);
36
+ }
37
+
38
+ docReady(() => sawportSDK.mountWidget({
39
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
40
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
41
+ projectId: XXXXXXXXXXXXXX,
42
+ user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
43
+ }, 'sawport-widget'))
44
+ </script>
18
45
  </body>
19
46
  ```
20
47
 
21
48
  ### Setting up enterprise credentials
22
- call the gloabl function `setSawportConfig` to set the enterprise credential.
49
+ Call the Sawport function `setSawportConfig` to set the enterprise credential.
23
50
  ```js
24
- document.ready(function (){
25
- window.setSawportConfig({
26
- projectId: XXXXXXXXXXXXXX,
27
- user: {email: 'example@emai.lcom'}
51
+ docReady(() => sawportSDK.setSawportConfig({
52
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
53
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
54
+ projectId: XXXXXXXXXXXXXX,
55
+ user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}
28
56
  })
57
+ )
58
+ ```
59
+
60
+ # Usage In REACTJS
61
+ ## Install the SDK
62
+ ```bash
63
+ yarn add @sawport/react-sdk
64
+ ```
65
+
66
+ ## Configuring The Widget
67
+ You may configure the widget by passing object of config to the `SawportContext.Provider`.
68
+ ```jsx
69
+ import { SawportContext } from '@sawport/react-sdk';
70
+
71
+ <SawportContext.Provider
72
+ value={{
73
+ config: {
74
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}', // required
75
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/', // required
76
+ projectId: 'XXXXXXXXXXXXXX' // required
77
+ }
78
+ }}>
79
+ <YourApp />
80
+ </SawportContext.Provider>
81
+ ```
82
+ ## Using The Widget
83
+ ```jsx
84
+ import { Widget } from '@sawport/react-sdk';
85
+
86
+ <Widget user={{email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}} />
87
+ ```
88
+
89
+ ## Updating SDK Configuration
90
+ ```js
91
+ import { setSawportConfig } from '@sawport/react-sdk';
92
+
93
+ setSawportConfig({
94
+ user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'},
95
+ baseURL: 'https://{DASHBOARD_HOST_DOMAIN}', // required
96
+ apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/', // required
97
+ projectId: 'XXXXXXXXXXXXXX' // required
29
98
  })
30
99
  ```
31
100
 
32
- ## Available Scripts
101
+ # Usage In VUEJS
102
+ ## Pull in Sawport SDK from the project's index.html
103
+ ```html
104
+ <!DOCTYPE html>
105
+ <html lang="en">
106
+ <head>
107
+ <meta charset="UTF-8">
108
+ <link rel="icon" href="/favicon.ico">
109
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
110
+ <title>Vite App</title>
111
+ <!-- ADD SAWPORT SDK CSS -->
112
+ <link href="https://unpkg.com/@sawport/react-sdk/dist/style.css" rel="stylesheet" />
113
+ </head>
114
+ <body>
115
+ <div id="app"></div>
116
+ <!-- CREATE A DIV TO HOLD SAWPORT WIDGET -->
117
+ <div id="sawport-widget"></div>
118
+ <!-- ADD SAWPORT SDK JS -->
119
+ <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
120
+ <script type="module" src="/src/main.js"></script>
121
+ </body>
122
+ </html>
123
+ ```
33
124
 
34
- In the project directory, you can run:
125
+ ## Mounting Sawport SDK From Your Vuejs APP
126
+ You need to mount the widget from your vuejs app any time and any where.
127
+ By pulling the Sawport SDK, `sawportSDK` variable would be exposed to your vuejs app globally.
128
+ ```vue
129
+ <script setup>
130
+ import HelloWorld from './components/HelloWorld.vue'
35
131
 
36
- ### `yarn start`
132
+ console.log({sawportSDK});
37
133
 
38
- Runs the app in the development mode.\
39
- Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
134
+ const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/'
135
+
136
+ // sawportSDK is globally accessible
137
+ // Call Once
138
+ sawportSDK.mountWidget({
139
+ baseURL: dashboardUrl,
140
+ apiURL: `${dashboardUrl}/api/v1/`,
141
+ projectId: 'XXXXXXXXXXXXXX',
142
+ user: {email: 'example@email.com', mobile: '2348123456789', name: 'Firstname Lastname'}, // optional
143
+ }, 'sawport-widget')
144
+ </script>
145
+
146
+ <template>
147
+ <div class="wrapper">
148
+ <!-- YOU MAY ADD DIV WITH ID ANYWHERE TO HOLD THE SAWPORT WIDGET -->
149
+ <!-- <div id="sawport-widget"></div> -->
150
+ <HelloWorld msg="You did it!" />
151
+ </div>
152
+ </template>
153
+ ```
40
154
 
41
- The page will reload if you make edits.\
42
- You will also see any lint errors in the console.
155
+ # API References `sawportSDK`
43
156
 
44
- ### `yarn test`
157
+ ## Widget
158
+ Sawport React SDK widget component
159
+ ### Type
160
+ - React Component
161
+ ### Props
162
+ - [user](#user)
163
+ - [projectId](#projectid)
45
164
 
46
- Launches the test runner in the interactive watch mode.\
47
- See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
165
+ ## SawportContext
166
+ Sawport Context for global configuration of the widget
167
+ ### Type
168
+ - React Context Component
169
+ ### Props
170
+ #### value
171
+ - [config](#sawportconfig)
172
+ - [setConfig](#setsawportconfig)
48
173
 
49
- ### `yarn build`
174
+ ## setSawportConfig
175
+ ### Type
176
+ - Function(config)
177
+ ### Props
178
+ - [config](#sawportconfig)
50
179
 
51
- Builds the app for production to the `build` folder.\
52
- It correctly bundles React in production mode and optimizes the build for the best performance.
180
+ ## sawportConfig
181
+ The Sawport configuration object
182
+ ### Type
183
+ - Object
184
+ ### user
185
+ - name: `customer name to populate in the widget`
186
+ - mobile: `customer phone number to populate in the widget`
187
+ - email: `customer email to populate in the widget`
188
+ ### projectId
189
+ `The Enterprise's ID from the Dashboard`
53
190
 
54
- The build is minified and the filenames include the hashes.\
55
- Your app is ready to be deployed!
191
+ ## useSawportConfig
192
+ The React hook to get access to the Sawport configuration object
193
+ ### Type
194
+ - React Hook - Function()
195
+ ### Return
196
+ - [config](#sawportconfig)
56
197
 
57
- See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
198
+ ## useSawportContext
199
+ React hook for Sawport Context for global configuration of the widget
200
+ ### Type
201
+ - React Context Hook - Function()
202
+ ### Return
203
+ - Sawport Context
204
+ - - [config](#sawportconfig)
205
+ - - [setConfig](#setsawportconfig)
206
+
207
+ ## mountWidget
208
+ Method to mount the Sawport SDK widget in HTML element with id of `sawport-widget`
209
+ ### Type
210
+ - Function(config)
211
+ ### Props
212
+ - [config](#sawportconfig)