diff --git a/src/components/shared/basic/ReleaseProcess/OfferCard/index.tsx b/src/components/shared/basic/ReleaseProcess/OfferCard/index.tsx index a8cb88bd8..b36b537e6 100644 --- a/src/components/shared/basic/ReleaseProcess/OfferCard/index.tsx +++ b/src/components/shared/basic/ReleaseProcess/OfferCard/index.tsx @@ -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 @@ -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( @@ -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) diff --git a/src/components/shared/basic/ReleaseProcess/OfferPage/index.tsx b/src/components/shared/basic/ReleaseProcess/OfferPage/index.tsx index 074be0273..90d261596 100644 --- a/src/components/shared/basic/ReleaseProcess/OfferPage/index.tsx +++ b/src/components/shared/basic/ReleaseProcess/OfferPage/index.tsx @@ -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' @@ -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 @@ -85,6 +89,7 @@ export default function OfferPage({ const [updateDocumentUpload] = useUpdateServiceDocumentUploadMutation() const [loading, setLoading] = useState(false) const [deleteDocument, deleteResponse] = useDeleteDocumentMutation() + const [fetchDocumentById] = useFetchDocumentMutation() useEffect(() => { if (fetchServiceStatus) dispatch(setServiceStatus(fetchServiceStatus)) @@ -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 (
handleDownload(value)} handleDelete={(documentId: string) => { documentId && deleteDocument(documentId) }} diff --git a/src/features/serviceManagement/types.ts b/src/features/serviceManagement/types.ts index 8d189e079..a2a6cf390 100644 --- a/src/features/serviceManagement/types.ts +++ b/src/features/serviceManagement/types.ts @@ -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: '',