-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [IOBP-405] Wallet details update services pagoPA capability (#5322
) ## Short description This PR implements a toggle to update the pagoPA capability status inside the wallet details screen; ## List of changes proposed in this pull request - Added a new action `walletDetailsPagoPaCapabilityToggle` - Adapted the `WalletDetailsPagoPaPaymentCapability` component; - Added a new saga `handleTogglePagoPaCapability` that manages the toggle of the services that have `PAGOPA` as the service name, updating the status to `DISABLED` or `ENABLED` - ## How to test - Checkout this PR from io-dev-api-server: pagopa/io-dev-api-server#331 - Complete the new wallet onboarding process from the `New Wallet Playground` - After you add a payment method correctly, you should be able to see the wallet details with a switch that can be toggled ## Preview https://github.com/pagopa/io-app/assets/34343582/7884038e-97ab-444e-a02f-e8073e04f1e1
- Loading branch information
Showing
9 changed files
with
211 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 38 additions & 83 deletions
121
ts/features/walletV3/common/components/WalletDetailsPagoPaPaymentCapability.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
ts/features/walletV3/details/saga/handleTogglePagoPaCapability.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { call, put, select } from "typed-redux-saga/macro"; | ||
import * as E from "fp-ts/lib/Either"; | ||
import { ActionType } from "typesafe-actions"; | ||
import { SagaCallReturnType } from "../../../../types/utils"; | ||
import { | ||
walletDetailsGetInstrument, | ||
walletDetailsPagoPaCapabilityToggle | ||
} from "../store/actions"; | ||
import { readablePrivacyReport } from "../../../../utils/reporters"; | ||
import { getGenericError, getNetworkError } from "../../../../utils/errors"; | ||
import { WalletClient } from "../../common/api/client"; | ||
import { withRefreshApiCall } from "../../../fastLogin/saga/utils"; | ||
import { walletDetailsInstrumentSelector } from "../store"; | ||
import { ServiceNameEnum } from "../../../../../definitions/pagopa/walletv3/ServiceName"; | ||
import { Service } from "../../../../../definitions/pagopa/walletv3/Service"; | ||
import { ServiceStatusEnum } from "../../../../../definitions/pagopa/walletv3/ServiceStatus"; | ||
import { WalletService } from "../../../../../definitions/pagopa/walletv3/WalletService"; | ||
|
||
/** | ||
* Handle the remote call to toggle the Wallet pagopa capability | ||
*/ | ||
export function* handleTogglePagoPaCapability( | ||
updateWalletServicesById: WalletClient["updateWalletServicesById"], | ||
action: ActionType<(typeof walletDetailsPagoPaCapabilityToggle)["request"]> | ||
) { | ||
try { | ||
const walletDetails = yield* select(walletDetailsInstrumentSelector); | ||
if (!walletDetails) { | ||
throw new Error("walletDetails is undefined"); | ||
} | ||
const updatedServices = walletDetails.services.map(service => ({ | ||
...service, | ||
status: updatePagoPaServiceStatus(service) | ||
})); | ||
|
||
const updateWalletPagoPaServicesRequest = updateWalletServicesById({ | ||
walletId: action.payload.walletId, | ||
body: { | ||
services: updatedServices as Array<WalletService> | ||
} | ||
}); | ||
const updateWalletResult = (yield* call( | ||
withRefreshApiCall, | ||
updateWalletPagoPaServicesRequest, | ||
action | ||
)) as unknown as SagaCallReturnType<typeof updateWalletServicesById>; | ||
if (E.isRight(updateWalletResult)) { | ||
if (updateWalletResult.right.status === 204) { | ||
// handled success | ||
const successAction = walletDetailsPagoPaCapabilityToggle.success(); | ||
yield* put(successAction); | ||
if (action.payload.onSuccess) { | ||
action.payload.onSuccess(successAction); | ||
} | ||
return; | ||
} | ||
// not handled error codes | ||
const failureAction = walletDetailsPagoPaCapabilityToggle.failure({ | ||
...getGenericError( | ||
new Error(`response status code ${updateWalletResult.right.status}`) | ||
) | ||
}); | ||
yield* put(failureAction); | ||
if (action.payload.onFailure) { | ||
action.payload.onFailure(failureAction); | ||
} | ||
} else { | ||
// cannot decode response | ||
const failureAction = walletDetailsPagoPaCapabilityToggle.failure({ | ||
...getGenericError( | ||
new Error(readablePrivacyReport(updateWalletResult.left)) | ||
) | ||
}); | ||
yield* put(failureAction); | ||
if (action.payload.onFailure) { | ||
action.payload.onFailure(failureAction); | ||
} | ||
} | ||
} catch (e) { | ||
yield* put(walletDetailsGetInstrument.failure({ ...getNetworkError(e) })); | ||
} | ||
} | ||
|
||
const updatePagoPaServiceStatus = ( | ||
service: Service | ||
): ServiceStatusEnum | undefined => { | ||
if (service.name === ServiceNameEnum.PAGOPA) { | ||
return service.status === ServiceStatusEnum.DISABLED | ||
? ServiceStatusEnum.ENABLED | ||
: ServiceStatusEnum.DISABLED; | ||
} | ||
return service.status; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.