@sawport/react-sdk 0.1.0-alpha.51 → 0.1.0-alpha.53

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,9 +1,7 @@
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>
@@ -11,19 +9,26 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
11
9
  ...
12
10
  ```
13
11
 
14
- ### Put the widget into a container id of `sawport-widget`
12
+ ### Create a div with id of `sawport-widget` that will contain the widget.
15
13
  ```html
16
14
  ...
17
15
  <div id="sawport-widget"></div>
18
16
  </body>
19
17
  ```
20
18
 
21
- ### Pull in ther sawport SDK into your website
22
- > Mount the sawport widget when document is fully loaded and with default configurations.
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.
23
22
  ```html
24
23
  ...
25
24
  <script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
25
+ </body>
26
+ ```
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
+ ...
27
32
  <script>function docReady(fn) {
28
33
  ['complete', 'interactive'].includes(document.readyState)
29
34
  ? setTimeout(fn, 1)
@@ -34,47 +39,174 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
34
39
  baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
35
40
  apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
36
41
  projectId: XXXXXXXXXXXXXX,
37
- user: {email: 'example@emai.lcom', phone: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
42
+ user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
38
43
  }, 'sawport-widget'))
39
44
  </script>
40
45
  </body>
41
46
  ```
42
47
 
43
48
  ### Setting up enterprise credentials
44
- > Call the Sawport function `setSawportConfig` to set the enterprise credential.
49
+ Call the Sawport function `setSawportConfig` to set the enterprise credential.
45
50
  ```js
46
51
  docReady(() => sawportSDK.setSawportConfig({
47
52
  baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
48
53
  apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
49
54
  projectId: XXXXXXXXXXXXXX,
50
- user: {email: 'example@emai.lcom', phone: '080XXXXXXXXX', name: 'Firstname Lastname'}
55
+ user: {email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}
51
56
  })
52
- })
57
+ )
53
58
  ```
54
59
 
55
- ## Available Scripts
56
-
57
- In the project directory, you can run:
58
-
59
- ### `yarn start`
60
-
61
- Runs the app in the development mode.\
62
- Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
60
+ # Usage In REACTJS
61
+ ## Install the SDK
62
+ ```bash
63
+ yarn add @sawport/react-sdk
64
+ ```
63
65
 
64
- The page will reload if you make edits.\
65
- You will also see any lint errors in the console.
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';
66
85
 
67
- ### `yarn test`
86
+ <Widget user={{email: 'example@emai.lcom', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}} />
87
+ ```
68
88
 
69
- Launches the test runner in the interactive watch mode.\
70
- See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
89
+ ## Updating SDK Configuration
90
+ ```js
91
+ import { setSawportConfig } from '@sawport/react-sdk';
71
92
 
72
- ### `yarn build`
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
98
+ })
99
+ ```
73
100
 
74
- Builds the app for production to the `build` folder.\
75
- It correctly bundles React in production mode and optimizes the build for the best performance.
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
+ ```
76
124
 
77
- The build is minified and the filenames include the hashes.\
78
- Your app is ready to be deployed!
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'
131
+
132
+ console.log({sawportSDK});
133
+
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
+ ```
79
154
 
80
- See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
155
+ # API References `sawportSDK`
156
+
157
+ ## Widget
158
+ Sawport React SDK widget component
159
+ ### Type
160
+ - React Component
161
+ ### Props
162
+ - [user](#user)
163
+ - [projectId](#projectid)
164
+
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)
173
+
174
+ ## setSawportConfig
175
+ ### Type
176
+ - Function(config)
177
+ ### Props
178
+ - [config](#sawportconfig)
179
+
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`
190
+
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)
197
+
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)