diff --git a/administration/src/bp-modules/self-service/CardSelfServiceForm.tsx b/administration/src/bp-modules/self-service/CardSelfServiceForm.tsx index 400c8a0e8..874314a42 100644 --- a/administration/src/bp-modules/self-service/CardSelfServiceForm.tsx +++ b/administration/src/bp-modules/self-service/CardSelfServiceForm.tsx @@ -2,6 +2,7 @@ import { Checkbox, FormGroup, InputGroup, Intent } from '@blueprintjs/core' import InfoOutlined from '@mui/icons-material/InfoOutlined' import { styled } from '@mui/material' import React, { ReactElement, useContext, useState } from 'react' +import { useSearchParams } from 'react-router-dom' import { Card, getFullNameValidationErrorMessage, isFullNameValid, isValid } from '../../cards/Card' import ClearInputButton from '../../cards/extensions/components/ClearInputButton' @@ -48,6 +49,7 @@ const CardSelfServiceForm = ({ const [touchedFullName, setTouchedFullName] = useState(false) const [openDataPrivacy, setOpenDataPrivacy] = useState(false) const [openReferenceInformation, setOpenReferenceInformation] = useState(false) + const [_, setSearchParams] = useSearchParams() const cardValid = isValid(card, { expirationDateNullable: true }) const appToaster = useAppToaster() const showErrorMessage = touchedFullName || formSendAttempt @@ -68,6 +70,7 @@ const CardSelfServiceForm = ({ return } await generateCards() + setSearchParams(undefined, { replace: true }) } return ( diff --git a/administration/src/bp-modules/self-service/hooks/useCardGeneratorSelfService.tsx b/administration/src/bp-modules/self-service/hooks/useCardGeneratorSelfService.tsx index a7469dbed..9916ea13f 100644 --- a/administration/src/bp-modules/self-service/hooks/useCardGeneratorSelfService.tsx +++ b/administration/src/bp-modules/self-service/hooks/useCardGeneratorSelfService.tsx @@ -1,7 +1,8 @@ import { ApolloError } from '@apollo/client' import React, { useCallback, useContext, 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,9 +37,12 @@ type UseCardGeneratorSelfServiceReturn = { const useCardGeneratorSelfService = (): UseCardGeneratorSelfServiceReturn => { const projectConfig = useContext(ProjectConfigContext) const appToaster = useAppToaster() - const [selfServiceCard, setSelfServiceCard] = useState( - initializeCard(projectConfig.card, undefined, { expirationDate: null }) - ) + const [searchParams] = useSearchParams() + const [selfServiceCard, setSelfServiceCard] = useState(() => { + const headers = getHeaders(projectConfig) + const values = headers.map(header => searchParams.get(header)) + return initializeCardFromCSV(projectConfig.card, values, headers, undefined, true) + }) const [isLoading, setIsLoading] = useState(false) const [selfServiceState, setSelfServiceState] = useState(CardSelfServiceStep.form) const [deepLink, setDeepLink] = useState('') diff --git a/administration/src/cards/Card.ts b/administration/src/cards/Card.ts index 20dfbb017..5c57bbb34 100644 --- a/administration/src/cards/Card.ts +++ b/administration/src/cards/Card.ts @@ -162,12 +162,12 @@ export const initializeCardFromCSV = ( cardConfig: CardConfig, line: (string | null)[], headers: string[], - region: Region, + region: Region | undefined, withDefaults = false ): Card => { const defaultCard = withDefaults ? initializeCard(cardConfig, region) - : { fullName: '', expirationDate: null, extensions: { [REGION_EXTENSION_NAME]: region.id } } + : { fullName: '', expirationDate: null, extensions: region ? { [REGION_EXTENSION_NAME]: region.id } : {} } const extensions = headers.reduce((acc, header, index) => { const value = line[index] const extension = Extensions.find(extension => extension.name === getExtensionNameByCSVHeader(cardConfig, header)) diff --git a/administration/src/cards/extensions/BirthdayExtension.tsx b/administration/src/cards/extensions/BirthdayExtension.tsx index f29e84bd7..ccede1cf1 100644 --- a/administration/src/cards/extensions/BirthdayExtension.tsx +++ b/administration/src/cards/extensions/BirthdayExtension.tsx @@ -62,7 +62,7 @@ const BirthdayExtension: Extension = { }, }), isValid: ({ birthday }: BirthdayExtensionState) => { - if (birthday === null) { + if (!birthday) { return false } const today = PlainDate.fromLocalDate(new Date())