Skip to content

Commit

Permalink
Add identificationLevel=Auto on mail invitations
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodyowl committed Nov 29, 2024
1 parent c0a46ec commit e8863ac
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
68 changes: 49 additions & 19 deletions clients/banking/src/components/MembershipInvitationLinkModal.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -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 (
<LakeModal
visible={accountMembershipId != null}
Expand All @@ -51,18 +45,54 @@ export const MembershipInvitationLinkModal = ({ accountMembershipId, onPressClos
)
.getOr(t("members.invitationTitle"))}
>
<LakeLabel
label={t("members.invitationLink")}
render={id => {
{match(data)
.with(AsyncData.P.NotAsked, AsyncData.P.Loading, () => <LoadingView />)
.with(AsyncData.P.Done(Result.P.Error(P.select())), () => <ErrorView error={error} />)

Check failure on line 50 in clients/banking/src/components/MembershipInvitationLinkModal.tsx

View workflow job for this annotation

GitHub Actions / Test & build

Cannot find name 'error'. Did you mean 'Error'?
.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)

Check failure on line 62 in clients/banking/src/components/MembershipInvitationLinkModal.tsx

View workflow job for this annotation

GitHub Actions / Test & build

'accountMembership' is possibly 'null' or 'undefined'.
.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 (
<Box direction="row">
<LakeTextInput id={id} readOnly={true} value={value} hideErrors={true} />
<Space width={12} />
<CopyTextButton value={value} />
</Box>
<LakeLabel
label={t("members.invitationLink")}
render={id => {
return (
<Box direction="row">
<LakeTextInput id={id} readOnly={true} value={urlAsString} hideErrors={true} />
<Space width={12} />
<CopyTextButton value={urlAsString} />
</Box>
);
}}
/>
);
}}
/>
})
.exhaustive()}
</LakeModal>
);
};
1 change: 1 addition & 0 deletions server/src/index.swan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e8863ac

Please sign in to comment.