From d78900d5d72071d25b6448c584f00a30d7e39a83 Mon Sep 17 00:00:00 2001 From: nidhigarg Date: Mon, 7 Aug 2023 16:13:29 +0530 Subject: [PATCH] fix(sonar bugs): replacing promise for fetching images --- .../AdminBoardDetail/BoardContentDetails.tsx | 38 ++++++++++++++----- .../components/BoardHeader/index.tsx | 2 +- src/services/CommonService.ts | 15 ++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/components/pages/AdminBoardDetail/BoardContentDetails.tsx b/src/components/pages/AdminBoardDetail/BoardContentDetails.tsx index 37bcd246c..df8d25f97 100644 --- a/src/components/pages/AdminBoardDetail/BoardContentDetails.tsx +++ b/src/components/pages/AdminBoardDetail/BoardContentDetails.tsx @@ -35,22 +35,42 @@ import BoardPrivacy from './components/BoardPrivacy' import BoardRoles from './components/BoardRoles' import './AdminBoardDetail.scss' import BoardTechnicalUserSetup from './components/BoardTechnicalUserSetup' +import { fetchImageWithToken } from 'services/ImageService' export default function BoardContentDetails({ item }: { item: AppDetails }) { const { t } = useTranslation() const navigate = useNavigate() - const [images, setImages] = useState() + const [images, setImages] = useState([]) + console.log('images', images) useEffect(() => { if (item) { - const newPromies = CommonService.fetchLeadPictures(item.images, item.id) - Promise.all(newPromies) - .then((result) => { - setImages(result.flat()) - }) - .catch((err) => { - console.log(err) - }) + item.images?.map((image: any) => { + console.log('image', image) + let url = CommonService.getImageURL(image, item.id) + return fetchImageWithToken(url) + .then((buffer) => { + const urlObj = { + url: URL.createObjectURL( + new Blob([buffer], { type: 'image/png' }) + ), + text: '', + } + console.log('urlObj', urlObj) + setImages((oldArray: any) => [...oldArray, urlObj]) + }) + .catch((err) => { + console.log(err) + }) + }) + // const newPromies = CommonService.fetchLeadPictures(item.images, item.id) + // Promise.all(newPromies) + // .then((result) => { + // setImages(result.flat()) + // }) + // .catch((err) => { + // console.log(err) + // }) } }, [item]) diff --git a/src/components/pages/AdminBoardDetail/components/BoardHeader/index.tsx b/src/components/pages/AdminBoardDetail/components/BoardHeader/index.tsx index ea2e5349b..d0c565918 100644 --- a/src/components/pages/AdminBoardDetail/components/BoardHeader/index.tsx +++ b/src/components/pages/AdminBoardDetail/components/BoardHeader/index.tsx @@ -80,7 +80,7 @@ export default function BoardHeader({ item }: AppDetailHeaderProps) { {item.title} - + {[CardDetails.LANGUAGE, CardDetails.USECASE, CardDetails.PRICE].map( (field) => (
diff --git a/src/services/CommonService.ts b/src/services/CommonService.ts index f518c4670..010bc3d19 100644 --- a/src/services/CommonService.ts +++ b/src/services/CommonService.ts @@ -91,6 +91,20 @@ const fetchLeadPictures = (images: string[], appId: string) => { return newPromies } +const getImageURL = (image: any, appId: string) => { + let url = '' + if (!image.documentId) { + url = `${getApiBase()}/api/apps/${appId}/appDocuments/${isValidPictureId( + image + )}` + } else { + url = `${getApiBase()}/api/apps/${appId}/appDocuments/${isValidPictureId( + image.documentId + )}` + } + return url +} + const isValidPictureId = (id: string) => { return id === '00000000-0000-0000-0000-000000000000' ? '00000000-0000-0000-0000-000000000001' @@ -156,6 +170,7 @@ const CommonService = { fetchLeadPictures, getRoleDescription, getCompanyRoleUpdateData, + getImageURL, } export default CommonService