-
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.
feat: [IOCOM-1413] Archiving/Restoring of user messages, new Messages…
… Home (#5935)⚠️ This PR depends on #5912⚠️ ## Short description This PR adds the support for archiving and restoring of user messages, in the new messages home. |iOS|Android| |-|-| |<video src="https://github.com/pagopa/io-app/assets/5150343/a5f7a2a9-3c20-4ea6-9f34-ce18f22b7ee9" />|<video src="https://github.com/pagopa/io-app/assets/5150343/025fcc9f-3123-44bf-b45a-b5d4d36cfa4d" />| **_Please note_** that the toast showing "Annullato" has been removed. ## List of changes proposed in this pull request New archiving/restoring UI and UX. In order to both fix previous problems and not change a complex business logic, this PR builds above the latter, keeping the compatibility with the old system (the algorithm is explained in `ts/features/messages/saga/handleUpsertMessageStatusAttributes.ts`) - actions and reducer. The feature is implemented with three states: - "disabled" | "enabled": the latter displays the bottom CTAs and allows to select messages for archiving/restoring - "processing": the system is busy processing the asynchronous archiving/restoring of messages Messages are enqueued by Id while in the "enabled" state and processed one at a time while in "processing" state, in order to properly handle whatever failure may happen. It also supports cancellation by the user. If at any moment an error or a cancellation happens, the processing is suspended, the user is notified but she can later resume it. - `ArchiveRestoreBar` is the component that displays the bottom CTAs for archiving/restoring Since the bottom bar is hidden while picking messages or processing them, there are some application entry points that have been disabled, in order not to trigger a flow that may later bring back to another main screen without the bottom bar. Such flows are deep link following, push notification tapping, message reloading and next page loading during processing, first message page loading and message search. ## How to test Using the io-dev-api-server, make sure to enable both DS and new messages home. Long tap (and later tap) on some messages and try the archiving/restoring/cancelling.
- Loading branch information
Showing
38 changed files
with
941 additions
and
1,396 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
108 changes: 108 additions & 0 deletions
108
ts/features/messages/components/Home/ArchiveRestoreBar.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,108 @@ | ||
import React, { useCallback, useEffect } from "react"; | ||
import { StyleSheet, View } from "react-native"; | ||
import { ButtonOutline, ButtonSolid } from "@pagopa/io-app-design-system"; | ||
import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
import { | ||
useIODispatch, | ||
useIOSelector, | ||
useIOStore | ||
} from "../../../../store/hooks"; | ||
import { | ||
areThereEntriesForShownMessageListCategorySelector, | ||
isArchivingDisabledSelector, | ||
isArchivingInProcessingModeSelector | ||
} from "../../store/reducers/archiving"; | ||
import { useIOTabNavigation } from "../../../../navigation/params/AppParamsList"; | ||
import { shownMessageCategorySelector } from "../../store/reducers/allPaginated"; | ||
import I18n from "../../../../i18n"; | ||
import { | ||
resetMessageArchivingAction, | ||
startProcessingMessageArchivingAction | ||
} from "../../store/actions/archiving"; | ||
import { MessageListCategory } from "../../types/messageListCategory"; | ||
import { useHardwareBackButton } from "../../../../hooks/useHardwareBackButton"; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: "row", | ||
paddingHorizontal: 24, | ||
paddingTop: 8 | ||
}, | ||
endButtonContainer: { | ||
flex: 1, | ||
marginStart: 4 | ||
}, | ||
startButtonContainer: { | ||
flex: 1, | ||
marginEnd: 4 | ||
} | ||
}); | ||
|
||
type ArchiveRestoreCTAsProps = { | ||
category: MessageListCategory; | ||
}; | ||
|
||
export const ArchiveRestoreBar = () => { | ||
const store = useIOStore(); | ||
const tabNavigation = useIOTabNavigation(); | ||
|
||
const isArchivingDisabled = useIOSelector(isArchivingDisabledSelector); | ||
const shownCategory = useIOSelector(shownMessageCategorySelector); | ||
|
||
const androidBackButtonCallback = useCallback(() => { | ||
// Disable Android back button while processing archiving/restoring | ||
const state = store.getState(); | ||
return isArchivingInProcessingModeSelector(state); | ||
}, [store]); | ||
useHardwareBackButton(androidBackButtonCallback); | ||
|
||
useEffect(() => { | ||
tabNavigation.setOptions({ | ||
tabBarStyle: { | ||
display: isArchivingDisabled ? "flex" : "none" | ||
} | ||
}); | ||
}, [isArchivingDisabled, tabNavigation]); | ||
|
||
if (isArchivingDisabled) { | ||
return null; | ||
} | ||
|
||
return <ArchiveRestoreCTAs category={shownCategory} />; | ||
}; | ||
|
||
const ArchiveRestoreCTAs = ({ category }: ArchiveRestoreCTAsProps) => { | ||
const safeAreaInsets = useSafeAreaInsets(); | ||
const dispatch = useIODispatch(); | ||
|
||
const archiveRestoreCTAEnabled = useIOSelector(state => | ||
areThereEntriesForShownMessageListCategorySelector(state, category) | ||
); | ||
const isProcessing = useIOSelector(isArchivingInProcessingModeSelector); | ||
|
||
const rightButtonLabel = I18n.t( | ||
`messages.cta.${category === "ARCHIVE" ? "unarchive" : "archive"}` | ||
); | ||
return ( | ||
<View | ||
style={[styles.container, { paddingBottom: 8 + safeAreaInsets.bottom }]} | ||
> | ||
<View style={styles.startButtonContainer}> | ||
<ButtonOutline | ||
label="Annulla" | ||
fullWidth | ||
onPress={() => dispatch(resetMessageArchivingAction(undefined))} | ||
/> | ||
</View> | ||
<View style={styles.endButtonContainer}> | ||
<ButtonSolid | ||
disabled={!archiveRestoreCTAEnabled} | ||
label={rightButtonLabel} | ||
loading={isProcessing} | ||
fullWidth | ||
onPress={() => dispatch(startProcessingMessageArchivingAction())} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
}; |
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
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.