Skip to content

Commit

Permalink
Merge pull request #5081 from PasinduYeshan/fix/invite-parent
Browse files Browse the repository at this point in the history
  • Loading branch information
pavinduLakshan authored Dec 19, 2023
2 parents f523a95 + 6946bc3 commit 7e6ff99
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 115 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-dragons-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/console": patch
---

Move parent user invite option to separate wizard
115 changes: 26 additions & 89 deletions apps/console/src/features/users/components/wizard/add-user-wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import React, { FunctionComponent, ReactElement, useEffect, useState } from "rea
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import { Dispatch } from "redux";
import { DropdownItemProps, Grid, Icon, Menu, Modal } from "semantic-ui-react";
import { DropdownItemProps, Grid, Icon, Modal } from "semantic-ui-react";
import { AddUserUpdated } from "./steps/add-user-basic";
import { AddUserGroups } from "./steps/add-user-groups";
import { AddUserType } from "./steps/add-user-type";
Expand All @@ -58,7 +58,6 @@ import {
HiddenFieldNames,
PasswordOptionTypes,
UserAccountTypesMain,
UserManagementConstants,
WizardStepsFormTypes
} from "../../constants";
import {
Expand All @@ -68,7 +67,6 @@ import {
WizardStepInterface,
createEmptyUserDetails } from "../../models";
import { generatePassword, getConfiguration, getUsernameConfiguration } from "../../utils";
import { InviteParentOrgUser } from "../guests/pages/invite-parent-org-user";

interface AddUserWizardPropsInterface extends IdentifiableComponentInterface, TestableComponentInterface {
closeWizard: () => void;
Expand All @@ -90,10 +88,6 @@ interface AddUserWizardPropsInterface extends IdentifiableComponentInterface, Te
requiredSteps?: WizardStepsFormTypes[] | string[];
userStore?: string;
requestedPasswordOption?: PasswordOptionTypes;
/**
* The Callback to trigger on user invite success.
*/
onUserInviteSuccess?: () => void;
}

/**
Expand All @@ -113,16 +107,13 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
): ReactElement => {

const {
adminTypeSelection,
closeWizard,
currentStep,
defaultUserTypeSelection,
emailVerificationEnabled,
isSubOrg,
onSuccessfulUserAddition,
userStore,
requiredSteps,
onUserInviteSuccess,
[ "data-testid" ]: testId
} = props;

Expand Down Expand Up @@ -527,24 +518,13 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
setInitialTempGroupList(newGroupList);
};

/**
* Triggers a form submit event for the form in the InviteParentOrgUser component.
*/
const submitParentUserInviteForm = () => {
document
.getElementById(UserManagementConstants.INVITE_PARENT_ORG_USER_FORM_ID)
.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
};

const navigateToNext = () => {
if (wizardSteps[ currentWizardStep ]?.name === WizardStepsFormTypes.USER_MODE) {
handleWizardFormSubmit(wizardState[ WizardStepsFormTypes.USER_MODE ], WizardStepsFormTypes.USER_MODE);
}

if (wizardSteps[ currentWizardStep ]?.name === WizardStepsFormTypes.BASIC_DETAILS) {
userTypeSelection === AdminAccountTypes.EXTERNAL
? setSubmitGeneralSettings()
: submitParentUserInviteForm();
setSubmitGeneralSettings();
}

if (wizardSteps[ currentWizardStep ]?.name === WizardStepsFormTypes.GROUP_LIST) {
Expand Down Expand Up @@ -883,16 +863,6 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
return wizardTitle;
};

/**
* Returns the text on the wizard subheading.
* @returns Text on the wizard subheading.
*/
const resolveWizardSubHeading = (): string => {
return (userTypeSelection === UserAccountTypesMain.EXTERNAL)
? t("extensions:manage.users.wizard.addUser.subtitle")
: t("console:manage.features.parentOrgInvitations.addUserWizard.description");
};

/**
* Returns the text on the primary button of the wizard.
* @returns Text on the primary button.
Expand All @@ -902,9 +872,7 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
return null;
}
if (wizardState[ WizardStepsFormTypes.USER_TYPE ]?.userType === administratorConfig.adminRoleName) {
return adminTypeSelection === AdminAccountTypes.INTERNAL
? t("extensions:manage.features.user.addUser.add")
: t("extensions:manage.features.user.addUser.invite");
t("extensions:manage.features.user.addUser.add");
}
if (wizardSteps[ currentWizardStep ]?.name === WizardStepsFormTypes.USER_SUMMARY) {
return t("extensions:manage.features.user.addUser.close");
Expand Down Expand Up @@ -939,59 +907,28 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
return {
content: (
<>
{
isSubOrg && (
<div className="mt-4 mb-4">
<Menu
compact={ true }
>
<Menu.Item
name={ t("console:manage.features.users.addUserType.createUser.title") }
active={ userTypeSelection === AdminAccountTypes.EXTERNAL }
onClick={ () => setUserTypeSelection(AdminAccountTypes.EXTERNAL) }
/>
<Menu.Item
name={ t("console:manage.features.users.addUserType.inviteParentUser.title") }
active={ userTypeSelection === AdminAccountTypes.INTERNAL }
onClick={ () => setUserTypeSelection(AdminAccountTypes.INTERNAL) }
/>
</Menu>
</div>
)
}
{
userTypeSelection === AdminAccountTypes.EXTERNAL ? (
<AddUserUpdated
triggerSubmit={ submitGeneralSettings }
initialValues={ wizardState && wizardState[ WizardStepsFormTypes.BASIC_DETAILS ] }
emailVerificationEnabled={ emailVerificationEnabled }
onSubmit={ (values: AddUserWizardStateInterface) =>
handleWizardFormSubmit(values, WizardStepsFormTypes.BASIC_DETAILS) }
hiddenFields={ hiddenFields }
requestedPasswordOption={ wizardState &&
wizardState[ WizardStepsFormTypes.BASIC_DETAILS ]?.passwordOption }
isFirstNameRequired={ isFirstNameRequired }
isLastNameRequired={ isLastNameRequired }
isEmailRequired={ isEmailRequired }
setUserSummaryEnabled={ setUserSummaryEnabled }
setAskPasswordFromUser={ setAskPasswordFromUser }
setOfflineUser={ setOfflineUser }
setSelectedUserStore = { setSelectedUserStore }
isBasicDetailsLoading={ isBasicDetailsLoading }
setBasicDetailsLoading={ setBasicDetailsLoading }
validationConfig ={ validationData }
isUserStoreError={ isUserStoreError }
readWriteUserStoresList={ readWriteUserStoresList }
/>
) : (
<InviteParentOrgUser
closeWizard={ closeWizard }
setIsSubmitting={ setIsSubmitting }
onUserInviteSuccess={ onUserInviteSuccess }
setAlert={ setAlert }
/>
)
}
<AddUserUpdated
triggerSubmit={ submitGeneralSettings }
initialValues={ wizardState && wizardState[ WizardStepsFormTypes.BASIC_DETAILS ] }
emailVerificationEnabled={ emailVerificationEnabled }
onSubmit={ (values: AddUserWizardStateInterface) =>
handleWizardFormSubmit(values, WizardStepsFormTypes.BASIC_DETAILS) }
hiddenFields={ hiddenFields }
requestedPasswordOption={ wizardState &&
wizardState[ WizardStepsFormTypes.BASIC_DETAILS ]?.passwordOption }
isFirstNameRequired={ isFirstNameRequired }
isLastNameRequired={ isLastNameRequired }
isEmailRequired={ isEmailRequired }
setUserSummaryEnabled={ setUserSummaryEnabled }
setAskPasswordFromUser={ setAskPasswordFromUser }
setOfflineUser={ setOfflineUser }
setSelectedUserStore = { setSelectedUserStore }
isBasicDetailsLoading={ isBasicDetailsLoading }
setBasicDetailsLoading={ setBasicDetailsLoading }
validationConfig ={ validationData }
isUserStoreError={ isUserStoreError }
readWriteUserStoresList={ readWriteUserStoresList }
/>
</>
),
icon: getUserWizardStepIcons().general,
Expand Down Expand Up @@ -1186,7 +1123,7 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
<Modal.Header className="wizard-header">
{ resolveWizardTitle() }
<Heading as="h6">
{ resolveWizardSubHeading() }
{ t("extensions:manage.users.wizard.addUser.subtitle") }
</Heading>
</Modal.Header>
{ handleModalContent() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { IdentifiableComponentInterface } from "@wso2is/core/models";
import { Heading, LinkButton, PrimaryButton, useWizardAlert } from "@wso2is/react-components";
import React, { FunctionComponent, ReactElement, useState } from "react";
import { useTranslation } from "react-i18next";
import { Grid, Modal } from "semantic-ui-react";
import { UserManagementConstants } from "../../constants";
import { InviteParentOrgUser } from "../guests/pages/invite-parent-org-user";

/**
* Interface for the Invite Parent Org User Wizard.
*/
interface InviteParentOrgUserWizardProps extends IdentifiableComponentInterface {
closeWizard: () => void;
[ "data-componentid" ]: string;
/**
* The Callback to trigger on user invite success.
*/
onUserInviteSuccess?: () => void;
}

export const InviteParentOrgUserWizard: FunctionComponent<InviteParentOrgUserWizardProps> = (
props: InviteParentOrgUserWizardProps
): ReactElement => {

const {
closeWizard,
onUserInviteSuccess,
[ "data-componentid" ]: componentId
} = props;

const { t } = useTranslation();
const [ isSubmitting, setIsSubmitting ] = useState<boolean>(false);
const [ alert, setAlert, alertComponent ] = useWizardAlert();

/**
* Triggers a form submit event for the form in the InviteParentOrgUser component.
*/
const submitParentUserInviteForm = () => {
document
.getElementById(UserManagementConstants.INVITE_PARENT_ORG_USER_FORM_ID)
.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
};

return (
<Modal
data-componentid={ componentId }
open
className="wizard application-create-wizard"
dimmer="blurring"
size="small"
onClose={ closeWizard }
closeOnDimmerClick={ false }
closeOnEscape
>
<Modal.Header className="wizard-header">
{ t("console:manage.features.parentOrgInvitations.addUserWizard.heading") }
<Heading as="h6">
{ t("console:manage.features.parentOrgInvitations.addUserWizard.description") }
</Heading>
</Modal.Header>
<Modal.Content className="content-container" scrolling>
{ alert && alertComponent }
<InviteParentOrgUser
closeWizard={ closeWizard }
setIsSubmitting={ setIsSubmitting }
onUserInviteSuccess={ onUserInviteSuccess }
setAlert={ setAlert }
data-componentid={ `${ componentId }-form` }
/>
</Modal.Content>
<Modal.Actions>
<Grid>
<Grid.Row column={ 1 }>
<Grid.Column mobile={ 8 }>
<LinkButton
data-componentid={ `${ componentId }-cancel-button` }
floated="left"
onClick={ () => {
closeWizard();
} }
>
{ t("common:cancel") }
</LinkButton>
</Grid.Column>
<Grid.Column mobile={ 8 } tablet={ 8 } computer={ 8 }>
<PrimaryButton
data-componentid={ `${ componentId }-finish-button` }
floated="right"
onClick={ submitParentUserInviteForm }
loading={ isSubmitting }
disabled={ isSubmitting }
>
{ t("extensions:manage.features.user.addUser.invite") }
</PrimaryButton>
</Grid.Column>
</Grid.Row>
</Grid>
</Modal.Actions>
</Modal>
);
};

Loading

0 comments on commit 7e6ff99

Please sign in to comment.