aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/hooks/index.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-09-04 14:17:55 -0300
committerSebastian <sebasjm@gmail.com>2023-09-04 14:17:55 -0300
commite1d86816a7c07cb8ca2d54676d5cdbbe513f2ba7 (patch)
treed4ed5506ab3550a7e9b1a082d7ffeddf9f3c4954 /packages/merchant-backoffice-ui/src/hooks/index.ts
parentff20c3e25e076c24f7cb93eabe58b6f934f51f35 (diff)
downloadwallet-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.ts23
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];
}