Skip to content

Commit

Permalink
feat: use isUrgent to decide if we should includeDocument or not
Browse files Browse the repository at this point in the history
  • Loading branch information
thoreyjona committed Oct 4, 2024
1 parent bd9d843 commit 0e6b1e9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions apps/native/app/src/screens/document-detail/document-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 ?? '', [
Expand Down Expand Up @@ -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)
}
}
},
})
Expand Down

0 comments on commit 0e6b1e9

Please sign in to comment.