1.0.1 - Added useTuitioClient default options
parent
627d1af5ad
commit
67035fbc7e
|
@ -35,3 +35,4 @@ All tests in the package can be executed by running: `npm test`.
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
1.0.0 - Package initialization
|
1.0.0 - Package initialization
|
||||||
|
1.0.1 - Added useTuitioClient default options
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@flare/tuitio-client-react",
|
"name": "@flare/tuitio-client-react",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@flare/tuitio-client-react",
|
"name": "@flare/tuitio-client-react",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@flare/tuitio-client": "^1.0.4"
|
"@flare/tuitio-client": "^1.0.4"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@flare/tuitio-client-react",
|
"name": "@flare/tuitio-client-react",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "Tuitio client react is an npm package written in typescript that facilitates the integration of a react application with Tuitio.",
|
"description": "Tuitio client react is an npm package written in typescript that facilitates the integration of a react application with Tuitio.",
|
||||||
"main": "./dist/cjs/index.js",
|
"main": "./dist/cjs/index.js",
|
||||||
"module": "./dist/esm/index.js",
|
"module": "./dist/esm/index.js",
|
||||||
|
|
|
@ -4,12 +4,18 @@ import { TuitioClient, invalidate } from "@flare/tuitio-client";
|
||||||
import type { TuitioAuthenticationResult } from "@flare/tuitio-client";
|
import type { TuitioAuthenticationResult } from "@flare/tuitio-client";
|
||||||
|
|
||||||
export type TuitioClientHookOptions = {
|
export type TuitioClientHookOptions = {
|
||||||
onLoginSuccess: (result: TuitioAuthenticationResult, userName: string) => void;
|
onLoginSuccess?: (result: TuitioAuthenticationResult, userName: string) => void;
|
||||||
onLoginFailed: (result: TuitioAuthenticationResult, userName: string) => void;
|
onLoginFailed?: (result: TuitioAuthenticationResult, userName: string) => void;
|
||||||
onLoginError: (error: any) => void;
|
onLoginError?: (error: any) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useTuitioClient = (options: TuitioClientHookOptions) => {
|
const defaultOptions: TuitioClientHookOptions = {
|
||||||
|
onLoginSuccess: undefined,
|
||||||
|
onLoginFailed: undefined,
|
||||||
|
onLoginError: undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
const useTuitioClient = (options: TuitioClientHookOptions = defaultOptions) => {
|
||||||
const state = useContext(TuitioContext);
|
const state = useContext(TuitioContext);
|
||||||
const dispatchActions = useContext(TuitioDispatchContext);
|
const dispatchActions = useContext(TuitioDispatchContext);
|
||||||
|
|
||||||
|
|
|
@ -102,13 +102,7 @@ describe("useTuitioClient", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call invalidate when logout is called", () => {
|
it("should call invalidate when logout is called", () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() => useTuitioClient());
|
||||||
useTuitioClient({
|
|
||||||
onLoginSuccess: jest.fn(),
|
|
||||||
onLoginFailed: jest.fn(),
|
|
||||||
onLoginError: jest.fn()
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
result.current.logout();
|
result.current.logout();
|
||||||
|
|
Loading…
Reference in New Issue