Skip to content

Commit 6ce61df

Browse files
committed
feat: add setCustomize method
1 parent 22d118f commit 6ce61df

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed

.changeset/tidy-bananas-find.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-use-zendesk": minor
3+
---
4+
5+
add setCustomize method

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Library add some useful fields.
115115
| useSessionAuth | () => void | See details on [Zendesk docs](https://developer.zendesk.com/api-reference/widget-messaging/web/authentication/).
116116
| logoutUser | () => void | Your app may have a logout function that brings users back to a login screen. In this case, revert the messaging Web Widget to a pre-login state
117117
| resetWidget | () => void | This method clears all widget local state, including user data, conversations, and connections.
118+
| setCustomize | (theme: Partial<ZendeskCustomizationTheme>) => void | Dynamically updates the Web Widget Messengers color theme so it aligns with your brand or site theme.
118119
| isOpen | boolean | this flag indicates if chat is visible or hidden. Derivated from from `onOpen` and `onCLose`
119120
| unreadMessages | number / undefined | this flag indicates number of unread messages . Derivated from from `onUnreadMessages`. Before internal callback this flag is `undefined` |
120121

apps/docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
## [TBD]
1+
## See [README.md](https://github.com/multivoltage/react-use-zendesk/blob/main/README.md)

apps/docs/app/components/ExampleList.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,29 @@ export const ExampleList: React.FC = () => {
260260
resetWidget();
261261
},
262262
},
263+
{
264+
id: "setCustomize",
265+
title: "Set Customize",
266+
description: (
267+
<div>
268+
Dynamically updates the Web Widget Messenger’s color theme so it aligns with your brand or site theme.{" "}
269+
<a
270+
href="https://developer.zendesk.com/api-reference/widget-messaging/web/core/#set-customize"
271+
target="_blank"
272+
>
273+
Set Customize
274+
</a>
275+
276+
</div>
277+
),
278+
buttonText: "customize",
279+
onClick({ setCustomize }) {
280+
setCustomize({
281+
primary: "#DB5F46",
282+
background: "#518e37ff"
283+
});
284+
},
285+
},
263286
{
264287
id: "useSessionAuth",
265288
title: "useSessionAuth",

packages/react-use-zendesk/src/provider.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
LoginFailedError,
66
ZendeskContextValues,
77
ZendeskConversationField,
8+
ZendeskCustomizationTheme,
89
ZendeskProviderProps,
910
} from "./types";
1011
import { PropsWithChildren } from "react";
@@ -145,6 +146,12 @@ export const ZendeskProvider: React.FC<
145146
});
146147
}, []);
147148

149+
const setCustomize = React.useCallback((theme: Partial<ZendeskCustomizationTheme>) => {
150+
ZendeskApi("messenger:set", "customization", {
151+
theme
152+
});
153+
}, []);
154+
148155
const useSessionAuth = React.useCallback(() => {
149156
ZendeskApi("messenger", "useSessionAuth");
150157
}, []);
@@ -162,6 +169,7 @@ export const ZendeskProvider: React.FC<
162169
loginUser,
163170
logoutUser,
164171
resetWidget,
172+
setCustomize,
165173
useSessionAuth,
166174
isOpen,
167175
unreadMessages,

packages/react-use-zendesk/src/types.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ export type LoginFailedError = {
1717
type: string;
1818
};
1919

20+
export type ZendeskCustomizationTheme = {
21+
primary: string;
22+
onPrimary: string;
23+
message: string;
24+
onMessage: string;
25+
action: string;
26+
onAction: string;
27+
businessMessage: string;
28+
onBusinessMessage: string;
29+
background: string;
30+
onBackground: string;
31+
error: string;
32+
onError: string;
33+
notify: string;
34+
onNotify: string
35+
onSecondaryAction: string;
36+
}
37+
2038
export type ZendeskContextValues = {
2139
show: () => void;
2240
hide: () => void;
@@ -35,6 +53,7 @@ export type ZendeskContextValues = {
3553
) => void;
3654
logoutUser: () => void;
3755
resetWidget: () => void;
56+
setCustomize: (theme: Partial<ZendeskCustomizationTheme>) => void;
3857
useSessionAuth: () => void;
3958
isOpen: boolean;
4059
unreadMessages: number | undefined;
@@ -54,4 +73,5 @@ export type ZendeskMethod =
5473
| "loginUser"
5574
| "logoutUser"
5675
| "resetWidget"
57-
| "useSessionAuth";
76+
| "customization"
77+
| "useSessionAuth"

0 commit comments

Comments
 (0)