Skip to content

Commit

Permalink
feat(certificate): add certificate type
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhigarg-bmw committed Aug 28, 2023
1 parent 3df6537 commit fe5f8af
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@
"heading": "Zertifikate",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .",
"search": "Search",
"noUploadMessage": "No certificates available. All supported certificates are requested or active for your company.",
"tabs": {
"uploadedCertificates": "Uploaded Certificates",
"pending": "Pending",
Expand All @@ -1575,6 +1576,8 @@
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
"selectLabel": "Type of certificate",
"placeholder": "Please select",
"certificateTypeError": "Please select a value",
"noOptionsMessage": "No other options available",
"uploadDocumentTitle": "Please upload your certificate proof:",
"note": "Please upload only pdf files with maximum 1 MB.",
"descriptionLabel": "Description for verification",
Expand Down
3 changes: 3 additions & 0 deletions src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,7 @@
"heading": "Company Certificates",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .",
"search": "Search",
"noUploadMessage": "No certificates available. All supported certificates are requested or active for your company.",
"tabs": {
"uploadedCertificates": "Uploaded Certificates",
"pending": "Pending",
Expand All @@ -1514,6 +1515,8 @@
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
"selectLabel": "Type of certificate",
"placeholder": "Please select",
"certificateTypeError": "Please select a value",
"noOptionsMessage": "No other options available",
"uploadDocumentTitle": "Please upload your certificate proof:",
"note": "Please upload only pdf files with maximum 1 MB.",
"descriptionLabel": "Description for verification",
Expand Down
68 changes: 65 additions & 3 deletions src/components/overlays/UpdateCertificate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { useState } from 'react'
import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
import {
Expand All @@ -30,6 +30,8 @@ import {
DropAreaProps,
LoadingButton,
Typography,
SelectList,
Tooltips,
} from '@catena-x/portal-shared-components'
import { Box, Dialog } from '@mui/material'
import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'
Expand All @@ -39,17 +41,40 @@ import { closeOverlay, show } from 'features/control/overlay'
import { store } from 'features/store'
import { Dropzone } from '../../shared/basic/Dropzone'
import { error } from 'services/NotifyService'
import { useAddCertificateMutation } from 'features/certification/certificationApiSlice'
import {
useAddCertificateMutation,
useFetchCertificateTypesQuery,
} from 'features/certification/certificationApiSlice'
import './style.scss'

export type CertificateType = {
title: string
}

export default function UpdateCertificate({ id }: { id: string }) {
const { t } = useTranslation()
const dispatch = useDispatch<typeof store.dispatch>()
const [uploadedFile, setUploadedFile] = useState<File>()
const [submitClicked, setSubmitClicked] = useState<boolean>(false)
const [loading, setLoading] = useState<boolean>(false)
const [certificatetypesArr, setCertificatetypesArr] = useState<
CertificateType[]
>([])
const [selectedCertificate, setSelectedCertificate] = useState<string>('')

const [addCertificate] = useAddCertificateMutation()
const { data: certificateTypes } = useFetchCertificateTypesQuery()

useEffect(() => {
certificateTypes?.map((item) =>
setCertificatetypesArr((oldArray: CertificateType[]) => [
...oldArray,
{ title: item },
])
)
certificateTypes?.length === 1 &&
setSelectedCertificate(certificateTypes?.[0] ?? '')
}, [certificateTypes])

const renderDropArea = (props: DropAreaProps) => {
return <DropArea {...props} size="small" />
Expand Down Expand Up @@ -200,6 +225,43 @@ export default function UpdateCertificate({ id }: { id: string }) {

<DialogContent>
<div className="update-certificate">
{certificatetypesArr?.length && (
<Tooltips
additionalStyles={{
display:
certificatetypesArr.length === 1 ? 'block' : 'none',
}}
tooltipPlacement="bottom-start"
tooltipText={t(
'content.certificates.updateCertificate.noOptionsMessage'
)}
children={
<div>
<SelectList
error={!selectedCertificate}
helperText={t(
'content.certificates.updateCertificate.certificateTypeError'
)}
defaultValue={certificatetypesArr[0]}
items={certificatetypesArr}
label={t(
'content.certificates.updateCertificate.selectLabel'
)}
placeholder={
certificatetypesArr.length === 1
? certificatetypesArr[0].title
: t(
'content.certificates.updateCertificate.placeholder'
)
}
onChangeItem={(e) => setSelectedCertificate(e.title)}
keyTitle={'title'}
disabled={certificatetypesArr.length === 1}
/>
</div>
}
/>
)}
<Typography variant="h4" className="uploadDocumentTitle">
{t(
'content.certificates.updateCertificate.uploadDocumentTitle'
Expand Down Expand Up @@ -243,7 +305,7 @@ export default function UpdateCertificate({ id }: { id: string }) {
<Button
variant="contained"
onClick={handleSubmit}
disabled={uploadedFile === undefined}
disabled={uploadedFile === undefined || !selectedCertificate}
>
{t('global.actions.submit')}
</Button>
Expand Down
38 changes: 29 additions & 9 deletions src/components/pages/CertificateCredentials/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ import {
ViewSelector,
SortOption,
Button,
Tooltips,
} from '@catena-x/portal-shared-components'
import SortImage from 'components/shared/frame/SortImage'
import './CertificateCredentials.scss'
import { OVERLAYS } from 'types/Constants'
import { useFetchCertificatesQuery } from 'features/certification/certificationApiSlice'
import {
useFetchCertificateTypesQuery,
useFetchCertificatesQuery,
} from 'features/certification/certificationApiSlice'
import CertificateElements from './CertificateElements'

enum FilterType {
Expand Down Expand Up @@ -105,6 +109,7 @@ export default function CertificateCredentials() {
const { t } = useTranslation()

const { data } = useFetchCertificatesQuery()
const { data: certificateTypes } = useFetchCertificateTypesQuery()

const [{ searchExpr, showModal, selected, sortOption }, setState] =
useReducer(reducer, initialState)
Expand Down Expand Up @@ -221,14 +226,29 @@ export default function CertificateCredentials() {
</div>
</div>
<div className="uploadBtn">
<Button
size="small"
onClick={() =>
dispatch(show(OVERLAYS.UPDATE_CERTIFICATE, 'userId'))
}
>
{t('content.certificates.uploadCertificate')}
</Button>
{certificateTypes && (
<Tooltips
additionalStyles={{
cursor: 'pointer',
display: certificateTypes.length >= 0 ? 'none' : 'block',
}}
tooltipPlacement="top-start"
tooltipText={t('content.certificates.noUploadMessage')}
children={
<div>
<Button
size="small"
onClick={() =>
dispatch(show(OVERLAYS.UPDATE_CERTIFICATE, 'userId'))
}
disabled={certificateTypes.length <= 0}
>
{t('content.certificates.uploadCertificate')}
</Button>
</div>
}
/>
)}
</div>
<CertificateElements data={data} />
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/features/certification/certificationApiSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export const apiSlice = createApi({
method: 'PUT',
}),
}),
fetchCertificateTypes: builder.query<string[], void>({
query: () => '/api/administration/companydata/certificateTypes',
}),
}),
})

Expand All @@ -134,4 +137,5 @@ export const {
useFetchCredentialsSearchQuery,
useApproveCredentialMutation,
useDeclineCredentialMutation,
useFetchCertificateTypesQuery,
} = apiSlice

0 comments on commit fe5f8af

Please sign in to comment.