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(Firma con IO): [SFEQS-2071] Update Firma con IO with new DS components #5377

Merged
merged 66 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
ef8743a
chore: update
hevelius Jan 2, 2024
57eb58e
chore: update
hevelius Jan 2, 2024
bfeffcb
chore: update documents navigation bar
hevelius Jan 4, 2024
a01ffe7
chore: add loading component
hevelius Jan 4, 2024
bba48af
chore: update router screen
hevelius Jan 4, 2024
d5395eb
chore: update documents screen
hevelius Jan 4, 2024
8df1f63
chore: update signature field item
hevelius Jan 4, 2024
1966fcb
chore: update document signature preview
hevelius Jan 4, 2024
e5737dc
chore: update data sharing screen
hevelius Jan 4, 2024
6393c26
chore: update qtsp screen
hevelius Jan 4, 2024
8e60204
chore: update signature fields screen
hevelius Jan 4, 2024
8bfe166
chore: update typ
hevelius Jan 4, 2024
224bc0f
chore: update signautre requests list
hevelius Jan 4, 2024
248c33c
chore: update error component
hevelius Jan 4, 2024
4029d52
chore: update abort hook
hevelius Jan 4, 2024
90cdaa1
chore: update check service hook
hevelius Jan 4, 2024
7fbd71f
chore: no signature fields hook
hevelius Jan 4, 2024
ff485de
chore: update check service hook
hevelius Jan 4, 2024
782d193
chore: remove unused ref from check service hook
hevelius Jan 4, 2024
706a349
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 4, 2024
7b92301
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 8, 2024
bbb8124
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 10, 2024
8763b89
chore: migrate to header second level
hevelius Jan 11, 2024
80eac64
chore: update
hevelius Jan 11, 2024
aff1669
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 11, 2024
6229773
chore: use header second level hook
hevelius Jan 11, 2024
12a3a2c
fix: test
hevelius Jan 11, 2024
dcb1292
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 11, 2024
e6e1d21
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
shadowsheep1 Jan 12, 2024
0d642e0
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 15, 2024
3d8a28b
test: update snapshots
hevelius Jan 15, 2024
43caf39
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 15, 2024
927178f
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 16, 2024
cbc2d9c
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 17, 2024
c1e5022
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 17, 2024
3165d77
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 19, 2024
f71c713
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 22, 2024
37bbf8b
test: update snapshot
hevelius Jan 22, 2024
2763380
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 23, 2024
a5d0382
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 24, 2024
d4196d1
chore: update
hevelius Jan 24, 2024
a9e6857
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 24, 2024
e06c0d6
chore: update
hevelius Jan 25, 2024
1c1a8c3
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 25, 2024
adfc970
test: fix id
hevelius Jan 25, 2024
6944918
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 25, 2024
18e098d
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 25, 2024
69b1c6f
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 26, 2024
07fa8b4
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 29, 2024
c380adc
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 29, 2024
f029570
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 30, 2024
41fd877
chore: switch to safe-area-context
hevelius Jan 30, 2024
631a748
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 30, 2024
aef6bf9
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 30, 2024
c0671b1
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 30, 2024
999500e
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 30, 2024
59a92cf
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 31, 2024
1391fea
chore: add insets
hevelius Jan 31, 2024
cb2285b
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 31, 2024
f1eeda4
chore: update
hevelius Jan 31, 2024
be30280
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Jan 31, 2024
0efa059
chore: update spacing
hevelius Feb 1, 2024
1b3f73a
chore: update
hevelius Feb 2, 2024
2586b41
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Feb 2, 2024
5f40450
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Feb 2, 2024
c3bf1e7
Merge branch 'master' into SFEQS-2071-refactor-new-ds-component
hevelius Feb 2, 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
152 changes: 80 additions & 72 deletions ts/features/fci/components/DocumentViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import React, { useState } from "react";
import { StyleSheet } from "react-native";
import { constNull } from "fp-ts/lib/function";
import * as pot from "@pagopa/ts-commons/lib/pot";
import ReactNativeBlobUtil from "react-native-blob-util";
import Pdf from "react-native-pdf";
import * as S from "fp-ts/lib/string";
import { IOColors } from "@pagopa/io-app-design-system";
import FooterWithButtons from "../../../components/ui/FooterWithButtons";
import {
ButtonSolidProps,
FooterWithButtons,
IOColors
} from "@pagopa/io-app-design-system";
import I18n from "../../../i18n";
import { isIos } from "../../../utils/platform";
import { share } from "../../../utils/share";
import { showToast } from "../../../utils/showToast";
import { confirmButtonProps } from "../../../components/buttons/ButtonConfigurations";
import { FciDownloadPreviewDirectoryPath } from "../saga/networking/handleDownloadDocument";
import { useIODispatch, useIOSelector } from "../../../store/hooks";
import { fciDownloadPreview } from "../store/actions";
import {
fciDownloadPathSelector,
fciDownloadPreviewSelector
} from "../store/reducers/fciDownloadPreview";
import { LoadingErrorComponent } from "../../../components/LoadingErrorComponent";
import LoadingComponent from "./LoadingComponent";

