Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [IOCOM-1413] Archiving/Restoring of user messages, new Messages Home #5935

Merged
merged 52 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9f55e40
WiP
Vangaorth Jun 25, 2024
eb20144
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jun 25, 2024
c3046a6
WiP
Vangaorth Jun 26, 2024
17f174c
WiP
Vangaorth Jun 26, 2024
13e2d7c
Pre-renaming
Vangaorth Jun 26, 2024
0418d5d
Post rename
Vangaorth Jun 26, 2024
393781a
Implementation done, missing tests
Vangaorth Jun 27, 2024
02e2a42
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jun 27, 2024
0ab204c
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jun 27, 2024
8234717
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jun 27, 2024
bb45c90
Tests
Vangaorth Jun 28, 2024
485cd74
Tests
Vangaorth Jun 28, 2024
ca37a23
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jun 28, 2024
714dea5
Merge branch 'IOCOM-840_preconditions' of https://github.com/pagopa/i…
Vangaorth Jun 28, 2024
18e0386
Tests
Vangaorth Jun 28, 2024
566d856
Fixed bad snapshot title
Vangaorth Jun 28, 2024
7472074
Tests
Vangaorth Jun 30, 2024
526b32e
Tests
Vangaorth Jun 30, 2024
b54fd72
Tests
Vangaorth Jun 30, 2024
ddc7ebf
Tests
Vangaorth Jul 1, 2024
617a722
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jul 1, 2024
353827c
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jul 1, 2024
54b59f9
WiP
Vangaorth Jul 2, 2024
d4b200e
WiP
Vangaorth Jul 3, 2024
cac302a
WiP
Vangaorth Jul 3, 2024
d19be25
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jul 4, 2024
defd195
Merge branch 'IOCOM-840_preconditions' into IOCOM-1413_archive
Vangaorth Jul 4, 2024
0e78d2d
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jul 4, 2024
3613614
Merge branch 'IOCOM-840_preconditions' into IOCOM-1413_archive
Vangaorth Jul 4, 2024
d8c846a
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jul 4, 2024
a566608
Merge branch 'IOCOM-840_preconditions' into IOCOM-1413_archive
Vangaorth Jul 4, 2024
9def4f4
Merge branch 'master' into IOCOM-840_preconditions
Vangaorth Jul 4, 2024
7babb70
WiP
Vangaorth Jul 4, 2024
8c7f453
Merge branch 'IOCOM-840_preconditions' into IOCOM-1413_archive
Vangaorth Jul 4, 2024
bdddd3e
WiP
Vangaorth Jul 5, 2024
8737ef5
Fixed failing tests
Vangaorth Jul 5, 2024
33518d0
Fixed message archiving
Vangaorth Jul 5, 2024
2a70904
WiP
Vangaorth Jul 5, 2024
d2a97b9
Comments removed
Vangaorth Jul 5, 2024
effac5e
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 5, 2024
2983404
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 5, 2024
2dd7dc8
Proper color for PagoPA logo
Vangaorth Jul 5, 2024
49254cb
Merge branch 'IOCOM-1413_archive' of https://github.com/pagopa/io-app…
Vangaorth Jul 5, 2024
56c70f5
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 8, 2024
8b4f67a
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 8, 2024
d1bb58c
Removed "annullato" toast
Vangaorth Jul 8, 2024
3abd44b
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 8, 2024
3bcd1a4
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 9, 2024
d3a05ac
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 9, 2024
e78942d
Merge branch 'master' into IOCOM-1413_archive
Vangaorth Jul 9, 2024
9cd2da1
Remove unnecessary cast
Vangaorth Jul 9, 2024
188d3c2
Typo
Vangaorth Jul 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,9 @@ messages:
archive:
success: "Successfully archived!"
failure: "Failed to archive"
generic:
failure: "Operation failed"
success: "Operazione successful!"
restore:
success: "Successfully unarchived."
failure: "Failed to unarchive"
Expand Down
3 changes: 3 additions & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,9 @@ messages:
archive:
success: "Archiviazione riuscita!"
failure: "L’archiviazione non è andata a buon fine"
generic:
failure: "L'operazione non è andata a buon fine"
success: "Operazione riuscita!"
restore:
success: "Ripristino effettuato."
failure: "Il ripristino non è andato a buon fine"
Expand Down
108 changes: 108 additions & 0 deletions ts/features/messages/components/Home/ArchiveRestoreBar.tsx
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"
}
});
forrest57 marked this conversation as resolved.
Show resolved Hide resolved
}, [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>
);
};
2 changes: 1 addition & 1 deletion ts/features/messages/components/Home/DS/DoubleAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const DoubleAvatar = ({ backgroundLogoUri }: DoubleAvatarProps) => {
}
]}
>
<Icon name="productPagoPA" color="blueIO-500" size={20} />
<Icon name="productPagoPA" color="blueItalia-500" size={20} />
</View>
</View>
</View>
Expand Down
43 changes: 33 additions & 10 deletions ts/features/messages/components/Home/EmptyList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import React, { useMemo } from "react";
import React, { useCallback, useMemo } from "react";
import { constUndefined, pipe } from "fp-ts/lib/function";
import * as B from "fp-ts/lib/boolean";
import { ButtonSolidProps, IOPictograms } from "@pagopa/io-app-design-system";
import { useIODispatch, useIOSelector } from "../../../../store/hooks";
import {
useIODispatch,
useIOSelector,
useIOStore
} from "../../../../store/hooks";
import { emptyListReasonSelector } from "../../store/reducers/allPaginated";
import { OperationResultScreenContent } from "../../../../components/screens/OperationResultScreenContent";
import I18n from "../../../../i18n";
import { reloadAllMessages } from "../../store/actions";
import { pageSize } from "../../../../config";
import { MessageListCategory } from "../../types/messageListCategory";
import { isArchivingInProcessingModeSelector } from "../../store/reducers/archiving";

