Skip to content

Commit

Permalink
feat(service overview): add deactivate (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
lavanya-bmw authored Sep 20, 2023
1 parent 2d0a75a commit c5c40aa
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Enable credential reset
- Serview Overview
- Added Sub menu for active services in service overview
- Added Deactivate functionality
- Added image to service overview cards
- Data Space
- Last section background color issue
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
},
"dependencies": {
"@catena-x/portal-shared-components": "^2.0.27",
"@catena-x/portal-shared-components": "^2.0.29",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@hookform/error-message": "^2.0.1",
Expand Down
15 changes: 15 additions & 0 deletions src/assets/locales/de/servicerelease.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"loadmore": "Mehr laden",
"documentDeleteSuccess": "Document deleted successfully",
"documentDeleteError": "Something went wrong.",
"global": {
"actions": {
"confirm": "Bestätigen",
"cancel": "Stornieren",
"save": "Speichern"
}
},
"stepper": {
"marketCard": "Offer Card",
"servicePage": "Offer Page Details",
Expand Down Expand Up @@ -120,6 +127,14 @@
"submenuNotAvailable": "Sub-Menu is not available for not active apps.",
"sortOptions": {
"deactivate": "Deactivate"
},
"serviceDeactivate": {
"headerTitle": "Dienst deaktivieren",
"description": "Durch die Deaktivierung des Dienstes wird das Serviceangebot auf dem Catena-X-Marktplatz deaktiviert. Alle derzeit aktiven Abonnements bleiben aktiv und die Kunden sind von der Deaktivierung nicht betroffen. Neue Abonnements sind nicht möglich.",
"checkboxLabel": "Hiermit bestätige ich, dass ich die Geschäftsbedingungen für Business-Services gelesen habe und dass ich die Business-Services meines Unternehmens mit sofortiger Wirkung vom Marktplatz deaktiviere. Ich verstehe, dass es nicht möglich ist, die Deaktivierung selbst rückgängig zu machen.",
"checkboxErrorMsg": "Bitte bestätigen Sie, dass Sie die oben genannten Auswirkungen der Deaktivierung gelesen haben, bevor Sie fortfahren",
"successMsg": "Deaktivierung erfolgreich abgeschlossen",
"errorMsg": "Fehler! Etwas ist schief gelaufen"
}
},
"servicedetails": {
Expand Down
15 changes: 15 additions & 0 deletions src/assets/locales/en/servicerelease.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"loadmore": "Load More",
"documentDeleteSuccess": "Document deleted successfully",
"documentDeleteError": "Something went wrong.",
"global": {
"actions": {
"confirm": "Confirm",
"cancel": "Cancel",
"save": "Save"
}
},
"stepper": {
"marketCard": "Offer Card",
"servicePage": "Offer Page Details",
Expand Down Expand Up @@ -120,6 +127,14 @@
"submenuNotAvailable": "Sub-Menu is not available for not active apps.",
"sortOptions": {
"deactivate": "Deactivate"
},
"serviceDeactivate": {
"headerTitle": "Deactivate Service",
"description": "Deactivation of service will deactivate the service offer inside the Catena-X marketplace. Any current active subscription will stay active and customers wont be effected by the deactivation. New subscriptions are not possible.",
"checkboxLabel": "Hereby I confirm that I have read the business service terms and conditions and that I am deactivating my company business services from the marketplace with immediate effect. I understand that it is not possible to self-reverse the deactivation.",
"checkboxErrorMsg": "Please confirm that you have read the deactivation impact above before proceeding",
"successMsg": "Deactivation successfully completed",
"errorMsg": "Error! Something went wrong"
}
},
"servicedetails": {
Expand Down
18 changes: 9 additions & 9 deletions src/components/pages/AppOverview/AddRolesOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ const AddRolesOverlay = ({
})
}

const handleClose = () => {
handleOverlayClose()
setRolesPreviews([])
setRolesDescription([])
setUploadCSVError(false)
}

return (
<div className="detailsOverlay">
<Dialog
Expand All @@ -169,9 +176,7 @@ const AddRolesOverlay = ({
title={t('content.addRoles.uploadAdditionalRoles')}
intro={t('content.addRoles.uploadAdditionalRolesDescription')}
closeWithIcon={true}
onCloseWithIcon={() => {
handleOverlayClose()
}}
onCloseWithIcon={() => handleClose()}
/>
<DialogContent
sx={{
Expand Down Expand Up @@ -256,12 +261,7 @@ const AddRolesOverlay = ({
</Typography>
</DialogContent>
<DialogActions>
<Button
variant="outlined"
onClick={() => {
handleOverlayClose()
}}
>
<Button variant="outlined" onClick={() => handleClose()}>
{t('global.actions.cancel')}
</Button>

Expand Down
43 changes: 9 additions & 34 deletions src/components/pages/AppOverview/Deactivate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import {
import { useTranslation } from 'react-i18next'
import { useLocation, useNavigate, useParams } from 'react-router-dom'
import { Box } from '@mui/material'
import { useCallback, useEffect, useState } from 'react'
import { useState } from 'react'
import { useDeactivateAppMutation } from 'features/apps/apiSlice'
import { useFetchDocumentByIdMutation } from 'features/appManagement/apiSlice'
import { error } from 'services/NotifyService'
import { getApiBase } from 'services/EnvironmentService'
import { fetchImageWithToken } from 'services/ImageService'

export default function Deactivate() {
const { t } = useTranslation()
Expand All @@ -46,36 +46,8 @@ export default function Deactivate() {
const items: any = state
const app = items?.filter((item: any) => item.id === appId)
const [deactivateApp] = useDeactivateAppMutation()
const [deactivateCardImage, setDeactivateCardImage] = useState('')
const [fetchDocumentById] = useFetchDocumentByIdMutation()
const leadImageId = app?.[0]?.leadPictureId

const fetchImage = useCallback(
async (documentId: string, docType: string) => {
try {
const response = await fetchDocumentById({
appId: appId ?? '',
documentId,
})
if (response && 'data' in response) {
const file = response?.data?.data
if (docType === 'APP_LEADIMAGE') {
return setDeactivateCardImage(URL.createObjectURL(file))
}
}
} catch (err) {
error('ERROR WHILE FETCHING IMAGE', '', err as object)
}
},
[fetchDocumentById, appId]
)

useEffect(() => {
if (leadImageId) {
fetchImage(leadImageId, 'APP_LEADIMAGE')
}
}, [fetchImage, leadImageId])

const handleSaveClick = async () => {
setIsLoading(true)
await deactivateApp(app[0].id)
Expand Down Expand Up @@ -115,16 +87,19 @@ export default function Deactivate() {
<Box sx={{ width: '50%' }}>
<Card
image={{
src: deactivateCardImage,
src: `${getApiBase()}/api/apps/${
appId ?? ''
}/appDocuments/${leadImageId}`,
}}
title={app[0]?.title || ''}
subtitle={app[0]?.provider}
variant="minimal"
expandOnHover={false}
buttonText={''}
variant="minimal"
filledBackground={false}
imageShape="round"
filledBackground={false}
imageSize="small"
imageLoader={fetchImageWithToken}
/>
</Box>
<Box sx={{ marginTop: '10%' }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/********************************************************************************
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { PageBreadcrumb } from 'components/shared/frame/PageBreadcrumb/PageBreadcrumb'
import {
Typography,
PageHeader,
Card,
Checkbox,
Button,
Tooltips,
LoadingButton,
} from '@catena-x/portal-shared-components'
import { useTranslation } from 'react-i18next'
import { useLocation, useNavigate, useParams } from 'react-router-dom'
import { Box } from '@mui/material'
import { useState } from 'react'
import {
ServiceDeactivateEnum,
useDeactivateServiceMutation,
} from 'features/serviceManagement/apiSlice'
import { PAGES } from 'types/Constants'
import { getApiBase } from 'services/EnvironmentService'
import { fetchImageWithToken } from 'services/ImageService'

export default function ServiceDeactivate() {
const { t } = useTranslation('servicerelease')
const navigate = useNavigate()
const serviceId = useParams().serviceId
const [checked, setChecked] = useState(false)
const { state } = useLocation()
const [isLoading, setIsLoading] = useState(false)
const items: any = state
const service = items?.filter((item: any) => item.id === serviceId)
const [deactivateService] = useDeactivateServiceMutation()
const leadImageId = service?.[0]?.leadPictureId

const handleSaveClick = async () => {
setIsLoading(true)
await deactivateService(service[0].id)
.unwrap()
.then(() =>
navigate(`/${PAGES.SERVICEOVERVIEW}`, {
state: ServiceDeactivateEnum.SERVICE_DEACTIVATE_SUCCESS,
})
)
.catch((error) =>
navigate(`/${PAGES.SERVICEOVERVIEW}`, {
state: ServiceDeactivateEnum.SERVICE_DEACTIVATE_ERROR,
})
)
}

return (
<main className="deactivate-main">
<PageHeader title={service?.[0]?.title} topPage={true} headerHeight={200}>
<PageBreadcrumb backButtonVariant="contained" />
</PageHeader>
<section>
<Typography variant="body2" mb={3} align="center">
{service?.[0]?.title}
</Typography>
<Typography variant="h2" mb={3} align="center">
{t('serviceoverview.serviceDeactivate.headerTitle')}
</Typography>
<Typography variant="body2" align="center">
{t('serviceoverview.serviceDeactivate.description')}
</Typography>
</section>
<div className="mainContainer">
<div className="mainRow">
{service && (
<Box sx={{ display: 'flex' }}>
<Box sx={{ width: '50%' }}>
<Card
image={{
src: `${getApiBase()}/api/administration/documents/${leadImageId}`,
}}
title={service[0]?.title || ''}
subtitle={service[0]?.provider}
variant="minimal"
expandOnHover={false}
buttonText={''}
imageShape="round"
imageLoader={fetchImageWithToken}
filledBackground={false}
imageSize="small"
/>
</Box>
<Box sx={{ marginTop: '10%' }}>
<Checkbox
label={`${t(
'serviceoverview.serviceDeactivate.checkboxLabel'
)}`}
onChange={(e) =>
e.target.checked ? setChecked(true) : setChecked(false)
}
key={service[0].id}
className="checkbox-input"
/>
</Box>
</Box>
)}
</div>
</div>
<section>
<hr style={{ border: 0, borderTop: '1px solid #DCDCDC' }} />
<Box sx={{ position: 'relative', marginTop: '30px' }}>
<Button
size="small"
color="secondary"
onClick={() => navigate('/serviceoverview')}
>
{t('global.actions.cancel')}
</Button>
<Tooltips
tooltipPlacement="bottom-start"
tooltipText={
!checked
? t('serviceoverview.serviceDeactivate.checkboxErrorMsg')
: ''
}
children={
<span style={{ position: 'absolute', right: '10px' }}>
{isLoading ? (
<LoadingButton
loading={isLoading}
loadIndicator="Loading..."
variant="contained"
size="small"
onButtonClick={() => {}}
label={`${t('global.actions.confirm')}`}
/>
) : (
<Button
size="small"
onClick={handleSaveClick}
variant="contained"
disabled={!checked}
>
{t('global.actions.save')}
</Button>
)}
</span>
}
/>
</Box>
</section>
</main>
)
}
Loading

0 comments on commit c5c40aa

Please sign in to comment.