Skip to content

Commit b7bac9f

Browse files
refactor(app marketplace): remove axios library use (#1512)
#1248
1 parent debee77 commit b7bac9f

File tree

21 files changed

+325
-623
lines changed

21 files changed

+325
-623
lines changed

src/assets/locales/de/main.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@
303303
"favoriteSection": {
304304
"title": "Meine Favoriten",
305305
"myFavorite": "Meine Favoriten",
306-
"noFavoriteDescription": "Ihre App Favoriten werden in diesem Abschnitt angezeigt, sobald Favoriten ausgewählt sind."
306+
"noFavoriteDescription": "Ihre App-Favoriten werden in diesem Abschnitt angezeigt, sobald Favoriten ausgewählt sind.",
307+
"errorMsg": "Fehler! Etwas ist schief gelaufen"
307308
},
308309
"appOverviewSection": {
309310
"title": "App Übersicht",
@@ -327,7 +328,8 @@
327328
"noMatch": "Keine Treffer",
328329
"for": "zu Ihrem Suchausdruck",
329330
"dataLoadFailed": "Das Laden der Daten ist aufgrund fehlender Berechtigungsrechte fehlgeschlagen.",
330-
"loadFailed": "Laden fehlgeschlagen"
331+
"loadFailed": "Laden fehlgeschlagen",
332+
"errorMsg": "Fehler! Etwas ist schief gelaufen"
331333
}
332334
},
333335
"semantichub": {
@@ -576,7 +578,7 @@
576578
"headerTitle": "Update Contract Documents",
577579
"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 .",
578580
"successMsg": "Document uploaded successfully",
579-
"errorMsg": "Error! Something went wrong",
581+
"errorMsg": "Fehler! Etwas ist schief gelaufen",
580582
"uploadNewDocument": "Upload new document",
581583
"uploadNewDocumentDescription": "Hinweis: Es ist nur eine Datei zum Hochladen zulässig",
582584
"documentDeleteSuccess": "Document deleted successfully",
@@ -1412,7 +1414,7 @@
14121414
"message": "Please try it again"
14131415
},
14141416
"dataSavedSuccessMessage": "Data saved successfully",
1415-
"errormessage": "Error! Something went wrong",
1417+
"errormessage": "Fehler! Etwas ist schief gelaufen",
14161418
"fileSizeError": "Uploaded file is too big. Maximum 0.8MB is allowed",
14171419
"shouldNotStartWith": "and should not start with"
14181420
},
@@ -1585,7 +1587,7 @@
15851587
"helpText": "For any questions regarding these change(s), please contact the Catena-X helpdesk:",
15861588
"email": "[email protected]",
15871589
"tenantUrlSuccessMsg": "App Tenant URL successfully updated",
1588-
"tenantUrlErrorMsg": "Error! Something went wrong",
1590+
"tenantUrlErrorMsg": "Fehler! Etwas ist schief gelaufen",
15891591
"externalServices": {
15901592
"heading": "Details zum externen Dienst",
15911593
"trustedIssuer": {
@@ -1619,7 +1621,7 @@
16191621
"headerTitle": "App request management",
16201622
"search": "search company name/app title",
16211623
"noDataMessage": "No data available",
1622-
"errorMsg": "Error! Something went wrong",
1624+
"errorMsg": "Fehler! Etwas ist schief gelaufen",
16231625
"successMsg": "Successfully completed",
16241626
"tabs": {
16251627
"open": "Open",

src/assets/locales/en/main.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@
303303
"favoriteSection": {
304304
"title": "My Favorite Applications",
305305
"myFavorite": "My Favorites",
306-
"noFavoriteDescription": "Your app favorites will show up in this section as soon as favorites selected."
306+
"noFavoriteDescription": "Your app favorites will show up in this section as soon as favorites are selected.",
307+
"errorMsg": "Error! Something went wrong"
307308
},
308309
"appOverviewSection": {
309310
"title": "App Overview",
@@ -327,7 +328,8 @@
327328
"noMatch": "No Match",
328329
"for": "for your search term",
329330
"dataLoadFailed": "Data Load Failed due to missing permission rights.",
330-
"loadFailed": "Load Failed"
331+
"loadFailed": "Load Failed",
332+
"errorMsg": "Error! Something went wrong"
331333
}
332334
},
333335
"semantichub": {

src/components/pages/AppDetail/AppDetailHeader/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export default function AppDetailHeader({
226226
{t('content.appdetail.language')}:
227227
</Typography>
228228
<Typography variant="caption2" sx={{ pb: 2, ml: 1 }}>
229-
{item.languages?.map((lang, index) => (
229+
{item.languages?.map((lang: string, index: number) => (
230230
<span key={lang}>
231231
{` ${index ? ', ' : ''}${lang.toUpperCase()} `}
232232
</span>

src/components/pages/AppMarketplace/AppListSection/index.tsx

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,23 @@ import {
2525
} from '@catena-x/portal-shared-components'
2626
import { useTheme } from '@mui/material'
2727
import { AppListGroupView } from '../AppListGroupView'
28-
import { useDispatch, useSelector } from 'react-redux'
2928
import { useNavigate, useParams, useLocation } from 'react-router-dom'
30-
import { addItem, removeItem } from 'features/apps/favorites/actions'
3129
import {
3230
useFetchActiveAppsQuery,
3331
useFetchFavoriteAppsQuery,
3432
} from 'features/apps/apiSlice'
3533
import CommonService from 'services/CommonService'
36-
import type { AppDispatch } from 'features/store'
3734
import { appsControlSelector } from 'features/apps/control'
3835
import { type AppMarketplaceApp } from 'features/apps/types'
3936
import { useEffect, useState } from 'react'
4037
import { cloneDeep } from 'lodash'
4138
import NoItems from 'components/pages/NoItems'
39+
import {
40+
useAddItemMutation,
41+
useRemoveItemMutation,
42+
} from 'features/apps/favorites/apiSlice'
43+
import { useSelector } from 'react-redux'
44+
import { error } from 'services/NotifyService'
4245

4346
export const label = 'AppList'
4447

@@ -48,33 +51,63 @@ export default function AppListSection() {
4851
const { id } = useParams()
4952
const location = useLocation()
5053

51-
const dispatch = useDispatch<AppDispatch>()
5254
const navigate = useNavigate()
53-
const { data, error, isError, refetch } = useFetchActiveAppsQuery()
55+
const {
56+
data,
57+
error: fetchError,
58+
isError,
59+
refetch,
60+
} = useFetchActiveAppsQuery()
5461
const { data: favoriteItems, refetch: refetchFavoriteApps } =
5562
useFetchFavoriteAppsQuery()
63+
5664
const control = useSelector(appsControlSelector)
5765
const [list, setList] = useState<AppMarketplaceApp[]>([])
5866
const [favList, setFavList] = useState<string[]>([])
5967

60-
// To-Do fix the type issue with status and data from FetchBaseQueryError
68+
const [addItem] = useAddItemMutation()
69+
const [removeItem] = useRemoveItemMutation()
70+
71+
// Add an ESLint exception until there is a solution
6172
// eslint-disable-next-line
62-
const activeAppsError = error as any
73+
const activeAppsError = fetchError as any
6374

6475
const checkIsFavorite = (appId: string) => favList?.includes(appId)
6576

6677
const addOrRemoveFavorite = (event: React.MouseEvent, appId: string) => {
6778
const favs = cloneDeep(favList)
68-
event?.stopPropagation()
79+
event.stopPropagation()
80+
6981
if (checkIsFavorite(appId)) {
70-
dispatch(removeItem(appId))
71-
const indexVal = favs?.indexOf(appId)
72-
favs.splice(indexVal, 1)
73-
arrangeDataList(list, favs)
82+
removeItem(appId)
83+
.unwrap()
84+
.then(() => {
85+
favs.splice(favs.indexOf(appId), 1)
86+
arrangeDataList(list, favs)
87+
refetchFavoriteApps()
88+
})
89+
.catch((err) => {
90+
error(
91+
t('content.appstore.appOverviewSection.errorMsg'),
92+
'',
93+
err as object
94+
)
95+
})
7496
} else {
75-
dispatch(addItem(appId))
76-
favs?.push(appId)
77-
arrangeDataList(list, favs)
97+
addItem(appId)
98+
.unwrap()
99+
.then(() => {
100+
favs.push(appId)
101+
arrangeDataList(list, favs)
102+
refetchFavoriteApps()
103+
})
104+
.catch((err) => {
105+
error(
106+
t('content.appstore.appOverviewSection.errorMsg'),
107+
'',
108+
err as object
109+
)
110+
})
78111
}
79112
}
80113

@@ -104,9 +137,7 @@ export default function AppListSection() {
104137
variant="indeterminate"
105138
colorVariant="primary"
106139
size={50}
107-
sx={{
108-
color: theme.palette.primary.main,
109-
}}
140+
sx={{ color: theme.palette.primary.main }}
110141
/>
111142
</div>
112143
)

src/components/pages/AppMarketplace/FavoriteSection/FavoriteItem.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import { Card } from '@catena-x/portal-shared-components'
2222
import uniqueId from 'lodash/uniqueId'
2323
import { useNavigate } from 'react-router-dom'
2424
import { useState, useEffect } from 'react'
25-
import { removeItem } from 'features/apps/favorites/actions'
26-
import { useDispatch } from 'react-redux'
2725
import CommonService from 'services/CommonService'
28-
import type { AppDispatch } from 'features/store'
2926
import { useFetchDocumentByIdMutation } from 'features/apps/apiSlice'
27+
import { useRemoveItemMutation } from 'features/apps/favorites/apiSlice'
28+
import { error } from 'services/NotifyService'
29+
import { t } from 'i18next'
3030
interface FavoriteItemProps {
3131
// Add an ESLint exception until there is a solution
3232
// eslint-disable-next-line
@@ -41,14 +41,20 @@ export default function FavoriteItem({
4141
cardClick,
4242
}: Readonly<FavoriteItemProps>) {
4343
const navigate = useNavigate()
44-
const dispatch = useDispatch<AppDispatch>()
4544
const [cardImage, setCardImage] = useState('')
4645
const [addedToFavorite, setAddedToFavorite] = useState(false)
4746
const [fetchDocumentById] = useFetchDocumentByIdMutation()
47+
const [removeItem] = useRemoveItemMutation()
4848

4949
const handleSecondaryButtonClick = (id: string) => {
50-
dispatch(removeItem(id))
51-
setAddedToFavorite(!addedToFavorite)
50+
removeItem(id)
51+
.unwrap()
52+
.then(() => {
53+
setAddedToFavorite(!addedToFavorite)
54+
})
55+
.catch((err) => {
56+
error(t('content.appstore.favoriteSection.errorMsg'), '', err as object)
57+
})
5258
}
5359

5460
useEffect(() => {

src/components/pages/AppMarketplace/FavoriteSection/index.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,18 @@ import { Box } from '@mui/material'
2323
import { useTranslation } from 'react-i18next'
2424
import FavoriteItem from './FavoriteItem'
2525
import EmptyFavorites from './EmptyFavorites'
26-
import { useFetchActiveAppsQuery } from 'features/apps/apiSlice'
26+
import {
27+
useFetchActiveAppsQuery,
28+
useFetchFavoriteAppsQuery,
29+
} from 'features/apps/apiSlice'
2730
import { appToCard } from 'features/apps/mapper'
28-
import { useDispatch, useSelector } from 'react-redux'
29-
import { itemsSelector } from 'features/apps/favorites/slice'
30-
import { useEffect } from 'react'
31-
import { fetchItems } from 'features/apps/favorites/actions'
32-
import type { AppDispatch } from 'features/store'
3331

3432
export default function FavoriteSection() {
3533
const { t } = useTranslation()
36-
const dispatch = useDispatch<AppDispatch>()
37-
const active = useFetchActiveAppsQuery().data ?? []
38-
const favorites = useSelector(itemsSelector)
39-
const favoriteSectionPosition = favorites.length === 0 ? 30 : 35
34+
const { data: active = [] } = useFetchActiveAppsQuery()
35+
const { data: favorites = [] } = useFetchFavoriteAppsQuery()
4036

41-
useEffect(() => {
42-
dispatch(fetchItems())
43-
}, [dispatch])
37+
const favoriteSectionPosition = favorites.length === 0 ? 30 : 35
4438

4539
return (
4640
<Box

src/features/apps/details/api.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/features/apps/details/apiTestdata.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)