-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(service overview): add deactivate (#247)
- Loading branch information
1 parent
2d0a75a
commit c5c40aa
Showing
12 changed files
with
273 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
src/components/pages/ServiceReleaseProcess/components/ServiceDeactivate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
Oops, something went wrong.