Skip to content

Commit

Permalink
feat(company certificate): create upload new certificate page (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
manojava-gk authored Jan 26, 2024
1 parent 0f1ee81 commit d796770
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Provide new link from user menu for the company certificate page
- UI components created to display filter, sort and company certificates
- Company Certificate Details overlay
- Upload new Company Certificate overlay
- Company Roles
- Fetch the standard library data from standards.json and implement Table component to display it in the company roles section.

Expand Down
18 changes: 18 additions & 0 deletions src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,24 @@
"fileUpload": "File Upload",
"verification": "Verification"
},
"upload": {
"title": "Upload new certificate",
"description": "Select the certificate flow and upload your company certificate below. Please note - you are responsible for the certificate validity - only upload valid and official documents.",
"certificateTypeTitle": "Certificate Type",
"certificateTypeError": "",
"certificateTypeLabel": "",
"certificateTypePlaceholder": "Please select",
"certificateSiteTitle": "Certificate Site/Level",
"certificateSiteError": "",
"certificateSiteLabel": "",
"certificateSitePlaceholder": "Please select",
"uploadDocumentTitle": "Certificate file upload",
"note": "",
"comingsoon": "Coming soon",
"expiry": "Expiry Date",
"dateplaceholder": "Enter a Date",
"dateError": "Select a valid date"
},
"uploadCertificate": "Upload Certificate",
"noData": "Currently there are no certificates for the company. You can start uploading a certificate by clicking the 'Upload Certificate' button above.",
"validtill": "Valid Till",
Expand Down
18 changes: 18 additions & 0 deletions src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,24 @@
"fileUpload": "File Upload",
"verification": "Verification"
},
"upload": {
"title": "Upload new certificate",
"description": "Select the certificate flow and upload your company certificate below. Please note - you are responsible for the certificate validity - only upload valid and official documents.",
"certificateTypeTitle": "Certificate Type",
"certificateTypeError": "",
"certificateTypeLabel": "",
"certificateTypePlaceholder": "Please select",
"certificateSiteTitle": "Certificate Site/Level",
"certificateSiteError": "",
"certificateSiteLabel": "",
"certificateSitePlaceholder": "Please select",
"uploadDocumentTitle": "Certificate file upload",
"note": "",
"comingsoon": "Coming soon",
"expiry": "Expiry Date",
"dateplaceholder": "Enter a Date",
"dateError": "Select a valid date"
},
"uploadCertificate": "Upload Certificate",
"noData": "Currently there are no certificates for the company. You can start uploading a certificate by clicking the 'Upload Certificate' button above.",
"validtill": "Valid Till",
Expand Down
10 changes: 10 additions & 0 deletions src/components/pages/CompanyCertificates/CompanyCertificate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,13 @@
width: 50%;
}
}

.upload-certificate {
.title {
margin-top: 20px;
}

.date-picker {
width: 100%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function CompanyCertificateCard({
const [dotsMenu, setDotsMenu] = useState(false)
const dispatch = useDispatch()

const handleView = () =>
const handleView = (): unknown =>
dispatch(show(OVERLAYS.COMPANY_CERTIFICATE_DETAILS, item.documentId))
return (
<Box className="card-container">
Expand Down
264 changes: 264 additions & 0 deletions src/components/pages/CompanyCertificates/UploadCompanyCerificate.tsx
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>
)
}
11 changes: 10 additions & 1 deletion src/components/pages/CompanyCertificates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import UserService from 'services/UserService'
import { useFetchCertificatesQuery } from 'features/companyCertification/companyCertificateApiSlice'
import { useState } from 'react'
import { Box } from '@mui/material'
import UploadCompanyCertificate from './UploadCompanyCerificate'

interface TabButtonsType {
buttonText: string
Expand Down Expand Up @@ -60,6 +61,7 @@ export default function CompanyCertificates(): JSX.Element {
const [showModal, setShowModal] = useState<boolean>(false)
const [sortOption, setSortOption] = useState<string>(SortType.NEW)
const [filter, setFilter] = useState<string>(FilterType.ALL)
const [uploadModal, setUploadModal] = useState<boolean>(false)

const setBtnView = (e: React.MouseEvent<HTMLInputElement>): void => {
setFilter(e.currentTarget.value)
Expand Down Expand Up @@ -144,7 +146,7 @@ export default function CompanyCertificates(): JSX.Element {
<Button
size="small"
onClick={() => {
// no action
setUploadModal(true)
}}
disabled={
!UserService.hasRole(ROLES.UPLOAD_COMPANY_CERTIFICATE)
Expand All @@ -156,6 +158,13 @@ export default function CompanyCertificates(): JSX.Element {
</Box>
</Box>
{data != null && <CompanyCertificateElements data={data.content} />}
{uploadModal && (
<UploadCompanyCertificate
handleClose={() => {
setUploadModal(false)
}}
/>
)}
</Box>
</Box>
</main>
Expand Down
Loading

0 comments on commit d796770

Please sign in to comment.