-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IOCOM-1338, IOCOM-1562, IOCOM-1563] FIMS history export feature (#6091)
## Short description Addition of Fims history export feature https://github.com/user-attachments/assets/50fd997b-8035-48b3-8715-d13f3337ecc3 ## List of changes proposed in this pull request - history export saga - error/confirm alerts - required i18n entries - system alerts for both export request confirmation and already exporting notification ## How to test using the dev-server, navigate to profile>privacy>third party accesses and play around with the export functionality. Make sure everything works as expected. --------- Co-authored-by: Andrea <[email protected]>
- Loading branch information
Showing
9 changed files
with
251 additions
and
21 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
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
84 changes: 84 additions & 0 deletions
84
ts/features/fims/history/hooks/useFimsHistoryResultToasts.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* eslint-disable functional/immutable-data */ | ||
import { IOToast } from "@pagopa/io-app-design-system"; | ||
import { constVoid } from "fp-ts/lib/function"; | ||
import * as React from "react"; | ||
import { Alert } from "react-native"; | ||
import * as RemoteValue from "../../../../common/model/RemoteValue"; | ||
import I18n from "../../../../i18n"; | ||
import { useIODispatch, useIOSelector } from "../../../../store/hooks"; | ||
import { | ||
fimsHistoryExport, | ||
resetFimsHistoryExportState | ||
} from "../store/actions"; | ||
import { fimsHistoryExportStateSelector } from "../store/selectors"; | ||
|
||
const showFimsExportError = () => | ||
IOToast.error(I18n.t("FIMS.history.exportData.errorToast")); | ||
|
||
const showFimsExportSuccess = () => | ||
IOToast.success(I18n.t("FIMS.history.exportData.successToast")); | ||
|
||
const showFimsAlreadyExportingAlert = (onPress: () => void) => | ||
Alert.alert( | ||
I18n.t("FIMS.history.exportData.alerts.alreadyExporting.title"), | ||
I18n.t("FIMS.history.exportData.alerts.alreadyExporting.body"), | ||
[{ text: I18n.t("global.buttons.ok"), onPress }] | ||
); | ||
|
||
export const useFimsHistoryExport = () => { | ||
const historyExportState = useIOSelector(fimsHistoryExportStateSelector); | ||
const dispatch = useIODispatch(); | ||
const isProcessing = React.useRef<boolean>(false); | ||
|
||
React.useEffect(() => { | ||
RemoteValue.fold( | ||
historyExportState, | ||
constVoid, | ||
constVoid, | ||
value => { | ||
if (value === "SUCCESS") { | ||
showFimsExportSuccess(); | ||
isProcessing.current = false; | ||
} else { | ||
showFimsAlreadyExportingAlert(() => (isProcessing.current = false)); | ||
} | ||
}, | ||
() => { | ||
showFimsExportError(); | ||
isProcessing.current = false; | ||
} | ||
); | ||
}, [historyExportState, dispatch]); | ||
|
||
// cleanup | ||
React.useEffect( | ||
() => () => { | ||
dispatch(resetFimsHistoryExportState()); | ||
}, | ||
[dispatch] | ||
); | ||
|
||
const handleExportOnPress = () => { | ||
if (!isProcessing.current) { | ||
Alert.alert( | ||
I18n.t("FIMS.history.exportData.alerts.areYouSure"), | ||
undefined, | ||
[ | ||
{ text: I18n.t("global.buttons.cancel"), style: "cancel" }, | ||
{ | ||
text: I18n.t("global.buttons.confirm"), | ||
isPreferred: true, | ||
onPress: () => { | ||
isProcessing.current = true; | ||
dispatch(fimsHistoryExport.request()); | ||
} | ||
} | ||
] | ||
); | ||
} | ||
}; | ||
|
||
return { | ||
handleExportOnPress | ||
}; | ||
}; |
47 changes: 47 additions & 0 deletions
47
ts/features/fims/history/saga/handleExportFimsHistorySaga.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,47 @@ | ||
import * as E from "fp-ts/lib/Either"; | ||
import { pipe } from "fp-ts/lib/function"; | ||
import { call, put } from "typed-redux-saga/macro"; | ||
import { ActionType } from "typesafe-actions"; | ||
import { SagaCallReturnType } from "../../../../types/utils"; | ||
import { withRefreshApiCall } from "../../../fastLogin/saga/utils"; | ||
import { FimsHistoryClient } from "../api/client"; | ||
import { fimsHistoryExport } from "../store/actions"; | ||
|
||
export function* handleExportFimsHistorySaga( | ||
exportHistory: FimsHistoryClient["exports"], | ||
bearerToken: string, | ||
action: ActionType<typeof fimsHistoryExport.request> | ||
) { | ||
const exportHistoryRequest = exportHistory({ | ||
Bearer: bearerToken | ||
}); | ||
|
||
try { | ||
const exportHistoryResult = (yield* call( | ||
withRefreshApiCall, | ||
exportHistoryRequest, | ||
action | ||
)) as SagaCallReturnType<typeof exportHistory>; | ||
|
||
const resultAction = pipe( | ||
exportHistoryResult, | ||
E.foldW( | ||
_failure => fimsHistoryExport.failure(), | ||
success => { | ||
switch (success.status) { | ||
case 202: | ||
return fimsHistoryExport.success("SUCCESS"); | ||
case 409: | ||
return fimsHistoryExport.success("ALREADY_EXPORTING"); | ||
default: | ||
return fimsHistoryExport.failure(); | ||
} | ||
} | ||
) | ||
); | ||
|
||
yield* put(resultAction); | ||
} catch (e: any) { | ||
yield* put(fimsHistoryExport.failure()); | ||
} | ||
} |
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
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.