Skip to content

Commit

Permalink
[SELC-5842] Feat: update selfcare commons for new action
Browse files Browse the repository at this point in the history
Co-authored-by: andrea-putzu <[email protected]>
Co-authored-by: manuraf <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent e4c3f3d commit 3b6af75
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@mui/x-data-grid": "^5.0.1",
"@mui/x-data-grid-generator": "^5.0.1",
"@pagopa/mui-italia": "^1.5.0",
"@pagopa/selfcare-common-frontend": "^1.34.43",
"@pagopa/selfcare-common-frontend": "^1.34.44",
"@types/react": "^18.2.22",
"@types/react-dom": "^18.2.7",
"@types/react-router-dom": "^5.3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { Party } from '../../../../model/Party';
import { Product } from '../../../../model/Product';
import { interopProductIdList } from '../../../../utils/constants';
import { startWithProductInterop } from '../../../../utils/helperFunctions';
import ActiveProductCardContainer from './components/ActiveProductCardContainer';

Expand All @@ -19,19 +18,35 @@ export default function ActiveProductsSection({ party, products }: Readonly<Prop
const { t } = useTranslation();
const { hasPermission } = usePermissions();

const findAuthorizedProduct = (productId: string) =>
party?.products.find(
(p) =>
p.productId === productId && hasPermission(p.productId, Actions.AccessProductBackoffice)
);
const interopProducts = party?.products
.filter(
(product) =>
startWithProductInterop(product.productId) && product.productOnBoardingStatus === 'ACTIVE'
)
.map((p) => p.productId ?? '');

const authorizedInteropProducts = interopProductIdList
.map(findAuthorizedProduct)
.filter(Boolean)
.map((p) => p?.productId ?? '');
const authorizedInteropProducts = party?.products
.filter(
(product) =>
startWithProductInterop(product.productId) &&
hasPermission(product.productId ?? '', Actions.AccessProductBackoffice)
)
.map((p) => p.productId ?? '');

const hasMoreThanOneInteropEnv = authorizedInteropProducts.length > 1;

const isRelevantInteropProduct = (productId: string) => {
if (startWithProductInterop(productId)) {
if (authorizedInteropProducts.length > 0) {
return productId === authorizedInteropProducts[0];
}
if (interopProducts.length > 0) {
return productId === interopProducts[0];
}
}
return true;
};

return (
<React.Fragment>
<TitleBox
Expand All @@ -45,9 +60,7 @@ export default function ActiveProductsSection({ party, products }: Readonly<Prop
.filter(
(us) =>
us.productOnBoardingStatus === 'ACTIVE' &&
(startWithProductInterop(us.productId) && hasMoreThanOneInteropEnv
? us.productId === authorizedInteropProducts[0]
: true)
isRelevantInteropProduct(us.productId ?? '')
)
.sort((a, b) => {
const aHasPermission = hasPermission(
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2034,10 +2034,10 @@
write-yaml-file "^4.1.3"
yargs "^15.0.1"

"@pagopa/selfcare-common-frontend@^1.34.43":
version "1.34.43"
resolved "https://registry.yarnpkg.com/@pagopa/selfcare-common-frontend/-/selfcare-common-frontend-1.34.43.tgz#73c566ae9ee0d021260adbf347afa1bce3789b83"
integrity sha512-Wgb+PJQzZl9inIVhZKm/NwbARzJ/U9aZKtVU3wNfBTqP9kkbtSBogsNncBawRcsq1p7fVfwHRUSSVvbxcYm0Sg==
"@pagopa/selfcare-common-frontend@^1.34.44":
version "1.34.44"
resolved "https://registry.yarnpkg.com/@pagopa/selfcare-common-frontend/-/selfcare-common-frontend-1.34.44.tgz#d276cf4583526d9be6000e993f48a7b34d7663f2"
integrity sha512-Gv9KHHTZ1tYIDcqjx9vslpg23ei9fhbGAaNUkmKN3Pg1UunPkzeHpf/hcvJuBXRVW1C7yXj0TH92ZxYRNiWsxg==
dependencies:
"@emotion/react" "^11.11.1"
"@emotion/styled" "^11.11.0"
Expand Down

0 comments on commit 3b6af75

Please sign in to comment.