-
Notifications
You must be signed in to change notification settings - Fork 3
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
1430: Add query params to card self service form #1749
Changes from 7 commits
bf49cd7
34cb958
6224bbb
de0acba
654280a
64eba61
ee12261
db61b23
26bc352
0dbdae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { ApolloError } from '@apollo/client' | ||
import React, { useCallback, useContext, useState } from 'react' | ||
import React, { useCallback, useContext, useEffect, useState } from 'react' | ||
import { useSearchParams } from 'react-router-dom' | ||
|
||
import { Card, generateCardInfo, initializeCard } from '../../../cards/Card' | ||
import { Card, generateCardInfo, initializeCardFromCSV } from '../../../cards/Card' | ||
import { generatePdf } from '../../../cards/PdfFactory' | ||
import { CreateCardsError, CreateCardsResult } from '../../../cards/createCards' | ||
import getMessageFromApolloError from '../../../errors/getMessageFromApolloError' | ||
|
@@ -12,6 +13,7 @@ import { base64ToUint8Array, uint8ArrayToBase64 } from '../../../util/base64' | |
import downloadDataUri from '../../../util/downloadDataUri' | ||
import getCustomDeepLinkFromQrCode from '../../../util/getCustomDeepLinkFromQrCode' | ||
import { useAppToaster } from '../../AppToaster' | ||
import { getHeaders } from '../../cards/ImportCardsController' | ||
import FormErrorMessage from '../components/FormErrorMessage' | ||
|
||
export enum CardSelfServiceStep { | ||
|
@@ -35,13 +37,21 @@ type UseCardGeneratorSelfServiceReturn = { | |
const useCardGeneratorSelfService = (): UseCardGeneratorSelfServiceReturn => { | ||
const projectConfig = useContext(ProjectConfigContext) | ||
const appToaster = useAppToaster() | ||
const [selfServiceCard, setSelfServiceCard] = useState( | ||
initializeCard(projectConfig.card, undefined, { expirationDate: null }) | ||
) | ||
const [cardQueryParams, setSearchParams] = useSearchParams() | ||
const [selfServiceCard, setSelfServiceCard] = useState(() => { | ||
const headers = getHeaders(projectConfig) | ||
const values = headers.map(header => cardQueryParams.get(header)) | ||
return initializeCardFromCSV(projectConfig.card, values, headers, undefined, true) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙃 I really like your implementation. If you feel motivated, feel free to add the same functionality to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should merge this soon to create the next beta artifact and i would prefer to implement this in a separate task There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have created a new ticket for that #1799 |
||
const [isLoading, setIsLoading] = useState<boolean>(false) | ||
const [selfServiceState, setSelfServiceState] = useState<CardSelfServiceStep>(CardSelfServiceStep.form) | ||
const [deepLink, setDeepLink] = useState<string>('') | ||
const [code, setCode] = useState<CreateCardsResult | null>(null) | ||
|
||
useEffect(() => { | ||
setSearchParams(undefined, { replace: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think its better to move this to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @f1sh1918 pls check if that's what you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you can just reuse the hook in const [_, setSearchParams] = useSearchParams() and execute the function as you did. Then you don't have to pass down the function neither to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hopefully, it's good to go now, thx 🙈 |
||
}, [setSearchParams]) | ||
|
||
const [createCardsSelfService] = useCreateCardsFromSelfServiceMutation() | ||
|
||
const handleErrors = useCallback( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