-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [IOCOM-1560] Fims history screen (#6021)
## Short description Addition of FIMS history screen, with email export coming soon <img src="https://github.com/user-attachments/assets/c3d804a1-96f6-489a-9d2e-5d5227731af3" width=250/> ## List of changes proposed in this pull request - required i18n keys - new simplified utility pot fold function - required selectors - required screen and components - full design-perfect screen coming soon due to problematic component interactions - new auto fetching/refreshing service data hook ## How to test using the dev-server, while checked out in the fims testing branch, navigate to profile>privacy>third party accesses and make sure everything is working as intended --------- Co-authored-by: Andrea <[email protected]>
- Loading branch information
Showing
12 changed files
with
226 additions
and
38 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
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,22 @@ | ||
import * as React from "react"; | ||
import { ServiceId } from "../../../../../definitions/backend/ServiceId"; | ||
import { useIODispatch, useIOSelector } from "../../../../store/hooks"; | ||
import { serviceByIdPotSelector } from "../../../services/details/store/reducers"; | ||
import { loadServiceDetail } from "../../../services/details/store/actions/details"; | ||
import { isStrictNone } from "../../../../utils/pot"; | ||
|
||
export const useAutoFetchingServiceByIdPot = (serviceId: ServiceId) => { | ||
const dispatch = useIODispatch(); | ||
const serviceData = useIOSelector(state => | ||
serviceByIdPotSelector(state, serviceId) | ||
); | ||
const shouldFetchServiceData = isStrictNone(serviceData); | ||
|
||
React.useEffect(() => { | ||
if (shouldFetchServiceData) { | ||
dispatch(loadServiceDetail.request(serviceId)); | ||
} | ||
}, [dispatch, serviceId, shouldFetchServiceData]); | ||
|
||
return { serviceData }; | ||
}; |
42 changes: 42 additions & 0 deletions
42
ts/features/fims/history/components/FimsHistoryListItem.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,42 @@ | ||
import { ListItemNav } from "@pagopa/io-app-design-system"; | ||
import { constNull } from "fp-ts/lib/function"; | ||
import * as React from "react"; | ||
import { ServiceId } from "../../../../../definitions/backend/ServiceId"; | ||
import { ServicePublic } from "../../../../../definitions/backend/ServicePublic"; | ||
import { Consent } from "../../../../../definitions/fims/Consent"; | ||
import { dateToAccessibilityReadableFormat } from "../../../../utils/accessibility"; | ||
import { potFoldWithDefault } from "../../../../utils/pot"; | ||
import { useAutoFetchingServiceByIdPot } from "../../common/utils/hooks"; | ||
import { LoadingFimsHistoryListItem } from "./FimsHistoryLoaders"; | ||
|
||
type SuccessListItemProps = { | ||
serviceData: ServicePublic; | ||
consent: Consent; | ||
}; | ||
const SuccessListItem = ({ serviceData, consent }: SuccessListItemProps) => ( | ||
<ListItemNav | ||
onPress={constNull} | ||
value={serviceData.organization_name} | ||
topElement={{ | ||
dateValue: dateToAccessibilityReadableFormat(consent.timestamp) | ||
}} | ||
description={consent.redirect?.display_name} | ||
hideChevron | ||
/> | ||
); | ||
type HistoryListItemProps = { | ||
item: Consent; | ||
}; | ||
|
||
export const FimsHistoryListItem = ({ item }: HistoryListItemProps) => { | ||
const { serviceData } = useAutoFetchingServiceByIdPot( | ||
item.service_id as ServiceId | ||
); | ||
|
||
return potFoldWithDefault(serviceData, { | ||
default: LoadingFimsHistoryListItem, | ||
some: data => <SuccessListItem serviceData={data} consent={item} />, | ||
someError: data => <SuccessListItem serviceData={data} consent={item} />, | ||
someLoading: data => <SuccessListItem serviceData={data} consent={item} /> | ||
}); | ||
}; |
25 changes: 25 additions & 0 deletions
25
ts/features/fims/history/components/FimsHistoryLoaders.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,25 @@ | ||
import { Divider } from "@pagopa/io-app-design-system"; | ||
import * as React from "react"; | ||
import { View } from "react-native"; | ||
import Placeholder from "rn-placeholder"; | ||
|
||
export const LoadingFimsHistoryItemsFooter = ({ | ||
showFirstDivider | ||
}: { | ||
showFirstDivider?: boolean; | ||
}) => ( | ||
<> | ||
{showFirstDivider && <Divider />} | ||
<LoadingFimsHistoryListItem /> | ||
<Divider /> | ||
<LoadingFimsHistoryListItem /> | ||
<Divider /> | ||
<LoadingFimsHistoryListItem /> | ||
</> | ||
); | ||
|
||
export const LoadingFimsHistoryListItem = () => ( | ||
<View style={{ paddingVertical: 16 }}> | ||
<Placeholder.Box height={16} width={178} radius={8} animate="fade" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,76 @@ | ||
import { VSpacer } from "@pagopa/io-app-design-system"; | ||
import * as pot from "@pagopa/ts-commons/lib/pot"; | ||
import { Body, Divider, IOStyles, VSpacer } from "@pagopa/io-app-design-system"; | ||
import { constNull } from "fp-ts/lib/function"; | ||
import * as React from "react"; | ||
import { SafeAreaView, Text, View } from "react-native"; | ||
import LoadingScreenContent from "../../../../components/screens/LoadingScreenContent"; | ||
import { FlatList, SafeAreaView, View } from "react-native"; | ||
import { FooterActions } from "../../../../components/ui/FooterActions"; | ||
import { useHeaderSecondLevel } from "../../../../hooks/useHeaderSecondLevel"; | ||
import I18n from "../../../../i18n"; | ||
import { useIODispatch, useIOSelector } from "../../../../store/hooks"; | ||
import { FimsHistoryListItem } from "../components/FimsHistoryListItem"; | ||
import { LoadingFimsHistoryItemsFooter } from "../components/FimsHistoryLoaders"; | ||
import { fimsHistoryGet } from "../store/actions"; | ||
import { fimsHistoryPotSelector } from "../store/selectors"; | ||
import { | ||
fimsHistoryToUndefinedSelector, | ||
isFimsHistoryLoadingSelector | ||
} from "../store/selectors"; | ||
|
||
export const FimsHistoryScreen = () => { | ||
const dispatch = useIODispatch(); | ||
const historyPot = useIOSelector(fimsHistoryPotSelector); | ||
const isLoading = useIOSelector(isFimsHistoryLoadingSelector); | ||
const consents = useIOSelector(fimsHistoryToUndefinedSelector); | ||
|
||
React.useEffect(() => { | ||
dispatch(fimsHistoryGet.request({})); | ||
dispatch(fimsHistoryGet.request({ shouldReloadFromScratch: true })); | ||
}, [dispatch]); | ||
|
||
const fetchMore = React.useCallback(() => { | ||
if (consents?.continuationToken) { | ||
dispatch( | ||
fimsHistoryGet.request({ | ||
continuationToken: consents.continuationToken | ||
}) | ||
); | ||
} | ||
}, [consents?.continuationToken, dispatch]); | ||
|
||
const renderLoadingFooter = () => | ||
isLoading ? ( | ||
<LoadingFimsHistoryItemsFooter | ||
showFirstDivider={(consents?.items.length ?? 0) > 0} | ||
/> | ||
) : null; | ||
useHeaderSecondLevel({ | ||
title: "History" | ||
title: I18n.t("FIMS.history.historyScreen.header"), | ||
supportRequest: true | ||
}); | ||
if (pot.isLoading(historyPot)) { | ||
return <LoadingScreenContent contentTitle="" />; | ||
} | ||
const history = pot.toUndefined(historyPot)?.items ?? []; | ||
|
||
return ( | ||
<SafeAreaView style={{ flex: 1 }}> | ||
{history.map((item, index) => ( | ||
<View key={index}> | ||
<Text>{item.timestamp.toDateString()}</Text> | ||
<VSpacer size={8} /> | ||
<> | ||
<SafeAreaView> | ||
<View style={IOStyles.horizontalContentPadding}> | ||
<Body>{I18n.t("FIMS.history.historyScreen.body")}</Body> | ||
</View> | ||
))} | ||
</SafeAreaView> | ||
|
||
<VSpacer size={16} /> | ||
|
||
<FlatList | ||
data={consents?.items} | ||
contentContainerStyle={IOStyles.horizontalContentPadding} | ||
ItemSeparatorComponent={Divider} | ||
keyExtractor={item => item.id} | ||
renderItem={item => <FimsHistoryListItem item={item.item} />} | ||
onEndReached={fetchMore} | ||
ListFooterComponent={renderLoadingFooter} | ||
/> | ||
</SafeAreaView> | ||
<FooterActions | ||
actions={{ | ||
type: "SingleButton", | ||
primary: { | ||
label: I18n.t("FIMS.history.exportData.CTA"), | ||
onPress: constNull // full export functionality coming soon | ||
} | ||
}} | ||
/> | ||
</> | ||
); | ||
}; |
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
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