-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from IntersectMBO/feature/usersnap-integration
feature: Usersnap integration to Feedback button
- Loading branch information
Showing
7 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use client"; | ||
import React from "react"; | ||
|
||
import { useUsersnapApi } from "../../context/usersnap"; | ||
import { Button } from "../atoms"; | ||
|
||
/** | ||
* The FeedbackButton component renders a button that, when clicked, | ||
* forces the Usersnap widget to open, allowing users to provide feedback or report bugs. | ||
* @param param0 title: Button text | ||
* @returns | ||
*/ | ||
export function FeedbackButton({ title }) { | ||
const usersnapApi = useUsersnapApi(); | ||
|
||
/** | ||
* This method ignores all the display rules and opens the widget | ||
* no matter what | ||
*/ | ||
const handleOpenWidgetForce = () => { | ||
usersnapApi | ||
?.show(process.env.NEXT_PUBLIC_USERSNAP_PROJECT_API_KEY) | ||
.then((widgetApi) => widgetApi.open({})); | ||
}; | ||
|
||
return ( | ||
<Button onClick={handleOpenWidgetForce} variant="outlined"> | ||
{title} | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"use client"; | ||
import React, { useEffect, useState, useContext } from "react"; | ||
import { InitOptions, loadSpace, SpaceApi } from "@usersnap/browser"; | ||
|
||
export const UsersnapContext = React.createContext<SpaceApi | null>(null); | ||
|
||
// This context is used to integrate the Usersnap widget, | ||
// Usersnap is a tool for collecting user feedback and bug reports directly from the application | ||
export const UsersnapProvider = ({ | ||
initParams, | ||
children, | ||
}: UsersnapProviderProps) => { | ||
const [usersnapApi, setUsersnapApi] = useState<SpaceApi | null>(null); | ||
|
||
useEffect(() => { | ||
loadSpace(process.env.NEXT_PUBLIC_USERSNAP_GLOBAL_API_KEY).then( | ||
(api: SpaceApi) => { | ||
api.init(initParams); | ||
setUsersnapApi(api); | ||
} | ||
); | ||
}, [initParams]); | ||
|
||
return ( | ||
<UsersnapContext.Provider value={usersnapApi}> | ||
{children} | ||
</UsersnapContext.Provider> | ||
); | ||
}; | ||
|
||
interface UsersnapProviderProps { | ||
initParams?: InitOptions; | ||
children: React.ReactNode; | ||
} | ||
|
||
export function useUsersnapApi() { | ||
return useContext(UsersnapContext); | ||
} |