@adyen/kyc-components
Version:
This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.
36 lines (35 loc) • 1.98 kB
JavaScript
try {
let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "319937ec-89ed-4685-91c1-d8bd3c585e9d", e._sentryDebugIdIdentifier = "sentry-dbid-319937ec-89ed-4685-91c1-d8bd3c585e9d");
} catch (e) {}
import { o as createLogger } from "./translation-BFxyJ1c5.js";
import { r as useLegalEntity } from "./useLegalEntity-yxi9XhLi.js";
import { useMemo } from "preact/hooks";
import { skipToken } from "@tanstack/preact-query";
//#region src/hooks/useAssociatedLegalEntity.ts
var logger = createLogger();
/**
* Fetches and returns an entity of the given type which is associated to the given root legal entity.
* Also returns a callback that can be used to refetch the associated entity.
*
* @param parentLegalEntity the parent legal entity to find an associated entity for
* @param associationType the type of associated entity to fetch.
* If multiple types are provided, the first matching association is used.
*/
function useAssociatedLegalEntity(parentLegalEntity, associationType) {
const { data, refetch, isLoading } = useLegalEntity(useMemo(() => {
if (!parentLegalEntity) return void 0;
const typesToFind = Array.isArray(associationType) ? associationType : [associationType];
const matchingAssociations = parentLegalEntity.entityAssociations?.filter((entity) => typesToFind.includes(entity.type)) ?? [];
if (matchingAssociations.length > 1) logger.warn(`Multiple matching associations found for types: ${typesToFind.join(", ")} - returning the first.
${matchingAssociations.map((ass) => JSON.stringify(ass, null, 2)).join("\n")}`);
return matchingAssociations[0];
}, [parentLegalEntity, associationType])?.legalEntityId ?? skipToken);
return {
data,
refetch,
isLoading
};
}
//#endregion
export { useAssociatedLegalEntity as t };