From 0e6b1e9e64c0d6e66185a0ac8d96ca86f177e050 Mon Sep 17 00:00:00 2001 From: thoreyjona Date: Tue, 1 Oct 2024 11:17:31 +0000 Subject: [PATCH] feat: use isUrgent to decide if we should includeDocument or not --- .../document-detail/document-detail.tsx | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/apps/native/app/src/screens/document-detail/document-detail.tsx b/apps/native/app/src/screens/document-detail/document-detail.tsx index 7a1e0c5a7c66..246c19f9021d 100644 --- a/apps/native/app/src/screens/document-detail/document-detail.tsx +++ b/apps/native/app/src/screens/document-detail/document-detail.tsx @@ -218,8 +218,7 @@ const PdfViewer = React.memo( export const DocumentDetailScreen: NavigationFunctionComponent<{ docId: string isUrgent?: boolean - confirmation?: DocumentV2Action -}> = ({ componentId, docId, isUrgent, confirmation }) => { +}> = ({ componentId, docId, isUrgent }) => { useNavigationOptions(componentId) const client = useApolloClient() @@ -247,18 +246,26 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{ returnPartialData: true, }) + // We want to make sure we don't include the document content if isUrgent is undefined/null since then we don't have + // the info from the server and don't want to make any assumptions about it just yet + const shouldIncludeDocument = !( + isUrgent === true || + isUrgent === undefined || + isUrgent === null + ) + // Fetch the document to get the content information const docRes = useGetDocumentQuery({ variables: { input: { id: docId, - // If the document has a confirmation action we first need to show confirmation modal before fetching the document content - includeDocument: !!confirmation, + // If the document is urgent we need to check if the user needs to confirm reception of it before fetching the document data + includeDocument: shouldIncludeDocument, }, locale: locale === 'is-IS' ? 'is' : 'en', }, fetchPolicy: 'no-cache', - onCompleted: (data) => { + onCompleted: async (data) => { const confirmation = data.documentV2?.confirmation if (confirmation && !refetching && !showConfirmedAlert) { RNAlert.alert(confirmation.title ?? '', confirmation.data ?? '', [ @@ -290,6 +297,19 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{ }, }, ]) + } else if (!confirmation && !refetching) { + // If the user has already confirmed accepting the document we fetch the content + setRefetching(true) + try { + const result = await docRes.refetch({ + input: { id: docId, includeDocument: true }, + }) + if (result.data?.documentV2?.alert) { + setShowConfirmedAlert(true) + } + } finally { + setRefetching(false) + } } }, })