@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.
354 lines (353 loc) • 18.2 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] = "821b0042-9df2-4b43-a6f0-c6b67fddc21a", e._sentryDebugIdIdentifier = "sentry-dbid-821b0042-9df2-4b43-a6f0-c6b67fddc21a");
} catch (e) {}
import { i as Typography, n as addResourceBundles, r as useTranslation } from "./translation-BFxyJ1c5.js";
import { r as Loader, t as Button } from "./Button-oj6H8OrC.js";
import { n as httpGet, s as useApiContext } from "./http-D1NDkBxF.js";
import { r as useLegalEntity } from "./useLegalEntity-yxi9XhLi.js";
import { t as getLegalEntityCountry } from "./getLegalEntityCountry-C6bSV6sB.js";
import { s as noop } from "./useAnalyticsContext-BVFDMrVE.js";
import { t as _rolldown_dynamic_import_helper_default } from "./_rolldown_dynamic_import_helper-rq_tsyLP.js";
import { t as StackLayout } from "./StackLayout-Bhbj68nx.js";
import { t as TaskVerificationStatus } from "./TaskVerificationStatus-kCWYhocq.js";
import { n as TASK_STATUS_POLLING_INTERVAL_MS, r as TaskStatuses } from "./taskStatus-C7XU4UIF.js";
import { p as TaskTypes } from "./entityAssociationUtil-BEzUdPbm.js";
import { t as useTaskStatus } from "./useTaskStatus-PqBc0I7k.js";
import { t as Image } from "./Image-BEzOZ1tt.js";
import { t as getIndividualLegalEntityName } from "./getName-Bdwp_hkV.js";
import { t as IndividualDropin } from "./IndividualDropin-D1n1fwWm.js";
import { t as List } from "./List-DLrcpMVd.js";
import { t as LandingLayout } from "./LandingLayout-z8j2xiqg.js";
import { t as ListItem } from "./ListItem-BWH4IPrj.js";
import { n as getDecisionMakerDescription, r as getLandingLayoutProps, t as DecisionMakerDetails } from "./DecisionMakerDetails-CYAI6xGa.js";
import { lazy } from "preact/compat";
import { useCallback as useCallback$1, useEffect as useEffect$1, useMemo as useMemo$1, useState as useState$1 } from "preact/hooks";
import { jsx, jsxs } from "preact/jsx-runtime";
import { useQuery } from "@tanstack/preact-query";
//#region src/api/invitedEntity/useInvitedEntityAssociationData.ts
var getInvitedEntityAssociationData = async (invitedLegalEntityId, baseUrl) => {
return httpGet({
baseUrl,
path: `invitedLegalEntities/${invitedLegalEntityId}/entityAssociationData`
});
};
var useInvitedEntityAssociationData = (invitedLegalEntityId, options) => {
const { baseUrl } = useApiContext();
return useQuery({
queryKey: ["entityAssociationData", invitedLegalEntityId],
queryFn: () => getInvitedEntityAssociationData(invitedLegalEntityId, baseUrl.value),
...options
});
};
//#endregion
//#region src/api/invitedEntity/useInvitedEntityRootCapabilities.ts
var getInvitedEntityRootCapabilities = async (invitedLegalEntityId, baseUrl) => {
return httpGet({
baseUrl,
path: `invitedLegalEntities/${invitedLegalEntityId}/rootCapabilities`
});
};
/**
* Retrieves a given legal entity.
*
* @param {boolean} isInvitedEntity :
*/
var useInvitedEntityRootCapabilities = () => {
const { rootLegalEntityId, baseUrl } = useApiContext();
const result = useQuery({
queryKey: ["invitedEntityRootCapabilities", rootLegalEntityId.value],
queryFn: () => getInvitedEntityRootCapabilities(rootLegalEntityId.value, baseUrl.value)
});
return {
refetch: result.refetch,
isLoading: result.isLoading,
isError: result.isError,
data: result.data?.capabilities
};
};
var InvitedDecisionMaker_module_default = {
"invited-decision-makers-container": "adyen-kyc-invited-decision-makers-container",
invitedDecisionMakersContainer: "adyen-kyc-invited-decision-makers-container"
};
//#endregion
//#region src/components/Individual/tasks/DecisionMakers/InvitedDecisionMaker/InvitedDecisionMakerGettingStarted/InvitedDecisionMakerGettingStarted.tsx
var decisionMakerGroup$1 = lazy(() => import("./decision-makers-group-BLkUEz0w.js"));
var InvitedDecisionMakerGettingStarted = ({ addDecisionMakerOnClick }) => {
const { t } = useTranslation("individual");
const { t: commonT } = useTranslation("common");
return /* @__PURE__ */ jsx("div", {
className: InvitedDecisionMaker_module_default.invitedDecisionMakersContainer,
children: /* @__PURE__ */ jsx(LandingLayout, {
media: /* @__PURE__ */ jsx(Image, { lazyLoadedImage: decisionMakerGroup$1 }),
title: t(($) => $["tellUsAboutYourself"]),
description: t(($) => $["invitedDecisionMakerIntroDescription"]),
actions: /* @__PURE__ */ jsx(Button, {
fullWidth: true,
onClick: addDecisionMakerOnClick,
children: commonT(($) => $["getStarted"])
})
})
});
};
//#endregion
//#region src/components/Individual/tasks/DecisionMakers/hooks/useTaskStatusWithTimeout.ts
/**
* Custom hook that polls for a specific task status with a built-in timeout.
* It manages the timeout state, stopping polling if the task completes, errors out, or the timeout is reached.
*
* @param taskType - The specific type of task to monitor.
* @param timeoutMs - The duration in milliseconds before timing out if the task is still processing.
* @returns Status indicators and the current task status.
*/
var useTaskStatusWithTimeout = (taskType, timeoutMs = 16e3) => {
const [hasTimedOut, setHasTimedOut] = useState$1(false);
const { data: taskStatuses } = useTaskStatus({ refetchInterval: (query) => {
const status = query.state.data?.statuses?.find((task) => task.type === taskType)?.status;
if (status === "FINISHED" || status === "ERROR" || hasTimedOut) return false;
return TASK_STATUS_POLLING_INTERVAL_MS;
} });
const submitStatus = taskStatuses?.[taskType]?.status;
useEffect$1(() => {
let timer;
if (submitStatus === TaskStatuses.PROCESSING) timer = setTimeout(() => {
setHasTimedOut(true);
}, timeoutMs);
return () => {
if (timer) clearTimeout(timer);
};
}, [submitStatus, timeoutMs]);
const isLoading = submitStatus === TaskStatuses.PROCESSING && !hasTimedOut || submitStatus === void 0;
const isErrorOrDetailsRequired = submitStatus === TaskStatuses.ERROR || submitStatus === TaskStatuses.DETAILS_REQUIRED;
return {
submitStatus,
decisionMakerStatus: submitStatus ?? TaskStatuses.UNKNOWN,
isLoading,
isErrorOrDetailsRequired
};
};
//#endregion
//#region src/components/Individual/tasks/DecisionMakers/InvitedDecisionMaker/InvitedDecisionMakerSubmitSuccess/InvitedDecisionMakerSubmitSuccess.tsx
var decisionMakerGroup = lazy(() => import("./decision-makers-group-BLkUEz0w.js"));
var InvitedDecisionMakerSubmitSuccess = ({ decisionMaker, handleEdit = noop }) => {
const { t } = useTranslation("individual");
const [showDecisionMakerModal, setShowDecisionMakerModal] = useState$1(false);
const { submitStatus, decisionMakerStatus, isLoading, isErrorOrDetailsRequired } = useTaskStatusWithTimeout(TaskTypes.INVITED_INDIVIDUAL);
const landingLayoutProps = useMemo$1(() => getLandingLayoutProps(submitStatus, isErrorOrDetailsRequired, t), [
submitStatus,
isErrorOrDetailsRequired,
t
]);
const handleOpenModal = useCallback$1(() => setShowDecisionMakerModal(true), []);
const handleCloseModal = useCallback$1(() => setShowDecisionMakerModal(false), []);
const decisionMakerWithStatus = useMemo$1(() => ({
...decisionMaker,
status: decisionMakerStatus
}), [decisionMaker, decisionMakerStatus]);
if (isLoading) return /* @__PURE__ */ jsx("div", {
className: InvitedDecisionMaker_module_default.invitedDecisionMakersContainer,
children: /* @__PURE__ */ jsxs(StackLayout, {
align: "center",
gap: "xSmall",
children: [
/* @__PURE__ */ jsx(Loader, {
shortMessage: "",
longMessage: ""
}),
/* @__PURE__ */ jsx(Typography, {
variant: "title-l",
el: "h1",
children: t(($) => $["verifyingYourDetails"])
}),
/* @__PURE__ */ jsx(Typography, {
variant: "body",
el: "p",
color: "secondary",
children: t(($) => $["thisUsuallyTakesAbout15Seconds"])
})
]
})
});
return /* @__PURE__ */ jsxs("div", {
className: InvitedDecisionMaker_module_default.invitedDecisionMakersContainer,
children: [
/* @__PURE__ */ jsx(LandingLayout, {
media: /* @__PURE__ */ jsx(Image, { lazyLoadedImage: decisionMakerGroup }),
...landingLayoutProps
}),
(submitStatus === TaskStatuses.PROCESSING || isErrorOrDetailsRequired) && /* @__PURE__ */ jsxs(List, {
variant: "grouped-primary",
padding: "medium",
dividers: false,
children: [/* @__PURE__ */ jsx(ListItem, {
accessory: /* @__PURE__ */ jsx(TaskVerificationStatus, { status: decisionMakerStatus }),
avatar: {
iconName: "user",
circle: true
},
title: decisionMaker.name,
description: getDecisionMakerDescription(decisionMaker.types, t)
}), isErrorOrDetailsRequired && /* @__PURE__ */ jsx("div", {
className: "adyen-kyc-u-margin-top-16",
children: /* @__PURE__ */ jsx(Button, {
fullWidth: true,
onClick: handleOpenModal,
children: t(($) => $["reviewDetails"])
})
})]
}),
isErrorOrDetailsRequired && showDecisionMakerModal && /* @__PURE__ */ jsx(DecisionMakerDetails, {
handleClose: handleCloseModal,
handleEdit,
decisionMaker: decisionMakerWithStatus
})
]
});
};
//#endregion
//#region src/components/EmbeddedDropins/InvitedDecisionMakerComponent/InvitedDecisionMakerComponent.tsx
function InvitedDecisionMakerComponent({ invitedIndividualId }) {
if (!invitedIndividualId) throw new Error("Must provide `invitedIndividualEntityId`");
const { i18n } = useTranslation();
addResourceBundles(i18n, [
{
ns: "common",
importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
"../../../language/locales/bg-BG.json": () => import("./bg-BG-COHRuTI-.js"),
"../../../language/locales/cs-CZ.json": () => import("./cs-CZ-CmcYZLZp.js"),
"../../../language/locales/da-DK.json": () => import("./da-DK-C_oe1bpM.js"),
"../../../language/locales/de-DE.json": () => import("./de-DE-CMc1Fpfl.js"),
"../../../language/locales/el-GR.json": () => import("./el-GR-Bv2QgmVV.js"),
"../../../language/locales/en-US.instructions.json": () => import("./en-US.instructions-DJharl6b.js"),
"../../../language/locales/en-US.json": () => import("./en-US-cJAmQhFR.js").then((n) => n.n),
"../../../language/locales/es-ES.json": () => import("./es-ES-DtlXpZ_5.js"),
"../../../language/locales/et-EE.json": () => import("./et-EE-PTcJ2hRW.js"),
"../../../language/locales/fi-FI.json": () => import("./fi-FI-C1Ns3CEo.js"),
"../../../language/locales/fr-FR.json": () => import("./fr-FR-DgPRYmmJ.js"),
"../../../language/locales/hr-HR.json": () => import("./hr-HR-BQfjrcPC.js"),
"../../../language/locales/hu-HU.json": () => import("./hu-HU-DfYPelYo.js"),
"../../../language/locales/it-IT.json": () => import("./it-IT-cnETv3Cg.js"),
"../../../language/locales/ja-JP.json": () => import("./ja-JP-D0gz56Ni.js"),
"../../../language/locales/lt-LT.json": () => import("./lt-LT-Bbh9MWxc.js"),
"../../../language/locales/lv-LV.json": () => import("./lv-LV-C8fqHR2g.js"),
"../../../language/locales/nl-NL.json": () => import("./nl-NL-CQSu4iNn.js"),
"../../../language/locales/no-NO.json": () => import("./no-NO-C0DXekH-.js"),
"../../../language/locales/pl-PL.json": () => import("./pl-PL-10KUcobm.js"),
"../../../language/locales/pt-BR.json": () => import("./pt-BR-DWKF33yP.js"),
"../../../language/locales/pt-PT.json": () => import("./pt-PT-CjIFIi4R.js"),
"../../../language/locales/ro-RO.json": () => import("./ro-RO-DQFRJwp8.js"),
"../../../language/locales/sk-SK.json": () => import("./sk-SK-BfoXFhAL.js"),
"../../../language/locales/sl-SI.json": () => import("./sl-SI-CyIN1sc5.js"),
"../../../language/locales/sv-SE.json": () => import("./sv-SE-Xh17T6yC.js")
}), `../../../language/locales/${lang}.json`, 6)
},
{
ns: "ui",
importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
"../../ui/language/bg-BG.json": () => import("./bg-BG-BUBUyZgz.js"),
"../../ui/language/cs-CZ.json": () => import("./cs-CZ-BFJyFYpX.js"),
"../../ui/language/da-DK.json": () => import("./da-DK-BNvIcL59.js"),
"../../ui/language/de-DE.json": () => import("./de-DE-B8Eby_UK.js"),
"../../ui/language/el-GR.json": () => import("./el-GR-DYmDnzZe.js"),
"../../ui/language/en-US.json": () => import("./en-US-Mma5wIWL.js"),
"../../ui/language/es-ES.json": () => import("./es-ES-DLBRDQJZ.js"),
"../../ui/language/et-EE.json": () => import("./et-EE-C_Z4PWda.js"),
"../../ui/language/fi-FI.json": () => import("./fi-FI-azwPyx-k.js"),
"../../ui/language/fr-FR.json": () => import("./fr-FR-CzdHSH04.js"),
"../../ui/language/hr-HR.json": () => import("./hr-HR-C7Hp8OgD.js"),
"../../ui/language/hu-HU.json": () => import("./hu-HU-B34uBEZ9.js"),
"../../ui/language/it-IT.json": () => import("./it-IT-BCqVu72_.js"),
"../../ui/language/ja-JP.json": () => import("./ja-JP-C7_6K98B.js"),
"../../ui/language/lt-LT.json": () => import("./lt-LT-BhzsTniu.js"),
"../../ui/language/lv-LV.json": () => import("./lv-LV-B6yxwa6Z.js"),
"../../ui/language/nl-NL.json": () => import("./nl-NL-4iZ44kzK.js"),
"../../ui/language/no-NO.json": () => import("./no-NO-BSJ1rjY4.js"),
"../../ui/language/pl-PL.json": () => import("./pl-PL-BHjlKdWC.js"),
"../../ui/language/pt-BR.json": () => import("./pt-BR-BMIZHo3V.js"),
"../../ui/language/pt-PT.json": () => import("./pt-PT-s_KcBKav.js"),
"../../ui/language/ro-RO.json": () => import("./ro-RO-DsFmqo3p.js"),
"../../ui/language/sk-SK.json": () => import("./sk-SK-BspZv60l.js"),
"../../ui/language/sl-SI.json": () => import("./sl-SI-D26FDPwq.js"),
"../../ui/language/sv-SE.json": () => import("./sv-SE-JKGeqd9J.js")
}), `../../ui/language/${lang}.json`, 5)
},
{
ns: "individual",
importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
"../../Individual/language/bg-BG.json": () => import("./bg-BG-BlOJQ7iZ.js"),
"../../Individual/language/cs-CZ.json": () => import("./cs-CZ-CtEcakjz.js"),
"../../Individual/language/da-DK.json": () => import("./da-DK-Cp1cdZTG.js"),
"../../Individual/language/de-DE.json": () => import("./de-DE-ZWLyKP5G.js"),
"../../Individual/language/el-GR.json": () => import("./el-GR-DSmTVw3A.js"),
"../../Individual/language/en-US.instructions.json": () => import("./en-US.instructions-HI_HXwIA.js"),
"../../Individual/language/en-US.json": () => import("./en-US-5p2iDJhN.js"),
"../../Individual/language/es-ES.json": () => import("./es-ES-CKWpTQva.js"),
"../../Individual/language/et-EE.json": () => import("./et-EE-BeU-JlIv.js"),
"../../Individual/language/fi-FI.json": () => import("./fi-FI-DKJi4py_.js"),
"../../Individual/language/fr-FR.json": () => import("./fr-FR-JIF28b7U.js"),
"../../Individual/language/hr-HR.json": () => import("./hr-HR-C4LLZhRc.js"),
"../../Individual/language/hu-HU.json": () => import("./hu-HU-1NJpWkUj.js"),
"../../Individual/language/it-IT.json": () => import("./it-IT-C4b9Y6tP.js"),
"../../Individual/language/ja-JP.json": () => import("./ja-JP-BFkGV7Ct.js"),
"../../Individual/language/lt-LT.json": () => import("./lt-LT-Cq2T_YgH.js"),
"../../Individual/language/lv-LV.json": () => import("./lv-LV-DcclJdry.js"),
"../../Individual/language/nl-NL.json": () => import("./nl-NL-DWgJVfgU.js"),
"../../Individual/language/no-NO.json": () => import("./no-NO-BCZzdSpR.js"),
"../../Individual/language/pl-PL.json": () => import("./pl-PL-D3efS6b_.js"),
"../../Individual/language/pt-BR.json": () => import("./pt-BR-OCQiqikl.js"),
"../../Individual/language/pt-PT.json": () => import("./pt-PT-BHbd93Ic.js"),
"../../Individual/language/ro-RO.json": () => import("./ro-RO-CVzi0I9_.js"),
"../../Individual/language/sk-SK.json": () => import("./sk-SK-woMNza6o.js"),
"../../Individual/language/sl-SI.json": () => import("./sl-SI-Czu6HrQs.js"),
"../../Individual/language/sv-SE.json": () => import("./sv-SE-BIe7wyHM.js")
}), `../../Individual/language/${lang}.json`, 5)
}
]);
const [step, setStep] = useState$1("landingStep");
const { data: invitedIndividualLe } = useLegalEntity(invitedIndividualId);
const { data: invitedEntityAssociationData } = useInvitedEntityAssociationData(invitedIndividualId);
const { data: rootCapabilities } = useInvitedEntityRootCapabilities();
const invitedEntityDetails = useMemo$1(() => {
if (!invitedEntityAssociationData) return { roles: [] };
const { associations } = invitedEntityAssociationData;
return {
roles: Array.from(new Set(associations.map((a) => a.type))),
jobTitle: associations.find((a) => a.jobTitle)?.jobTitle,
rootCapabilities
};
}, [invitedEntityAssociationData, rootCapabilities]);
const decisionMaker = useMemo$1(() => ({
reference: invitedIndividualId,
name: getIndividualLegalEntityName(invitedIndividualLe),
types: invitedEntityDetails.roles,
legalEntityType: invitedIndividualLe?.type
}), [
invitedIndividualId,
invitedIndividualLe,
invitedEntityDetails.roles
]);
if (!invitedIndividualLe) return /* @__PURE__ */ jsx(Loader, {});
const country = getLegalEntityCountry(invitedIndividualLe);
const handleSubmitSuccess = () => setStep("submitSuccessStep");
switch (step) {
case "landingStep": return /* @__PURE__ */ jsx(InvitedDecisionMakerGettingStarted, { addDecisionMakerOnClick: () => setStep("provideDetailsStep") });
case "provideDetailsStep": return /* @__PURE__ */ jsx(IndividualDropin, {
taskType: TaskTypes.DECISION_MAKER,
taskName: "decisionMakerDetails",
legalEntityResponse: invitedIndividualLe,
problems: void 0,
country,
asModal: true,
handleHomeClick: () => setStep("landingStep"),
isInvitedEntity: true,
invitedEntityDetails,
onSubmit: handleSubmitSuccess
});
case "submitSuccessStep": return /* @__PURE__ */ jsx(InvitedDecisionMakerSubmitSuccess, {
decisionMaker,
handleEdit: () => setStep("provideDetailsStep")
});
}
}
//#endregion
export { InvitedDecisionMakerComponent as t };