Skip to content

Commit

Permalink
refactor: Update Zendesk integration in react-thirdparty package
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Jul 2, 2024
1 parent 0352cbc commit 6365d10
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 23 deletions.
5 changes: 4 additions & 1 deletion packages/react-thirdparty/recaptcha/Context.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext } from "react";
import { createContext, useContext } from "react";
import { ReCaptchaExecuteOptions } from "./Provider";

export interface GoogleReCaptchaConsumerProps {
Expand All @@ -12,3 +12,6 @@ const GoogleReCaptchaContext = createContext<GoogleReCaptchaConsumerProps>({
const { Consumer: GoogleReCaptchaConsumer } = GoogleReCaptchaContext;

export { GoogleReCaptchaConsumer, GoogleReCaptchaContext };

export const useGoogleReCaptchaContext = () =>
useContext(GoogleReCaptchaContext);
1 change: 0 additions & 1 deletion packages/react-thirdparty/recaptcha/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from "./useGoogleReCaptcha";
export * from "./useGoogleReCaptchaContext";
export * from "./GoogleReCaptcha";
export * from "./Context";
export * from "./Provider";
2 changes: 1 addition & 1 deletion packages/react-thirdparty/recaptcha/useGoogleReCaptcha.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect } from "react";
import { useGoogleReCaptchaContext } from "./useGoogleReCaptchaContext";
import { useGoogleReCaptchaContext } from "./Context";

export interface GoogleReCaptchaConfig {
onVerify: (token: string) => void | Promise<void>;
Expand Down

This file was deleted.

14 changes: 3 additions & 11 deletions packages/react-thirdparty/zendesk/Context.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { createContext, useContext } from "react";

export interface ZendeskContextProps {
executeZendesk: ZendeskWidget;
executeZendesk?: ZendeskWidget;
}

export const ZendeskContext = createContext<ZendeskContextProps | undefined>(
undefined
);
export const ZendeskContext = createContext<ZendeskContextProps>({});

/**
* Custom hook to use the Zendesk context.
* @throws If used outside of a ZendeskProvider.
* @returns The Zendesk context value.
*/
export const useZendeskContext = (): ZendeskContextProps => {
const context = useContext(ZendeskContext);
if (!context) {
throw new Error("useZendeskContext must be used within a ZendeskProvider");
}
return context;
};
export const useZendeskContext = () => useContext(ZendeskContext);
5 changes: 5 additions & 0 deletions packages/react-thirdparty/zendesk/Zendesk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const Zendesk: React.FC = () => {
const { executeZendesk } = useZendesk();

useEffect(() => {
if (!executeZendesk) {
console.warn("Zendesk client is not available");
return;
}

// Example usage of executeZendesk when the component mounts
executeZendesk("webWidget", "open");

Expand Down
5 changes: 1 addition & 4 deletions packages/react-thirdparty/zendesk/useZendesk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ import { useZendeskContext } from "./Context";
* Custom hook to access Zendesk client through context.
* @returns The Zendesk context value.
*/
export const useZendesk = () => {
const context = useZendeskContext();
return context;
};
export const useZendesk = () => useZendeskContext();

0 comments on commit 6365d10

Please sign in to comment.