diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e0506f13..eafb31a76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Created New page under User profile - Add edit Overlay UI - Fetech usecase via API + - Add Business Logic to upload document - Service Release Process - Service Release process not working - Service details page crash issue diff --git a/src/assets/locales/de/main.json b/src/assets/locales/de/main.json index 9f99bdc5b..087b5604d 100644 --- a/src/assets/locales/de/main.json +++ b/src/assets/locales/de/main.json @@ -1450,9 +1450,11 @@ "framework": "Framework", "expiry": "Expiry: {{expiry}}", "editUsecase": { - "title": "Trigger the use case participation by signing and uploading the use case frame agreement for {use case name}", - "description": "To be able to participate in the data exchange of the use case {use case name} please download the use case frame agreement {placeholder until download is available} and upload the signed document in the upload window below.After submission, the platform owner will validate the uploaded document you will be informed as soon as the validation is successfully finished", - "checkboxLabel": "Yes, I confirm that I have uploaded the signed use case frameagreement" + "title": "Trigger the use case participation by signing and uploading the use case frame agreement for {{usecaseName}}", + "description": "To be able to participate in the data exchange of the use case {{usecaseName}} please download the use case frame agreement {placeholder until download is available} and upload the signed document in the upload window below.After submission, the platform owner will validate the uploaded document you will be informed as soon as the validation is successfully finished", + "checkboxLabel": "Yes, I confirm that I have uploaded the signed use case frameagreement", + "error": "Something went wrong!", + "success": "Usecase document upload has been done successfully." } }, "certificates": { diff --git a/src/assets/locales/en/main.json b/src/assets/locales/en/main.json index 6c9744281..2ffdbc959 100644 --- a/src/assets/locales/en/main.json +++ b/src/assets/locales/en/main.json @@ -1412,9 +1412,11 @@ "framework": "Framework", "expiry": "Expiry: {{expiry}}", "editUsecase": { - "title": "Trigger the use case participation by signing and uploading the use case frame agreement for {use case name}", - "description": "To be able to participate in the data exchange of the use case {use case name} please download the use case frame agreement {placeholder until download is available} and upload the signed document in the upload window below.After submission, the platform owner will validate the uploaded document you will be informed as soon as the validation is successfully finished", - "checkboxLabel": "Yes, I confirm that I have uploaded the signed use case frameagreement" + "title": "Trigger the use case participation by signing and uploading the use case frame agreement for {{usecaseName}}", + "description": "To be able to participate in the data exchange of the use case {{usecaseName}} please download the use case frame agreement {placeholder until download is available} and upload the signed document in the upload window below.After submission, the platform owner will validate the uploaded document you will be informed as soon as the validation is successfully finished", + "checkboxLabel": "Yes, I confirm that I have uploaded the signed use case frameagreement", + "error": "Something went wrong!", + "success": "Usecase document upload has been done successfully." } }, "certificates": { diff --git a/src/components/overlays/EditUsecase/index.tsx b/src/components/overlays/EditUsecase/index.tsx index 7026b08c9..1b1698e13 100644 --- a/src/components/overlays/EditUsecase/index.tsx +++ b/src/components/overlays/EditUsecase/index.tsx @@ -17,6 +17,10 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +import { useState } from 'react' +import { useTranslation } from 'react-i18next' +import i18next from 'i18next' +import { useDispatch } from 'react-redux' import { Button, Checkbox, @@ -25,37 +29,64 @@ import { DialogHeader, DropArea, DropAreaProps, + LoadingButton, } from '@catena-x/portal-shared-components' -import { useTranslation } from 'react-i18next' -import { fetchAny } from 'features/admin/userOwn/actions' -import { useEffect, useState } from 'react' -import { useDispatch } from 'react-redux' -import './style.scss' +import { error, success } from 'services/NotifyService' import { OVERLAYS } from 'types/Constants' -import { show } from 'features/control/overlay' +import { closeOverlay, show } from 'features/control/overlay' import { store } from 'features/store' import { Dropzone } from '../../shared/basic/Dropzone' +import { useAddUsecaseMutation } from 'features/usecase/usecaseApiSlice' +import './style.scss' -export default function EditUsecase({ id }: { id: string }) { +export default function EditUsecase({ + id: verifiedCredentialTypeId, + title: credentialType, +}: { + id: string + title: string +}) { const { t } = useTranslation() const dispatch = useDispatch() - const [uploadedFile, setUploadedFile] = useState() + const [uploadedFile, setUploadedFile] = useState() const [checked, setChecked] = useState(false) + const [loading, setLoading] = useState(false) - useEffect(() => { - dispatch(fetchAny(id)) - }, [dispatch, id]) + const [addUsecase] = useAddUsecaseMutation() const renderDropArea = (props: DropAreaProps) => { return } + const handleUpload = async () => { + setLoading(true) + try { + const data = { + verifiedCredentialTypeId: verifiedCredentialTypeId, + credentialType: credentialType, + document: uploadedFile, + } + await addUsecase(data).unwrap() + setLoading(false) + dispatch(closeOverlay()) + success(t('content.usecaseParticipation.editUsecase.success')) + } catch (err) { + setLoading(false) + error(t('content.usecaseParticipation.editUsecase.error'), '', '') + } + } + return ( <> dispatch(show(OVERLAYS.NONE, '')), }} @@ -91,13 +122,27 @@ export default function EditUsecase({ id }: { id: string }) { > {t('global.actions.cancel')} - + {loading ? ( + {}} + sx={{ marginLeft: '10px' }} + /> + ) : ( + + )} ) diff --git a/src/components/overlays/UpdateCertificate/index.tsx b/src/components/overlays/UpdateCertificate/index.tsx index c87ed1a66..5482c9930 100644 --- a/src/components/overlays/UpdateCertificate/index.tsx +++ b/src/components/overlays/UpdateCertificate/index.tsx @@ -60,7 +60,7 @@ export default function UpdateCertificate({ id }: { id: string }) { try { if (uploadedFile) { const data = { - credentialTypeId: 'credentialType', + credentialType: 'DISMANTLER_CERTIFICATE', //static for now as we have only one certificate document: uploadedFile, } await addCertificate(data).unwrap() diff --git a/src/components/pages/UsecaseParticipation/index.tsx b/src/components/pages/UsecaseParticipation/index.tsx index 3ae123eb1..49664ea56 100644 --- a/src/components/pages/UsecaseParticipation/index.tsx +++ b/src/components/pages/UsecaseParticipation/index.tsx @@ -30,18 +30,31 @@ import uniqueId from 'lodash/uniqueId' import { show } from 'features/control/overlay' import { OVERLAYS } from 'types/Constants' import { PageBreadcrumb } from 'components/shared/frame/PageBreadcrumb/PageBreadcrumb' -import { useFetchUsecaseQuery } from 'features/usecase/usecaseApiSlice' +import { + UsecaseResponse, + VerifiedCredentialsData, + useFetchUsecaseQuery, +} from 'features/usecase/usecaseApiSlice' import './UsecaseParticipation.scss' import { SubscriptionStatus } from 'features/apps/apiSlice' +import { useEffect } from 'react' import { Link } from 'react-router-dom' export default function UsecaseParticipation() { const { t } = useTranslation() const dispatch = useDispatch() - const { data } = useFetchUsecaseQuery() + const { data, refetch } = useFetchUsecaseQuery() + + useEffect(() => { + refetch() + }, [refetch]) - const renderStatus = (status: string) => { + const renderStatus = ( + item: UsecaseResponse, + credential: VerifiedCredentialsData + ) => { + const status = credential.ssiDetailData?.participationStatus if ( status === SubscriptionStatus.PENDING || status === SubscriptionStatus.ACTIVE @@ -59,7 +72,15 @@ export default function UsecaseParticipation() { dispatch(show(OVERLAYS.EDIT_USECASE, 'userId'))} + onClick={() => + dispatch( + show( + OVERLAYS.EDIT_USECASE, + credential.externalDetailData.id, + item.credentialType + ) + ) + } withIcon={false} type="plain" /> @@ -193,9 +214,7 @@ export default function UsecaseParticipation() { variant="body3" className="fifthSection" > - {renderStatus( - credential.ssiDetailData?.participationStatus - )} + {renderStatus(item, credential)} diff --git a/src/features/certification/certificationApiSlice.tsx b/src/features/certification/certificationApiSlice.tsx index 5945c2880..474321ca3 100644 --- a/src/features/certification/certificationApiSlice.tsx +++ b/src/features/certification/certificationApiSlice.tsx @@ -43,7 +43,7 @@ export type CertificateResponse = { } export type CertificateRequest = { - credentialTypeId: string + credentialType: string document: File } @@ -58,7 +58,7 @@ export const apiSlice = createApi({ }), addCertificate: builder.mutation({ query: (body) => ({ - url: 'api/administration/companydata/ssiCertificate', + url: 'api/administration/companydata/certificates', method: 'POST', body: body, }), diff --git a/src/features/usecase/usecaseApiSlice.ts b/src/features/usecase/usecaseApiSlice.ts index 8bb357735..cd7c223fc 100644 --- a/src/features/usecase/usecaseApiSlice.ts +++ b/src/features/usecase/usecaseApiSlice.ts @@ -47,6 +47,12 @@ export type UsecaseResponse = { verifiedCredentials: VerifiedCredentialsData[] } +export type UsecaseRequest = { + verifiedCredentialTypeId: string + credentialType: string + document: any +} + export const apiSlice = createApi({ reducerPath: 'rtk/administration/usecase', baseQuery: fetchBaseQuery(apiBaseQuery()), @@ -54,7 +60,14 @@ export const apiSlice = createApi({ fetchUsecase: builder.query({ query: () => '/api/administration/companydata/useCaseParticipation', }), + addUsecase: builder.mutation({ + query: (body) => ({ + url: 'api/administration/companydata/useCaseParticipation', + method: 'POST', + body: body, + }), + }), }), }) -export const { useFetchUsecaseQuery } = apiSlice +export const { useFetchUsecaseQuery, useAddUsecaseMutation } = apiSlice diff --git a/src/services/AccessService.tsx b/src/services/AccessService.tsx index 295fa33c1..a56bdea3d 100644 --- a/src/services/AccessService.tsx +++ b/src/services/AccessService.tsx @@ -199,7 +199,7 @@ export const getOverlay = (overlay: OverlayState) => { case OVERLAYS.UPDATE_COMPANY_ROLE: return case OVERLAYS.EDIT_USECASE: - return + return case OVERLAYS.UPDATE_CERTIFICATE: return default: