Skip to content

Commit

Permalink
fix(service release process): fix download document (eclipse-tractusx…
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalgaurav-bmw authored Dec 13, 2024
1 parent ae8714b commit ba399a4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/components/shared/basic/ReleaseProcess/OfferCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import RetryOverlay from '../components/RetryOverlay'
import { success, error } from 'services/NotifyService'
import { DocumentTypeId } from 'features/appManagement/apiSlice'
import { PAGES } from 'types/Constants'
import { download } from 'utils/downloadUtils'
import { extractFileData } from 'utils/fileUtils'

type FormDataType = {
title: string
Expand Down Expand Up @@ -179,6 +181,22 @@ export default function OfferCard() {
[fetchDocumentById, serviceId, setValue]
)

const handleDownload = async (documentName: string, documentId: string) => {
if (fetchDocumentById)
try {
const response = await fetchDocumentById({
appId: serviceId,
documentId,
}).unwrap()

const { fileType, file } = extractFileData(response)

download(file, fileType, documentName)
} catch (error) {
console.error(error, 'ERROR WHILE FETCHING DOCUMENT')
}
}

useEffect(() => {
if (serviceStatusData?.documents?.SERVICE_LEADIMAGE?.[0].documentId) {
fetchCardImage(
Expand Down Expand Up @@ -497,6 +515,7 @@ export default function OfferCard() {
note={t('serviceReleaseForm.note')}
requiredText={t('serviceReleaseForm.fileUploadIsMandatory')}
isRequired={false}
handleDownload={handleDownload}
handleDelete={(documentId: string) => {
setImageData({})
documentId && deleteDocument(documentId)
Expand Down
24 changes: 24 additions & 0 deletions src/components/shared/basic/ReleaseProcess/OfferPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
useFetchServiceStatusQuery,
useSaveServiceMutation,
useUpdateServiceDocumentUploadMutation,
useFetchDocumentMutation,
} from 'features/serviceManagement/apiSlice'
import { Dropzone, type DropzoneFile } from 'components/shared/basic/Dropzone'
import SnackbarNotificationWithButtons from '../components/SnackbarNotificationWithButtons'
Expand All @@ -54,7 +55,10 @@ import type { LanguageStatusType } from 'features/appManagement/types'
import { DocumentTypeId } from 'features/appManagement/apiSlice'
import { ButtonLabelTypes } from '..'
import { success, error } from 'services/NotifyService'
import { download } from 'utils/downloadUtils'
import { type FileState } from 'features/serviceManagement/types'
import { ALLOWED_MAX_SIZE_DOCUMENT } from 'types/Constants'
import { extractFileData } from 'utils/fileUtils'

type FormDataType = {
longDescriptionEN: string
Expand Down Expand Up @@ -85,6 +89,7 @@ export default function OfferPage({
const [updateDocumentUpload] = useUpdateServiceDocumentUploadMutation()
const [loading, setLoading] = useState<boolean>(false)
const [deleteDocument, deleteResponse] = useDeleteDocumentMutation()
const [fetchDocumentById] = useFetchDocumentMutation()

useEffect(() => {
if (fetchServiceStatus) dispatch(setServiceStatus(fetchServiceStatus))
Expand Down Expand Up @@ -268,6 +273,24 @@ export default function OfferPage({
setLoading(false)
}

const handleDownload = async (value: FileState[]) => {
const documentId = value[0].id
const documentName = value[0].name
if (fetchDocumentById)
try {
const response = await fetchDocumentById({
appId: serviceId,
documentId,
}).unwrap()

const { fileType, file } = extractFileData(response)

download(file, fileType, documentName)
} catch (error) {
console.error(error, 'ERROR WHILE FETCHING DOCUMENT')
}
}

return (
<div className="app-page">
<ReleaseStepHeader
Expand Down Expand Up @@ -349,6 +372,7 @@ export default function OfferPage({
}}
maxFilesToUpload={1}
maxFileSize={ALLOWED_MAX_SIZE_DOCUMENT}
handleDownload={() => handleDownload(value)}
handleDelete={(documentId: string) => {
documentId && deleteDocument(documentId)
}}
Expand Down
5 changes: 5 additions & 0 deletions src/features/serviceManagement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export enum SORTING_TYPE {
PROVIDER_DESC = 'ProviderDesc',
}

export interface FileState {
id: string
name: string
}

export const initialState: ServiceManagementState = {
serviceReleaseActiveStep: 1,
serviceId: '',
Expand Down

0 comments on commit ba399a4

Please sign in to comment.