Skip to content

Commit

Permalink
fix(app release process): enhance add technical user process (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
manojava-gk authored Jan 13, 2025
1 parent a2bd5a6 commit 1177eb4
Show file tree
Hide file tree
Showing 7 changed files with 552 additions and 208 deletions.
20 changes: 18 additions & 2 deletions src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,22 @@
"roleUpdateError": "Error while updating roles",
"encoding": "Encoding(select supported encoding)",
"encodingPlaceholder": "Select supported encoding",
"noneOption": "Nicht notwendig (für die Integration ist kein technischer User notwendig)"
"noneOption": "Nicht notwendig (für die Integration ist kein technischer User notwendig)",
"table": {
"addtechUserButton": "Neuen technischen Benutzer hinzufügen",
"title": "Technical Users",
"type": "Type",
"role": "Role",
"noRoles": "Keine technischen Benutzer hinzugefügt"
},
"form": {
"title": "Technischen Benutzer konfigurieren",
"intro": "Wählen Sie interne oder externe Rollen aus und fahren Sie mit der Konfiguration des technischen Benutzers fort",
"internalUserRoles": "Interner technischer Benutzer",
"internalUserRolesDescription": "Interne technische Benutzer werden in der direkten Umgebung des Portals erstellt und können daher mehrere Rollen haben",
"externalUserRoles": "Externer technischer Benutzer",
"externalUserRolesDescription": "Externe technische Benutzer werden in einer externen Umgebung erstellt und können daher nur eine Rolle haben"
}
},
"betaTest": {
"headerTitle": "CX Test Runs",
Expand Down Expand Up @@ -2400,7 +2415,8 @@
"loading": "Loading...",
"unsubscribe": "Unsubscribe",
"edit": "Edit",
"copyInfoSuccessMessage": "Information erfolgreich kopiert"
"copyInfoSuccessMessage": "Information erfolgreich kopiert",
"continue": "Continue"
},
"state": {
"enabled": "aktiv",
Expand Down
20 changes: 18 additions & 2 deletions src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,22 @@
"roleUpdateError": "Error while updating roles",
"encoding": "Encoding(select supported encoding)",
"encodingPlaceholder": "Select supported encoding",
"noneOption": "none (no technical user needed to run the app/service)"
"noneOption": "none (no technical user needed to run the app/service)",
"table": {
"addtechUserButton": "Configure Technical User",
"title": "Technical Users",
"type": "Type",
"role": "Role",
"noRoles": "No technical users added"
},
"form": {
"title": "Configure Technical User",
"intro": "Select internal or external roles and continue to configure technical user",
"internalUserRoles": "Internal technical user",
"internalUserRolesDescription": "Internal technical user are created in the direct environment of the portal therefore can have multiple roles",
"externalUserRoles": "External technical user",
"externalUserRolesDescription": "External technical user are created in external environment therefore can only have one role"
}
},
"betaTest": {
"headerTitle": "CX Test Runs",
Expand Down Expand Up @@ -2375,7 +2390,8 @@
"loading": "Loading...",
"unsubscribe": "Unsubscribe",
"edit": "Edit",
"copyInfoSuccessMessage": "Information copied successfully"
"copyInfoSuccessMessage": "Information copied successfully",
"continue": "Continue"
},
"state": {
"enabled": "enabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { Typography, Checkbox, Radio } from '@catena-x/portal-shared-components'
import { Typography } from '@catena-x/portal-shared-components'
import { useTranslation } from 'react-i18next'
import SnackbarNotificationWithButtons from '../components/SnackbarNotificationWithButtons'
import { Grid } from '@mui/material'
Expand All @@ -40,6 +40,8 @@ import { useForm } from 'react-hook-form'
import { ButtonLabelTypes } from '..'
import { setServiceStatus } from 'features/serviceManagement/actions'
import { error, success } from 'services/NotifyService'
import { TechUserTable } from '../TechnicalIntegration/TechUserTable'
import { AddTechUserForm } from '../TechnicalIntegration/AddTechUserForm'

export default function OfferTechnicalIntegration() {
const { t } = useTranslation('servicerelease')
Expand Down Expand Up @@ -88,36 +90,7 @@ export default function OfferTechnicalIntegration() {
mode: 'onChange',
})

const handleUserProfiles = (item: string, checked: boolean) => {
if (
serviceTechUserProfiles &&
serviceTechUserProfiles[0] === serviceTechnicalUserNone
) {
setServiceTechUserProfiles([...[], item])
} else {
const isSelected = serviceTechUserProfiles?.includes(item)
let selectedProfiles: string[] = []
if (!isSelected && checked) {
selectedProfiles = [...serviceTechUserProfiles, item]
} else if (isSelected && !checked) {
const oldTechUserProfiles = [...serviceTechUserProfiles]
oldTechUserProfiles.splice(oldTechUserProfiles.indexOf(item), 1)
selectedProfiles = [...oldTechUserProfiles]
}
setErrorMessage(selectedProfiles?.length === 0)
setServiceTechUserProfiles(selectedProfiles)
}
}

const selectProfiles = (type: string, checked: boolean, item: string) => {
if (type === 'radio') {
setServiceTechUserProfiles([...[], item])
} else if (type === 'checkbox') {
handleUserProfiles(item, checked)
}
}

const onSubmit = async (_submitData: unknown, buttonLabel: string) => {
const onSubmit = (_submitData: unknown, buttonLabel: string) => {
if (
!fetchServiceStatus?.serviceTypeIds.every((item) =>
[`${ServiceTypeIdsEnum.CONSULTANCY_SERVICE}`]?.includes(item)
Expand All @@ -135,40 +108,6 @@ export default function OfferTechnicalIntegration() {
) {
buttonLabel === ButtonLabelTypes.SAVE_AND_PROCEED &&
dispatch(serviceReleaseStepIncrement())
} else if (
!(
serviceTechUserProfiles.length === userProfiles.length &&
serviceTechUserProfiles.every((item) => userProfiles?.includes(item))
)
) {
setLoading(true)
const updateData = {
serviceId,
body: [
{
technicalUserProfileId: data?.[0]?.technicalUserProfileId ?? null,
userRoleIds:
serviceTechUserProfiles &&
serviceTechUserProfiles[0] === serviceTechnicalUserNone
? []
: serviceTechUserProfiles,
},
],
}
if (updateData)
await saveServiceTechnicalUserProfiles(updateData)
.unwrap()
.then(() => {
setErrorMessage(false)
refetch()
buttonLabel === ButtonLabelTypes.SAVE_AND_PROCEED
? dispatch(serviceReleaseStepIncrement())
: success(t('serviceReleaseForm.dataSavedSuccessMessage'))
})
.catch((err) => {
error(t('technicalIntegration.technicalUserProfileError'), '', err)
})
setLoading(false)
}
}

Expand All @@ -177,6 +116,35 @@ export default function OfferTechnicalIntegration() {
dispatch(serviceReleaseStepDecrement())
}

const [showTechUser, setShowTechUser] = useState<boolean>(false)

const handleUserProfiles = async (roles: string[]) => {
setShowTechUser(false)
setLoading(true)
const updateData = {
serviceId,
body: [
{
technicalUserProfileId: data?.[0]?.technicalUserProfileId ?? null,
userRoleIds:
roles && roles[0] === serviceTechnicalUserNone ? [] : roles,
},
],
}
if (updateData)
await saveServiceTechnicalUserProfiles(updateData)
.unwrap()
.then(() => {
setErrorMessage(false)
refetch()
success(t('serviceReleaseForm.dataSavedSuccessMessage'))
})
.catch((err) => {
error(t('technicalIntegration.technicalUserProfileError'), '', err)
})
setLoading(false)
}

return (
<>
<Typography variant="h3" mt={10} mb={4} align="center">
Expand All @@ -191,40 +159,23 @@ export default function OfferTechnicalIntegration() {
</Grid>

<form className="header-description">
<Grid container spacing={1.5} item>
{fetchServiceUserRoles?.map((item) => (
<Grid item md={12} className="userRoles" key={item.roleId}>
<Checkbox
label={`${item.roleName} (${item.roleDescription ?? ''})`}
checked={serviceTechUserProfiles.some(
(role) => item.roleId === role
)}
onChange={(e) => {
selectProfiles('checkbox', e.target.checked, item.roleId)
}}
size="small"
/>
</Grid>
))}
<Grid item md={12} className="userRoles">
<Radio
name="radio-buttons"
size="small"
checked={
serviceTechUserProfiles &&
serviceTechUserProfiles[0] === serviceTechnicalUserNone
}
label={`${t('technicalIntegration.noneOption')}`}
onChange={(e) => {
selectProfiles(
'radio',
e.target.checked,
serviceTechnicalUserNone
)
}}
/>
</Grid>
</Grid>
{data && (
<TechUserTable
userProfiles={data}
handleAddTechUser={() => {
setShowTechUser(true)
}}
/>
)}
{fetchServiceUserRoles && showTechUser && data && (
<AddTechUserForm
userProfiles={data[0]?.userRoles ?? []}
handleClose={() => {
setShowTechUser(false)
}}
handleConfirm={handleUserProfiles}
/>
)}

{errorMessage && (
<Typography variant="body2" className="file-error-msg">
Expand All @@ -245,10 +196,12 @@ export default function OfferTechnicalIntegration() {
pageSnackbar={techIntegrationSnackbar}
setPageSnackbar={setTechIntegrationSnackbar}
onBackIconClick={onBackIconClick}
onSave={handleSubmit((data) => onSubmit(data, ButtonLabelTypes.SAVE))}
onSaveAndProceed={handleSubmit((data) =>
onSave={handleSubmit((data) => {
onSubmit(data, ButtonLabelTypes.SAVE)
})}
onSaveAndProceed={handleSubmit((data) => {
onSubmit(data, ButtonLabelTypes.SAVE_AND_PROCEED)
)}
})}
isValid={serviceTechUserProfiles?.length > 0}
loader={loading}
helpUrl={
Expand Down
Loading

0 comments on commit 1177eb4

Please sign in to comment.