export type EmptyListProps = {
category: MessageListCategory;
Expand All @@ -24,9 +31,31 @@ type ScreenDataType = {

export const EmptyList = ({ category }: EmptyListProps) => {
const dispatch = useIODispatch();
const store = useIOStore();

const emptyListReason = useIOSelector(state =>
emptyListReasonSelector(state, category)
);
const onRetryCallback = useCallback(
() =>
pipe(
store.getState(),
isArchivingInProcessingModeSelector,
B.fold(
() =>
pipe(
{
pageSize,
filter: { getArchived: category === "ARCHIVE" }
},
reloadAllMessages.request,
dispatch
),
constUndefined
)
),
[category, dispatch, store]
);

const screenData = useMemo((): ScreenDataType | undefined => {
switch (emptyListReason) {
Expand All @@ -42,21 +71,15 @@ export const EmptyList = ({ category }: EmptyListProps) => {
action: {
testID: "home_emptyList_retry",
label: I18n.t("global.buttons.retry"),
onPress: () =>
dispatch(
reloadAllMessages.request({
pageSize,
filter: { getArchived: category === "ARCHIVE" }
})
)
onPress: onRetryCallback
},
pictogram: "fatalError",
title: I18n.t("messages.loadingErrorTitle")
};
default:
return undefined;
}
}, [category, dispatch, emptyListReason]);
}, [category, emptyListReason, onRetryCallback]);

if (!screenData) {
return null;
Expand Down
8 changes: 7 additions & 1 deletion ts/features/messages/components/Home/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ export const MessageList = React.forwardRef<FlatList, MessageListProps>(
/>
);
} else {
return <WrappedMessageListItem index={index} message={item} />;
return (
<WrappedMessageListItem
index={index}
listCategory={category}
message={item}
/>
);
}
}}
ListFooterComponent={<Footer category={category} />}
Expand Down
38 changes: 21 additions & 17 deletions ts/features/messages/components/Home/PagerViewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getMessagesViewPagerInitialPageIndex,
messageViewPageIndexToListCategory
} from "./homeUtils";
import { ArchiveRestoreBar } from "./ArchiveRestoreBar";

export const PagerViewContainer = React.forwardRef<PagerView>((_, ref) => {
const dispatch = useIODispatch();
Expand Down Expand Up @@ -89,22 +90,25 @@ export const PagerViewContainer = React.forwardRef<PagerView>((_, ref) => {
}, [dispatchReloadAllMessagesIfNeeded, store]);

return (
<PagerView
initialPage={initialPageIndex}
onPageSelected={onPagerViewPageSelected}
ref={ref}
style={IOStyles.flex}
>
<MessageList
category={"INBOX"}
key={`message_list_inbox`}
ref={inboxFlatListRef}
/>
<MessageList
category={"ARCHIVE"}
key={`message_list_category`}
ref={archiveFlatListRef}
/>
</PagerView>
<>
<PagerView
initialPage={initialPageIndex}
onPageSelected={onPagerViewPageSelected}
ref={ref}
style={IOStyles.flex}
>
<MessageList
category={"INBOX"}
key={`message_list_inbox`}
ref={inboxFlatListRef}
/>
<MessageList
category={"ARCHIVE"}
key={`message_list_category`}
ref={archiveFlatListRef}
/>
</PagerView>
<ArchiveRestoreBar />
</>
);
});
37 changes: 15 additions & 22 deletions ts/features/messages/components/Home/Toasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,35 @@ import { useIOToast } from "@pagopa/io-app-design-system";
import { useIOSelector } from "../../../../store/hooks";
import {
archiveMessagesErrorReasonSelector,
inboxMessagesErrorReasonSelector,
latestMessageOperationToastTypeSelector,
latestMessageOperationTranslationKeySelector
inboxMessagesErrorReasonSelector
} from "../../store/reducers/allPaginated";
import I18n from "../../../../i18n";
import {
processingResultReasonSelector,
processingResultTypeSelector
} from "../../store/reducers/archiving";

export const Toasts = () => {
const toast = useIOToast();

// Handling of archiving/unarchiving operations result
const latestMessageOperationToastType = useIOSelector(
latestMessageOperationToastTypeSelector
);
const latestMessageOperationTranslationKey = useIOSelector(
latestMessageOperationTranslationKeySelector
);
const processingResultType = useIOSelector(processingResultTypeSelector);
const processingResultReason = useIOSelector(processingResultReasonSelector);
useEffect(() => {
if (
latestMessageOperationToastType &&
latestMessageOperationTranslationKey
) {
const translationKey = I18n.t(latestMessageOperationTranslationKey);
switch (latestMessageOperationToastType) {
if (processingResultType && processingResultReason) {
switch (processingResultType) {
case "error":
toast.error(translationKey);
toast.error(processingResultReason);
break;
case "success":
toast.success(translationKey);
toast.success(processingResultReason);
break;
case "warning":
toast.warning(processingResultReason);
break;
}
}
}, [
latestMessageOperationToastType,
latestMessageOperationTranslationKey,
toast
]);
}, [processingResultType, processingResultReason, toast]);

// Handling of inbox messages errors. Be aware that any error
// that happens when the list is empty is not displayed with
Expand Down
Loading
Loading