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

fix(service-portal-licenses): Fix async pkpass generation #14969

Merged
merged 3 commits into from
May 28, 2024
Merged
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useEffect, useState } from 'react'
import { useMutation } from '@apollo/client'
thorkellmani marked this conversation as resolved.
Show resolved Hide resolved
import { Box, Button, toast } from '@island.is/island-ui/core'
import { theme } from '@island.is/island-ui/theme'
import { useLocale } from '@island.is/localization'
import { Locale } from '@island.is/shared/types'
import { useMutation } from '@apollo/client'
import {
FeatureFlagClient,
useFeatureFlagClient,
} from '@island.is/react/feature-flags'
thorkellmani marked this conversation as resolved.
Show resolved Hide resolved
import {
CREATE_PK_PASS,
GenericLicenseType,
useUserProfile,
} from '@island.is/service-portal/graphql'
import { Locale } from '@island.is/shared/types'
import { useEffect, useState } from 'react'
import { useWindowSize } from 'react-use'
import { m } from '../../lib/messages'
import { theme } from '@island.is/island-ui/theme'
import { hasPassedTimeout } from '../../utils/dateUtils'
import {
FeatureFlagClient,
useFeatureFlagClient,
} from '@island.is/react/feature-flags'
import { useWindowSize } from 'react-use'
import { DriversLicensePkPass } from './DriversLicensePkPass'

type PkPassProps = {
Expand Down Expand Up @@ -56,7 +56,7 @@
}
}
isFlagEnabled()
}, [])

Check warning on line 59 in libs/service-portal/licenses/src/components/QRCodeModal/PkPass.tsx

View workflow job for this annotation

GitHub Actions / linting (service-portal,service-portal-licenses)

React Hook useEffect has a missing dependency: 'featureFlagClient'. Either include it or remove the dependency array

useEffect(() => {
if (width < theme.breakpoints.md) {
Expand All @@ -75,19 +75,24 @@
setTimeout(() => setLinkError(false), 5000)
}

const getLink = async () => {
useEffect(() => {
thorkellmani marked this conversation as resolved.
Show resolved Hide resolved
if (pkpassUrl && !hasPassedTimeout(linkTimestamp, 10)) {
window.open(pkpassUrl)
setDisplayLoader(false)
return
window.location.assign(pkpassUrl)
}
}, [pkpassUrl, linkTimestamp])
thorkellmani marked this conversation as resolved.
Show resolved Hide resolved

const getLink = async () => {
await generatePkPass({
variables: { locale, input: { licenseType } },
})
.then((response) => {
if (!response.errors && window && typeof window !== 'undefined') {
setPkpassUrl(response?.data?.generatePkPass?.pkpassUrl)
window.location.assign(response?.data?.generatePkPass?.pkpassUrl)
if (
!response.errors &&
window &&
typeof window !== 'undefined' &&
response?.data?.generatePkPass?.pkpassUrl
) {
setPkpassUrl(response.data.generatePkPass.pkpassUrl)
thorkellmani marked this conversation as resolved.
Show resolved Hide resolved
setFetched(true)
setDisplayLoader(false)
setLinkTimestamp(new Date())
Expand Down
Loading