diff --git a/clients/banking/src/components/MembershipInvitationLinkModal.tsx b/clients/banking/src/components/MembershipInvitationLinkModal.tsx index d9613a710..f9fbaf2a2 100644 --- a/clients/banking/src/components/MembershipInvitationLinkModal.tsx +++ b/clients/banking/src/components/MembershipInvitationLinkModal.tsx @@ -1,8 +1,9 @@ -import { Option } from "@swan-io/boxed"; +import { AsyncData, Option, Result } from "@swan-io/boxed"; import { useDeferredQuery } from "@swan-io/graphql-client"; import { Box } from "@swan-io/lake/src/components/Box"; import { LakeLabel } from "@swan-io/lake/src/components/LakeLabel"; import { LakeTextInput } from "@swan-io/lake/src/components/LakeTextInput"; +import { LoadingView } from "@swan-io/lake/src/components/LoadingView"; import { Space } from "@swan-io/lake/src/components/Space"; import { LakeModal } from "@swan-io/shared-business/src/components/LakeModal"; import { useEffect } from "react"; @@ -12,6 +13,7 @@ import { getMemberName } from "../utils/accountMembership"; import { t } from "../utils/i18n"; import { projectConfiguration } from "../utils/projectId"; import { CopyTextButton } from "./CopyTextButton"; +import { ErrorView } from "./ErrorView"; type Props = { accountMembershipId: string | undefined; @@ -27,14 +29,6 @@ export const MembershipInvitationLinkModal = ({ accountMembershipId, onPressClos } }, [accountMembershipId, query]); - const value = match(projectConfiguration) - .with( - Option.P.Some({ projectId: P.select(), mode: "MultiProject" }), - projectId => - `${__env.BANKING_URL}/api/projects/${projectId}/invitation/${accountMembershipId ?? ""}`, - ) - .otherwise(() => `${__env.BANKING_URL}/api/invitation/${accountMembershipId ?? ""}`); - return ( - { + {match(data) + .with(AsyncData.P.NotAsked, AsyncData.P.Loading, () => ) + .with(AsyncData.P.Done(Result.P.Error(P.select())), () => ) + .with(AsyncData.P.Done(Result.P.Ok(P.select())), ({ accountMembership }) => { + const value = match(projectConfiguration) + .with( + Option.P.Some({ projectId: P.select(), mode: "MultiProject" }), + projectId => + `${__env.BANKING_URL}/api/projects/${projectId}/invitation/${accountMembershipId ?? ""}`, + ) + .otherwise(() => `${__env.BANKING_URL}/api/invitation/${accountMembershipId ?? ""}`); + + const url = new URL(value); + url.searchParams.append("identificationLevel", "Auto"); + match(accountMembership.statusInfo) + .with( + { + __typename: P.union( + "AccountMembershipBindingUserErrorStatusInfo", + "AccountMembershipInvitationSentStatusInfo", + ), + }, + ({ restrictedTo }) => { + if (restrictedTo.phoneNumber == null && accountMembership?.email != null) { + url.searchParams.append("email", accountMembership.email); + } + }, + ) + .otherwise(() => {}); + + const urlAsString = url.toString(); + return ( - - - - - + { + return ( + + + + + + ); + }} + /> ); - }} - /> + }) + .exhaustive()} ); }; diff --git a/server/src/index.swan.ts b/server/src/index.swan.ts index a1e3c4d3a..340d6d378 100644 --- a/server/src/index.swan.ts +++ b/server/src/index.swan.ts @@ -98,6 +98,7 @@ const getMailjetInput = ({ const ctaUrl = new URL( `${env.BANKING_URL}/api/projects/${projectInfo.id}/invitation/${inviteeAccountMembership.id}`, ); + ctaUrl.searchParams.append("identificationLevel", "Auto"); if (inviteeAccountMembership.statusInfo.restrictedTo.phoneNumber == null) { ctaUrl.searchParams.append("email", inviteeAccountMembership.email); }