diff options
author | Sebastian <sebasjm@gmail.com> | 2023-09-04 14:17:55 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-09-04 14:17:55 -0300 |
commit | e1d86816a7c07cb8ca2d54676d5cdbbe513f2ba7 (patch) | |
tree | d4ed5506ab3550a7e9b1a082d7ffeddf9f3c4954 /packages/merchant-backoffice-ui/src/hooks/index.ts | |
parent | ff20c3e25e076c24f7cb93eabe58b6f934f51f35 (diff) | |
download | wallet-core-e1d86816a7c07cb8ca2d54676d5cdbbe513f2ba7.tar.xz |
backoffcie new version, lot of changes
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/index.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/index.ts | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/index.ts b/packages/merchant-backoffice-ui/src/hooks/index.ts index b77b9dea8..79b22304a 100644 --- a/packages/merchant-backoffice-ui/src/hooks/index.ts +++ b/packages/merchant-backoffice-ui/src/hooks/index.ts @@ -19,9 +19,10 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { StateUpdater, useCallback, useState } from "preact/hooks"; +import { StateUpdater, useCallback, useEffect, useState } from "preact/hooks"; import { ValueOrFunction } from "../utils/types.js"; import { useMemoryStorage } from "@gnu-taler/web-util/browser"; +import { useMatchMutate } from "./backend.js"; const calculateRootPath = () => { const rootPath = @@ -56,8 +57,22 @@ export function useBackendDefaultToken( ): [string | undefined, ((d: string | undefined) => void)] { // uncomment for testing initialValue = "secret-token:secret" as string | undefined - const { update, value } = useMemoryStorage(`backend-token`, initialValue) - return [value, update]; + const { update: setToken, value: token, reset } = useMemoryStorage(`backend-token`, initialValue) + const clearCache = useMatchMutate() + useEffect(() => { + clearCache() + }, [token]) + + function updateToken( + value: (string | undefined) + ): void { + if (value === undefined) { + reset() + } else { + setToken(value) + } + } + return [token, updateToken]; } export function useBackendInstanceToken( @@ -73,14 +88,12 @@ export function useBackendInstanceToken( function updateToken( value: (string | undefined) ): void { - console.log("seeting token", value) if (value === undefined) { reset() } else { setToken(value) } } - console.log("token", token) return [token, updateToken]; } |