report-bug
v1.0.13
Published
```bash npm install --save report-bug ``` ## Import the report-bug Library.
Downloads
8
Maintainers
Readme
report-bug
Installation
npm install --save report-bug
Import the report-bug Library.
import BugReport from 'report-bug';
Usage
<BugReport user = {current_username} app_id = {current_appname} color = {bug_icon_color} reportLink={destination_link}/>
Props
user : string (current logged in user) app_id : string (client app name) color : string (bug icon color) reportLink : Link (API Endpoint)
Working
- Users can report a bug anywhere in our app by clicking on the Bug Icon. As soon as the user clicks the bug icon , captureScreenhot() method is called and a screenshot of the current screen is taken by using the html2canvas method. This method takes a DOM element as input and returns it's image i.e. body in our case. The image is then converted to base64 encoded URL using image_name.toDataURL() method and stored in the this.state.
captureScreenShot = async () => {
const canvas = await html2canvas(document.querySelector("body"));
const base64 = canvas.toDataURL("image/jpeg");
this.setState({ screenshot: base64, modal: true });
};
- The page_id of the page on which the bug icon is clicked is fetched by using window.location.pathname which returns the filename of the current page. The description given by the user in text area is also stored in this.state .
this.state = {
page_id : window.location.pathname.slice(1)
}
- when user clicks the submit submitHandler() is called which makes a post request to adminbugreport Api and Page id , user id, description, app_id and base64 encoded screenshot are sent to the backend and stored in customer_error_report table. If successful the Api returns a BugID which is displayed to the user on screen.
const body = { page_id, user_id, desc,app_id, screenshot };
const res = await Axios.post(Endpoints.adminbugreport, body);
const bugId = res.data.body
MIT © [email protected]