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

1430: Add query params to card self service form #1749

Merged
merged 10 commits into from
Nov 25, 2024

Conversation

seluianova
Copy link
Contributor

@seluianova seluianova commented Nov 6, 2024

Short description

When the user taps the “Extend Card” button in the app, the self-service portal should open with the pre-filled data.
In this PR, I added support for query parameters in the /erstellen route.

I feel a bit lost in React, so perhaps my implementation is not optimal, pls take a look.

Proposed changes

  • query params in the card self service form: name, geburtsdatum, ref

Side effects

no?

Testing

Open url with query params
http://localhost:3000/erstellen?name=Karla%20Koblenz&ref=123K&geburtsdatum=2003-06-10
localhost:3000/erstellen?Name=Karla%20Koblenz&Referenznummer=123K&Geburtsdatum=10.06.2003
The form should be pre-filled with the provided data

Resolved issues

Part of: #1430

@seluianova seluianova linked an issue Nov 6, 2024 that may be closed by this pull request
3 tasks
@f1sh1918
Copy link
Contributor

f1sh1918 commented Nov 7, 2024

Some general ideas to your pr.
Instead of updating the card in a hook in the form component, i would suggest to add this functionality in the existing useCardGeneratorSelfService hook where the card will be initialized. That also avoids unexpected rerendering.

You can just add a fkt handleQueryParams and return the needed values there and then initlialize them. Please also provide some Error handling if birthday can not be parsed and show a toast to the user.

if you add Nullish Coalescing in the handle query params fkt and return undefined you can even avoid null checking while initializing the card

const fullName = cardQueryParams.get('name') ?? undefined

Example useCardGeneratorSelfService.ts

  const [cardQueryParams] = useSearchParams()
  const {fullName, birthday, koblenzReferenceNumber} = handleQueryParams(cardQueryParams)
  const [selfServiceCard, setSelfServiceCard] = useState(
  initializeCard(projectConfig.card, undefined, { fullName, expirationDate: null, extensions: {birthday, koblenzReferenceNumber } })
  )
  )

After generating a card successfully the queryParams should be removed. You can get a set fkt from the useSearchParams hook and do sth like

setSearchParams(undefined, { replace: true })

@seluianova
Copy link
Contributor Author

@f1sh1918 thanks for the feedback, I applied your suggestions, pls check if I understood you right.

@seluianova seluianova force-pushed the 1430-create-card-query-params branch from 3cf521b to 0922e1b Compare November 11, 2024 13:11
@seluianova seluianova force-pushed the 1430-create-card-query-params branch from 0922e1b to 6224bbb Compare November 11, 2024 13:46
@seluianova seluianova mentioned this pull request Nov 13, 2024
# Conflicts:
#	administration/src/bp-modules/self-service/CardSelfServiceForm.tsx
#	administration/src/bp-modules/self-service/hooks/useCardGeneratorSelfService.tsx
@seluianova seluianova force-pushed the 1430-create-card-query-params branch from 1eb8192 to ee12261 Compare November 20, 2024 20:57
Copy link
Member

@steffenkleinle steffenkleinle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something is not quite right yet, when I open the URL as you suggested nothing happens except the query params being removed. None of the supplied properties is used to initialize the card.

const [selfServiceCard, setSelfServiceCard] = useState(
initializeCard(projectConfig.card, undefined, { expirationDate: null })
)
const [cardQueryParams, setSearchParams] = useSearchParams()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧

Suggested change
const [cardQueryParams, setSearchParams] = useSearchParams()
const [searchParams, setSearchParams] = useSearchParams()

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 })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧
Could you perhaps move this inside the initializing method to avoid the extra use effect and possible side effects?

Copy link
Contributor

@f1sh1918 f1sh1918 Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its better to move this to the createKoblenzPass function to only remove them if the card was created successfully, so the params will not be removed if there is a page refresh (maybe by accident)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f1sh1918 pls check if that's what you mean

Copy link
Contributor

@f1sh1918 f1sh1918 Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can just reuse the hook in CardSelfServiceForm @seluianova

const [_, setSearchParams] = useSearchParams()

and execute the function as you did. Then you don't have to pass down the function neither to CardSelfServiceForm nor adjust the useCardSelfService hook

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully, it's good to go now, thx 🙈

@seluianova
Copy link
Contributor Author

seluianova commented Nov 21, 2024

I think something is not quite right yet, when I open the URL as you suggested nothing happens except the query params being removed

Ah, sorry, I forgot to update the PR description. Param names should be the same as in card config now.
Name=Karla Koblenz&Geburtsdatum=11.11.2000
(Don't remember the exact ref number name, Referenznummer or something?)

Copy link
Member

@steffenkleinle steffenkleinle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on firefox, works with the correct link with correctly set query params. I updated the PR description.
Works as expected that way :)

Comment on lines 40 to 45
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)
})
Copy link
Member

Choose a reason for hiding this comment

The 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 useCardGenerator hook and remove the old implementation from AddCardsFrom

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created a new ticket for that #1799
@steffenkleinle could you please check and adjust the description (if needed), because I'm not sure I could describe this task nicely, and wouldn't want to mislead with the description.

Copy link
Contributor

@f1sh1918 f1sh1918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done 👍

One small comment should be resolved before merging

Comment on lines 40 to 45
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)
})
Copy link
Contributor

Choose a reason for hiding this comment

The 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

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 })
Copy link
Contributor

@f1sh1918 f1sh1918 Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think its better to move this to the createKoblenzPass function to only remove them if the card was created successfully, so the params will not be removed if there is a page refresh (maybe by accident)

@seluianova seluianova force-pushed the 1430-create-card-query-params branch from 78babd9 to d884657 Compare November 25, 2024 10:02
@seluianova seluianova mentioned this pull request Nov 25, 2024
3 tasks
@seluianova seluianova force-pushed the 1430-create-card-query-params branch from d884657 to 0dbdae9 Compare November 25, 2024 10:07
@seluianova seluianova merged commit 35e550b into main Nov 25, 2024
1 check passed
@seluianova seluianova deleted the 1430-create-card-query-params branch November 25, 2024 10:13
seluianova added a commit that referenced this pull request Nov 27, 2024
* 1430: Add query params to card self service form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend card
3 participants