The JoinWorkspace component allows an authenticated user to join a workspace if they have a valid join key.
The user will enter the JoinWorkspace component with an action name and a join key. By default, the join action is “No Action” and the join key is an empty GUID.
In the OnInitializedAsync method, the ActionName is checked. If the action is “Join” and there is a provided join key, the key is validated. If the action is “JoinDefault”, the default join key is validated. If the action is “JoinExistingPortal” the join key and portal guid are validated. If the action name is “JoinWorkspaceOwnerAdmin” the command is validated, then if the command is valid, the command is executed. If the ActionName is “JoinServerOwnerAdmin”, the command is validated and then executed.
Join links are validated by connecting to the API and querying the database. If the join link is valid, the join page content is loaded and displayed. Once the user has joined the database, if the join link creates an active user, the component navigates to the user’s default application. If the join link creates an inactive user, the component loads and displays the invite’s specified post-join content.
@if (UserInactive) { @if (AppState.User.JoinedContent != "") { @((MarkupString)AppState.User.JoinedContent) } } else { @if (JoinKeyInvalid) { <label for="JoinKey">Join Key</label> <div> <TelerikTextBox Placeholder="" Title="Paste Join Key here." @bind-Value="@JoinKey" Width="230px" Id="JoinKey" Name="joinKey"> </TelerikTextBox> <TelerikButton Title="ValidateKey" @onclick="ValidateKeyBtnOnClick">Validate Key</TelerikButton> </div> } else { @if (AppState.User.JoinPage != "") { @if (JoinKey.Length == 73 && AppState.User.JoinExistingPage != "") { @((MarkupString)AppState.User.JoinExistingPage) } else { @((MarkupString)AppState.User.JoinPage) } } @if (PortalFieldVisisble) { <label for="JoinButton">@AppState.User.PortalStringLabel</label> <TelerikTextBox Id="JoinButton" Title="Join" @bind-Value="@AppState.User.PortalStringValue"></TelerikTextBox> <br /> } @if (AppState.User.CheckboxText != "") { <table> <tr> <td> <TelerikCheckBox Id="SubscribeCheckbox" TValue="bool" @bind-Value="@Subscribe" AriaLabel="Subscribe"></TelerikCheckBox> </td> <td> @((MarkupString)AppState.User.CheckboxText) </td> </tr> </table> } @if (AppState.User.JoinPageBottomHTML != "") { @((MarkupString)AppState.User.JoinPageBottomHTML) } <br /> <TelerikButton Id="JoinButton" Title="Join" @onclick="JoinBtnOnClick">@JoinButtonText</TelerikButton> } } <TelerikWindow MaxHeight="30%" MaxWidth="30%" Centered="true" @bind-Visible="@ShowJoinPrompt" Modal="true" Draggable="false"> <WindowTitle> <strong>Confirm intent to Join</strong> </WindowTitle> <WindowContent> <div> You are attempting to join a workspace that you are already a part of! If you have navigated to this page with a bookmarked URL that includes a join link, consider editing the bookmark to the base url. If you wish to continue and join the workspace again, please click "Confirm" </div> <div> <table> <tr> <td> <TelerikButton TabIndex="0" OnClick="HideWindow">Confirm</TelerikButton> </td> <td> <TelerikButton TabIndex="0" OnClick="CancelJoin">Cancel</TelerikButton> </td> </tr> </table> </div> </WindowContent> <WindowActions> <WindowAction Name="Close"></WindowAction> </WindowActions> </TelerikWindow> @code { [CascadingParameter] protected Notification Notification { get; set; } private string JoinKey { get; set; } = ""; private string JoinLabelValue { get; set; } = "No Workspace Selected"; private string JoinButtonText { get; set; } = "Join Workspace"; private XElement InstanceData { get; set; } = null; private bool JoinKeyInvalid { get; set; } = true; private bool UserInactive { get; set; } = false; private bool JoinedContentAvailable { get; set; } = false; private bool Subscribe { get; set; } = true; private bool PortalFieldVisisble { get; set; } = false; private bool ShowJoinPrompt = false; protected override async Task OnInitializedAsync() { try { await AppState.EnterWorkspace(EventLog, InstanceClient); switch (AppState.URLParameters.ActionName) { case "Join": if (AppState.URLParameters.InviteUserGUID != Guid.Empty.ToString()) { JoinKey = AppState.URLParameters.InviteUserGUID; await ValidateKeyBtnOnClick(); } break; case "JoinDefault": JoinKey = AppState.URLParameters.InviteUserGUID; await ValidateKeyBtnOnClick(); break; case "JoinExistingPortal": if (AppState.URLParameters.InviteUserGUID != Guid.Empty.ToString()) { JoinKey = AppState.URLParameters.InviteUserGUID; if (AppState.URLParameters.PortalGUID != Guid.Empty.ToString()) { JoinKey = JoinKey + "-" + AppState.URLParameters.PortalGUID; } await ValidateKeyBtnOnClick(); } break; case "JoinWorkspaceOwnerAdmin": if (AppState.URLParameters.WorkspaceGUID != Guid.Empty.ToString()) { AppState.User.WorkspaceGUID = Guid.Parse(AppState.URLParameters.WorkspaceGUID); AppState.User.CommandName = "JoinWorkspaceOwnerAdmin"; AppState.User = await UserClient.CallAPI(AppState.User, "/UserState/CallAPI"); if (AppState.User.ErrorMessage == "") { await AppState.ChangeConfiguration("Descriptions", "true", UserClient); await NavigateToInstance(); } } break; case "JoinServerOwnerAdmin": AppState.User.CommandName = "JoinServerOwnerAdmin"; AppState.User = await UserClient.CallAPI(AppState.User, "/UserState/CallAPI"); if (AppState.User.ErrorMessage == "") { await AppState.ChangeConfiguration("Descriptions", "true", UserClient); await NavigateToInstance(); } break; case "No Action": if (AppState.User.Workspaces == "<NewDataSet />") { if (Configuration["DefaultJoinKey"] != "") { JoinKey = Configuration["DefaultJoinKey"]; await ValidateKeyBtnOnClick(); } } break; default: Notification.ShowDefaultErrorNotification("URL Parameters failed to initialize."); await EventLog.Log(1, "JoinWorkspace.OnInitializedAsync - Invalid URLParameter Interpretation", AppState.URLParameters.ToString()); break; } await base.OnInitializedAsync(); } catch (Exception e) { Notification.ShowDefaultErrorNotification(); await EventLog.Log(1, "JoinWorkspace.OnInitializedAsync - Unknown", e.ToString()); } } private async Task ValidateKeyBtnOnClick() { try { AppState.User.JoinKey = JoinKey; AppState.User.CommandName = "ValidateKey"; AppState.User = await UserClient.CallAPI(AppState.User, "/UserState/CallAPI"); if (AppState.User.ErrorMessage == "") { JoinKeyInvalid = false; JoinLabelValue = $"Click the button to join the {AppState.User.WorkspaceName} workspace"; ShowJoinPrompt = AppState.User.HasUserInWorkspace; if (AppState.User.JoinButtonText != "") { JoinButtonText = AppState.User.JoinButtonText; } if (AppState.User.JoinExistingButtonText != "" && JoinKey.Length == 73) { // The join link is a valid existing portal join link. JoinButtonText = AppState.User.JoinExistingButtonText; } if (JoinKey.Length == 36 && AppState.User.PortalStringLabel != "" && AppState.User.PortalStringElementName != "") { // Only visible for a new portal where a portal name is required. PortalFieldVisisble = true; } } else { Notification.ShowDefaultErrorNotification("Join Key Invalid!"); } this.StateHasChanged(); } catch (Exception ex) { Notification.ShowDefaultErrorNotification("Error Validating Join Key"); await EventLog.Log(1, "JoinWorkspace.ValidateKeyBtnOnClick - Unknown", ex.ToString()); } } private async Task NavigateToInstance() { try { await AppState.EnterWorkspace(EventLog, InstanceClient); AppState.BackgroundForm.Instance = new() { SessionGUID = AppState.User.SessionGUID, UserGUID = AppState.User.UserGUID }; if (AppState.User.PortalInstanceGUID == Guid.Empty) { AppState.BackgroundForm.Instance.InstanceGUID = AppState.User.WorkspaceGUID; } else { AppState.BackgroundForm.Instance.InstanceGUID = AppState.User.PortalInstanceGUID; } AppState.BackgroundForm.Instance.FormDefinitionGUID = AppState.User.DefaultApplicationGUID; AppState.LastApplicationGUID = AppState.User.DefaultApplicationGUID; await AppState.SetConfiguration(UserClient); if (AppState.User.ErrorMessage == "") { AppState.UserJoining = false; AppState.URLParams = ""; AppState.URLParameters = new(); NavigationManager.NavigateTo("Instance"); } else { Notification.ShowDefaultErrorNotification("Failed to set user configuration"); await EventLog.Log(1, "JoinWorkspace.NavigateToInstance - Failed to set user configuration", AppState.User.ErrorMessage); } } catch (Exception ex) { Notification.ShowDefaultErrorNotification(); await EventLog.Log(1, "JoinWorkspace.NavigateToInstance - Unknown", ex.ToString()); } } private async void JoinBtnOnClick() { try { Guid parsedInstanceGUID; if (Guid.TryParse(JoinKey.Left(36), out parsedInstanceGUID)) { AppState.User.InviteUserGUID = parsedInstanceGUID; AppState.User.JoinLinkCheckbox = Subscribe; AppState.User.CommandName = "JoinWorkspace"; AppState.User = await UserClient.CallAPI(AppState.User, "/UserState/CallAPI"); if (AppState.User.ErrorMessage == "") { if (AppState.User.UserState == "Active") { await NavigateToInstance(); } else { UserInactive = true; this.StateHasChanged(); } } else { Notification.ShowDefaultErrorNotification("Failed to Join Workspace"); await EventLog.Log(1, "JoinWorkspace.JoinBtnOnClick - Failed to Join Workspace", AppState.User.ErrorMessage); } } else { Notification.ShowDefaultErrorNotification("Invalid Join Key."); } } catch (Exception ex) { Notification.ShowDefaultErrorNotification("Unexpected error joining workspace."); await EventLog.Log(1, "JoinWorkspace.JoinBtnOnClick - Unknown", ex.ToString()); } } private async void HideWindow() { try { ShowJoinPrompt = false; this.StateHasChanged(); } catch (Exception ex) { Notification.ShowDefaultErrorNotification("Unexpected closing join prompt window."); await EventLog.Log(1, "JoinWorkspace.HideWindow - Unknown", ex.ToString()); } } private async void CancelJoin() { try { ShowJoinPrompt = false; if (AppState.User.Workspaces == "<NewDataSet />") { UserInactive = true; AppState.User.JoinedContent = "Your user account is currently inactive. <br> Please contact your server owner to activate your account."; this.StateHasChanged(); } else { AppState.UserJoining = false; AppState.NotifyStateChanged(); } } catch (Exception ex) { Notification.ShowDefaultErrorNotification("Unexpected error closing join prompt window."); await EventLog.Log(1, "JoinWorkspace.CancelJoin - Unknown", ex.ToString()); } } }