diff --git a/.changeset/rude-zebras-dress.md b/.changeset/rude-zebras-dress.md new file mode 100644 index 000000000..96a30b439 --- /dev/null +++ b/.changeset/rude-zebras-dress.md @@ -0,0 +1,5 @@ +--- +'@asgardeo/react': patch +--- + +Support sending invite links via email, with direct link sharing as a fallback. diff --git a/packages/react/src/components/presentation/auth/InviteUser/v2/BaseInviteUser.tsx b/packages/react/src/components/presentation/auth/InviteUser/v2/BaseInviteUser.tsx index cf0511f8c..dc59d2e5a 100644 --- a/packages/react/src/components/presentation/auth/InviteUser/v2/BaseInviteUser.tsx +++ b/packages/react/src/components/presentation/auth/InviteUser/v2/BaseInviteUser.tsx @@ -103,6 +103,11 @@ export interface BaseInviteUserRenderProps { */ inviteLinkCopied: boolean; + /** + * Whether the invite email was sent successfully. + */ + isEmailSent: boolean; + /** * Whether the invite link has been generated (admin flow complete). */ @@ -267,6 +272,7 @@ const BaseInviteUser: FC = ({ const [touchedFields, setTouchedFields] = useState>({}); const [inviteLink, setInviteLink] = useState(); const [inviteLinkCopied, setInviteLinkCopied] = useState(false); + const [emailSent, setEmailSent] = useState(false); const [isFormValid, setIsFormValid] = useState(true); const initializationAttemptedRef: any = useRef(false); @@ -437,6 +443,11 @@ const BaseInviteUser: FC = ({ onInviteLinkGenerated?.(inviteLinkValue, response.flowId); } + // Check if email was sent successfully + if (response.data?.additionalData?.['emailSent'] === 'true') { + setEmailSent(true); + } + // Check for error status if (response.flowStatus === 'ERROR') { handleError(response); @@ -501,6 +512,7 @@ const BaseInviteUser: FC = ({ setTouchedFields({}); setInviteLink(undefined); setInviteLinkCopied(false); + setEmailSent(false); initializationAttemptedRef.current = false; }, []); @@ -624,6 +636,7 @@ const BaseInviteUser: FC = ({ const {title, subtitle} = extractHeadings(components); const componentsWithoutHeadings: any = filterHeadings(components); const isInviteGenerated: any = !!inviteLink; + const isEmailSent: boolean = emailSent; // Render props const renderProps: BaseInviteUserRenderProps = { @@ -637,6 +650,7 @@ const BaseInviteUser: FC = ({ handleSubmit, inviteLink, inviteLinkCopied, + isEmailSent, isInviteGenerated, isLoading, isValid: isFormValid, @@ -695,7 +709,33 @@ const BaseInviteUser: FC = ({ ); } - // Invite link generated - success state + // Invite email sent successfully - show email sent confirmation + if (isInviteGenerated && isEmailSent) { + return ( + + + + Invite Email Sent! + + + + + + An invitation email has been sent successfully. The user can complete their registration using the link in + the email. + + +
+ +
+
+
+ ); + } + + // Invite link generated but email not sent - show copy link fallback if (isInviteGenerated && inviteLink) { return (