-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(company certificate): create upload new certificate page (#447)
- Loading branch information
1 parent
0f1ee81
commit d796770
Showing
8 changed files
with
356 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,3 +171,13 @@ | |
width: 50%; | ||
} | ||
} | ||
|
||
.upload-certificate { | ||
.title { | ||
margin-top: 20px; | ||
} | ||
|
||
.date-picker { | ||
width: 100%; | ||
} | ||
} |
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
264 changes: 264 additions & 0 deletions
264
src/components/pages/CompanyCertificates/UploadCompanyCerificate.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,264 @@ | ||
/******************************************************************************** | ||
* 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 { useEffect, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
Dialog, | ||
Button, | ||
DialogActions, | ||
DialogContent, | ||
DialogHeader, | ||
DropArea, | ||
type DropAreaProps, | ||
LoadingButton, | ||
Typography, | ||
SelectList, | ||
Tooltips, | ||
Datepicker, | ||
type DateType, | ||
} from '@catena-x/portal-shared-components' | ||
import { Dropzone } from '../../shared/basic/Dropzone' | ||
import { error } from 'services/NotifyService' | ||
import { | ||
type CertificateTypes, | ||
useFetchCertificateTypesQuery, | ||
useUploadCertificateMutation, | ||
} from 'features/companyCertification/companyCertificateApiSlice' | ||
|
||
interface UploadCompanyCertificateProps { | ||
readonly handleClose: () => void | ||
} | ||
|
||
export default function UploadCompanyCertificate({ | ||
handleClose, | ||
}: UploadCompanyCertificateProps): JSX.Element { | ||
const { t } = useTranslation() | ||
const [uploadedFile, setUploadedFile] = useState<File>() | ||
const [selectedCertificateType, setSelectedCertificateType] = | ||
useState<CertificateTypes>() | ||
const [loading, setLoading] = useState<boolean>(false) | ||
const [dateError, setDateError] = useState<boolean>(false) | ||
const [uploadCertificate] = useUploadCertificateMutation() | ||
const { data: certificateTypes } = useFetchCertificateTypesQuery() | ||
|
||
useEffect(() => { | ||
if (certificateTypes != null && certificateTypes?.length > 0) { | ||
setSelectedCertificateType(certificateTypes[0]) | ||
} | ||
}, []) | ||
|
||
const renderDropArea = (props: DropAreaProps): JSX.Element => { | ||
return <DropArea {...props} size="small" /> | ||
} | ||
|
||
const handleSubmit = async (): Promise<void> => { | ||
setLoading(true) | ||
try { | ||
if (uploadedFile != null) { | ||
const data = { | ||
certificateType: | ||
selectedCertificateType != null | ||
? selectedCertificateType.certificateType | ||
: '', | ||
document: uploadedFile, | ||
id: '', | ||
} | ||
await uploadCertificate(data).unwrap() | ||
handleClose() | ||
} | ||
// Add an ESLint exception until there is a solution | ||
// eslint-disable-next-line | ||
} catch (err: any) { | ||
setLoading(false) | ||
error( | ||
t('content.certificates.updateCertificate.error') + | ||
err.data.errors.unknown[0], | ||
'', | ||
'' | ||
) | ||
} | ||
} | ||
|
||
return ( | ||
<Dialog open={true}> | ||
<DialogHeader | ||
{...{ | ||
title: t('content.companyCertificate.upload.title'), | ||
intro: t('content.companyCertificate.upload.description'), | ||
closeWithIcon: true, | ||
onCloseWithIcon: () => { | ||
handleClose() | ||
}, | ||
}} | ||
/> | ||
|
||
<DialogContent> | ||
<div className="upload-certificate"> | ||
<Typography variant="h4" className="title"> | ||
{t('content.companyCertificate.upload.certificateTypeTitle')} | ||
</Typography> | ||
<SelectList | ||
error={selectedCertificateType == null} | ||
helperText={t( | ||
'content.companyCertificate.upload.certificateTypeError' | ||
)} | ||
defaultValue={certificateTypes?.[0]} | ||
items={certificateTypes ?? []} | ||
label={t('content.companyCertificate.upload.certificateTypeLabel')} | ||
placeholder={ | ||
certificateTypes?.length === 1 | ||
? certificateTypes[0].certificateType | ||
: t( | ||
'content.companyCertificate.upload.certificateTypePlaceholder' | ||
) | ||
} | ||
onChangeItem={(e: CertificateTypes) => { | ||
setSelectedCertificateType(e) | ||
}} | ||
keyTitle={'certificateType'} | ||
disabled={certificateTypes?.length === 1} | ||
/> | ||
<Typography variant="h4" className="title"> | ||
{t('content.companyCertificate.upload.certificateSiteTitle')} | ||
</Typography> | ||
<Tooltips | ||
additionalStyles={{ | ||
display: 'block', | ||
}} | ||
tooltipPlacement="bottom-end" | ||
tooltipText={t('content.companyCertificate.upload.comingsoon')} | ||
> | ||
<span> | ||
<SelectList | ||
error={false} | ||
helperText={t( | ||
'content.companyCertificate.upload.certificateSiteError' | ||
)} | ||
defaultValue={{}} | ||
items={[]} | ||
label={t( | ||
'content.companyCertificate.upload.certificateSiteLabel' | ||
)} | ||
placeholder={t( | ||
'content.companyCertificate.upload.certificateSitePlaceholder' | ||
)} | ||
onChangeItem={(e) => { | ||
// do nothing | ||
}} | ||
keyTitle={'certificateSite'} | ||
disabled={true} | ||
/> | ||
</span> | ||
</Tooltips> | ||
<Typography | ||
variant="h4" | ||
className="title" | ||
sx={{ | ||
marginBottom: '20px', | ||
}} | ||
> | ||
{t('content.companyCertificate.upload.expiry')} | ||
</Typography> | ||
<Datepicker | ||
placeholder={t('content.companyCertificate.upload.dateplaceholder')} | ||
locale="en" | ||
error={dateError} | ||
helperText={ | ||
dateError ? t('content.companyCertificate.upload.dateError') : '' | ||
} | ||
readOnly={false} | ||
inputFormat={'dd-MM-yyyy'} | ||
onChangeItem={(items: DateType) => { | ||
if (items != null && items < new Date()) { | ||
setDateError(true) | ||
} else { | ||
setDateError(false) | ||
} | ||
}} | ||
label={''} | ||
/> | ||
<Typography | ||
variant="h4" | ||
className="title" | ||
sx={{ | ||
marginBottom: '20px', | ||
}} | ||
> | ||
{t('content.companyCertificate.upload.uploadDocumentTitle')} | ||
</Typography> | ||
<Dropzone | ||
acceptFormat={{ 'application/pdf': [] }} | ||
maxFilesToUpload={1} | ||
maxFileSize={2097152} | ||
onChange={([file]) => { | ||
setUploadedFile(file) | ||
}} | ||
errorText={t( | ||
'content.usecaseParticipation.editUsecase.fileSizeError' | ||
)} | ||
DropStatusHeader={false} | ||
DropArea={renderDropArea} | ||
/> | ||
<div className="note"> | ||
<Typography variant="label2"> | ||
{t('content.companyCertificate.upload.note')} | ||
</Typography> | ||
</div> | ||
</div> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
variant="outlined" | ||
onClick={() => { | ||
handleClose() | ||
}} | ||
> | ||
{t('global.actions.close')} | ||
</Button> | ||
|
||
{loading ? ( | ||
<LoadingButton | ||
color="primary" | ||
helperText="" | ||
helperTextColor="success" | ||
label="" | ||
loadIndicator="Loading ..." | ||
loading | ||
size="medium" | ||
onButtonClick={() => { | ||
// do nothing | ||
}} | ||
sx={{ marginLeft: '10px' }} | ||
/> | ||
) : ( | ||
<Button | ||
variant="contained" | ||
onClick={handleSubmit} | ||
disabled={ | ||
uploadedFile === undefined || selectedCertificateType == null | ||
} | ||
> | ||
{t('global.actions.submit')} | ||
</Button> | ||
)} | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} |
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
Oops, something went wrong.