const styles = StyleSheet.create({
pdf: {
Expand All @@ -31,72 +32,88 @@ const styles = StyleSheet.create({
export const getFileNameFromUrl = (url: string) =>
url.substring(url.lastIndexOf("/") + 1).split("?")[0] + ".pdf";

const renderFooter = (url: string, filePath: string) =>
isIos ? (
const renderFooter = (url: string, filePath: string) => {
const confirmButtonProps: ButtonSolidProps = {
onPress: () => ReactNativeBlobUtil.ios.presentOptionsMenu(filePath),
label: I18n.t("messagePDFPreview.open"),
accessibilityLabel: I18n.t("messagePDFPreview.open")
};

const shareButtonProps: ButtonSolidProps = {
onPress: () => {
share(
`file://${
FciDownloadPreviewDirectoryPath + "/" + getFileNameFromUrl(url)
}`,
undefined,
false
)().catch(_ => {
showToast(I18n.t("messagePDFPreview.errors.sharing"));
});
},
label: I18n.t("global.buttons.share"),
accessibilityLabel: I18n.t("global.buttons.share")
};

const saveButtonProps: ButtonSolidProps = {
onPress: () => {
ReactNativeBlobUtil.MediaCollection.copyToMediaStore(
{
name: getFileNameFromUrl(url),
parentFolder: "",
mimeType: "application/pdf"
},
"Download",
FciDownloadPreviewDirectoryPath + "/" + getFileNameFromUrl(url)
)
.then(_ => {
showToast(
I18n.t("messagePDFPreview.savedAtLocation", {
name: "attachment.displayName"
}),
"success"
);
})
.catch(_ => {
showToast(I18n.t("messagePDFPreview.errors.saving"));
});
},
label: I18n.t("messagePDFPreview.save"),
accessibilityLabel: I18n.t("messagePDFPreview.save")
};

const openButtonProps: ButtonSolidProps = {
onPress: () => {
ReactNativeBlobUtil.android
.actionViewIntent(
FciDownloadPreviewDirectoryPath + "/" + getFileNameFromUrl(url),
"application/pdf"
)
.catch(_ => {
showToast(I18n.t("messagePDFPreview.errors.opening"));
});
},
label: I18n.t("messagePDFPreview.open"),
accessibilityLabel: I18n.t("messagePDFPreview.open")
};

return isIos ? (
<FooterWithButtons
type={"SingleButton"}
leftButton={confirmButtonProps(() => {
ReactNativeBlobUtil.ios.presentOptionsMenu(filePath);
}, I18n.t("messagePDFPreview.open"))}
primary={{ type: "Solid", buttonProps: confirmButtonProps }}
/>
) : (
<FooterWithButtons
type={"ThreeButtonsInLine"}
leftButton={{
bordered: true,
primary: false,
onPress: () => {
share(
`file://${
FciDownloadPreviewDirectoryPath + "/" + getFileNameFromUrl(url)
}`,
undefined,
false
)().catch(_ => {
showToast(I18n.t("messagePDFPreview.errors.sharing"));
});
},
title: I18n.t("global.buttons.share")
}}
midButton={{
bordered: true,
primary: false,
onPress: () => {
ReactNativeBlobUtil.MediaCollection.copyToMediaStore(
{
name: getFileNameFromUrl(url),
parentFolder: "",
mimeType: "application/pdf"
},
"Download",
FciDownloadPreviewDirectoryPath + "/" + getFileNameFromUrl(url)
)
.then(_ => {
showToast(
I18n.t("messagePDFPreview.savedAtLocation", {
name: "attachment.displayName"
}),
"success"
);
})
.catch(_ => {
showToast(I18n.t("messagePDFPreview.errors.saving"));
});
},
title: I18n.t("messagePDFPreview.save")
primary={{
type: "Solid",
buttonProps: shareButtonProps
}}
rightButton={confirmButtonProps(() => {
ReactNativeBlobUtil.android
.actionViewIntent(
FciDownloadPreviewDirectoryPath + "/" + getFileNameFromUrl(url),
"application/pdf"
)
.catch(_ => {
showToast(I18n.t("messagePDFPreview.errors.opening"));
});
}, I18n.t("messagePDFPreview.open"))}
secondary={{ type: "Outline", buttonProps: saveButtonProps }}
third={{ type: "Outline", buttonProps: openButtonProps }}
/>
);
};

type Props = {
documentUrl: string;
Expand All @@ -106,15 +123,6 @@ type Props = {
onError: () => void;
};

const LoadingComponent = () => (
<LoadingErrorComponent
isLoading={true}
loadingCaption={""}
onRetry={constNull}
testID={"FciRouterLoadingScreenTestID"}
/>
);

export const DocumentViewer = (props: Props): React.ReactElement => {
const [isError, setIsError] = useState(false);
const documentUrl = props.documentUrl;
Expand All @@ -128,7 +136,7 @@ export const DocumentViewer = (props: Props): React.ReactElement => {
}, [documentUrl, dispatch]);

if (pot.isLoading(fciDownloadSelector)) {
return <LoadingComponent />;
return <LoadingComponent testID={"FciRouterLoadingScreenTestID"} />;
}

if (pot.isError(fciDownloadSelector) || isError) {
Expand Down
109 changes: 58 additions & 51 deletions ts/features/fci/components/DocumentWithSignature.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import * as React from "react";
import Pdf from "react-native-pdf";
import { Body, Container, Left, Right } from "native-base";
import { constNull, pipe } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import * as pot from "@pagopa/ts-commons/lib/pot";
import { SafeAreaView, StyleSheet } from "react-native";
import { IconButton, IOColors } from "@pagopa/io-app-design-system";
import { IOStyles } from "../../../components/core/variables/IOStyles";
import FooterWithButtons from "../../../components/ui/FooterWithButtons";
import { StyleSheet, View } from "react-native";
import {
ButtonSolidProps,
FooterWithButtons,
H5,
HSpacer,
IconButton,
IOColors,
IOStyles,
VSpacer
} from "@pagopa/io-app-design-system";
import { SafeAreaView } from "react-native-safe-area-context";
import I18n from "../../../i18n";
import { ExistingSignatureFieldAttrs } from "../../../../definitions/fci/ExistingSignatureFieldAttrs";
import { SignatureFieldToBeCreatedAttrs } from "../../../../definitions/fci/SignatureFieldToBeCreatedAttrs";
import { fciSignatureDetailDocumentsSelector } from "../store/reducers/fciSignatureRequest";
import AppHeader from "../../../components/ui/AppHeader";
import { useIODispatch, useIOSelector } from "../../../store/hooks";
import { WithTestID } from "../../../types/WithTestID";
import { H5 } from "../../../components/core/typography/H5";
import { useOnFirstRender } from "../../../utils/hooks/useOnFirstRender";
import { fciDocumentSignatureFields } from "../store/actions";
import { fciSignatureFieldDrawingSelector } from "../store/reducers/fciSignatureFieldDrawing";
import LoadingSpinnerOverlay from "../../../components/LoadingSpinnerOverlay";
import DocumentsNavigationBar from "./DocumentsNavigationBar";
import LoadingComponent from "./LoadingComponent";

export type SignatureFieldAttrType =
| ExistingSignatureFieldAttrs
Expand All @@ -37,6 +42,14 @@ const styles = StyleSheet.create({
pdf: {
flex: 1,
backgroundColor: IOColors.bluegrey
},
header: {
alignItems: "center",
flexDirection: "row"
},
headerTitle: {
flex: 1,
textAlign: "center"
}
});

Expand All @@ -49,11 +62,12 @@ const DocumentWithSignature = (props: Props) => {
const { attrs, currentDoc } = props;
const dispatch = useIODispatch();
const onContinuePress = () => props.onClose();
const continueButtonProps = {
block: true,
primary: true,
const continueButtonProps: ButtonSolidProps = {
onPress: onContinuePress,
title: I18n.t("features.fci.documents.footer.backToSignFieldsList")
label: I18n.t("features.fci.documents.footer.backToSignFieldsList"),
accessibilityLabel: I18n.t(
"features.fci.documents.footer.backToSignFieldsList"
)
};

/**
Expand Down Expand Up @@ -139,12 +153,6 @@ const DocumentWithSignature = (props: Props) => {
);
};

/**
* Renders the loading spinner.
* @returns a loading spinner overlay
*/
const LoadingView = () => <LoadingSpinnerOverlay isLoading={true} />;

/**
* Callback to be used when the pdf cannot be loaded or the signature field cannot be drawn.
* It returns an empty fragment and calls the `onError` callback.
Expand All @@ -161,39 +169,40 @@ const DocumentWithSignature = (props: Props) => {
() =>
pot.fold(
parsedDocuments,
() => <LoadingView />,
() => <LoadingView />,
() => <LoadingView />,
() => <LoadingComponent />,
() => <LoadingComponent />,
() => <LoadingComponent />,
() => <ErrorView />,
some => (
<RenderPdf document={some.drawnBase64} page={some.signaturePage} />
),
() => <LoadingView />,
() => <LoadingView />,
() => <LoadingComponent />,
() => <LoadingComponent />,
() => <ErrorView />
),
[ErrorView, RenderPdf, parsedDocuments]
);

return (
<Container>
<AppHeader>
<Left />
<Body style={{ alignItems: "center" }}>
<H5 weight={"SemiBold"} color={"bluegrey"}>
{I18n.t("messagePDFPreview.title")}
</H5>
</Body>
<Right>
<IconButton
icon="closeLarge"
onPress={props.onClose}
color="neutral"
testID="FciDocumentWithSignatureTopRightButtonTestID"
accessibilityLabel={I18n.t("global.buttons.close")}
/>
</Right>
</AppHeader>
<SafeAreaView
style={[IOStyles.flex, IOStyles.bgWhite]}
testID={"FciDocumentsScreenTestID"}
edges={["bottom", "left", "right"]}
>
<View style={[IOStyles.horizontalContentPadding, styles.header]}>
<HSpacer />
<H5 weight={"SemiBold"} color={"bluegrey"} style={styles.headerTitle}>
{I18n.t("messagePDFPreview.title")}
</H5>
<IconButton
color="neutral"
accessibilityLabel={I18n.t("global.buttons.close")}
icon="closeLarge"
onPress={props.onClose}
testID="FciDocumentWithSignatureTopRightButtonTestID"
/>
</View>
<VSpacer />
<DocumentsNavigationBar
indicatorPosition={"right"}
titleLeft={I18n.t("features.fci.documentsBar.titleLeft", {
Expand All @@ -204,21 +213,19 @@ const DocumentWithSignature = (props: Props) => {
currentPage,
totalPages
})}
iconLeftColor={currentPage === 1 ? "bluegreyLight" : "blue"}
iconRightColor={currentPage === totalPages ? "bluegreyLight" : "blue"}
iconLeftDisabled={currentPage === 1}
iconRightDisabled={currentPage === totalPages}
onPrevious={onPrevious}
onNext={onNext}
disabled={false}
testID={"FciDocumentsNavBarTestID"}
/>
<SafeAreaView style={IOStyles.flex} testID={"FciDocumentsScreenTestID"}>
<RenderMask />
<FooterWithButtons
type={"SingleButton"}
leftButton={continueButtonProps}
/>
</SafeAreaView>
</Container>
<RenderMask />
<FooterWithButtons
type={"SingleButton"}
primary={{ type: "Solid", buttonProps: continueButtonProps }}
/>
</SafeAreaView>
);
};
export default DocumentWithSignature;
Loading
Loading