Skip to content
Snippets Groups Projects
Commit 2a66ae87 authored by Tore.Brede's avatar Tore.Brede
Browse files

GREG-113: Better handling of data from server. Handling date of birth

parent 420564e7
No related branches found
No related tags found
1 merge request!166GREG-113 guest date of birth
......@@ -10,6 +10,7 @@ import {
getCountries,
getCountryCallingCode,
} from 'libphonenumber-js'
import format from 'date-fns/format'
import OverviewGuestButton from '../../components/overviewGuestButton'
import GuestRegisterStep from './registerPage'
import { GuestRegisterCallableMethods } from './guestRegisterCallableMethods'
......@@ -62,6 +63,7 @@ export default function GuestRegister() {
passport: '',
passportNationality: '',
countryForCallingCode: '',
dateOfBirth: undefined,
authentication_method: AuthenticationMethod.Invite,
})
......@@ -91,7 +93,25 @@ export default function GuestRegister() {
}
}
let passportNumber = ''
let passportCountry = ''
if (jsonResponse.person.passport) {
const index = jsonResponse.person.passport.indexOf('-')
if (index !== -1) {
passportCountry = jsonResponse.person.passport.substring(0, index)
passportNumber = jsonResponse.person.passport.substring(
index + 1,
jsonResponse.person.passport.length
)
}
}
setGuestFormData({
fnr: jsonResponse.person.fnr,
passportNationality: passportCountry,
passport: passportNumber,
first_name: jsonResponse.person.first_name,
last_name: jsonResponse.person.last_name,
ou_name_en: jsonResponse.role.ou_name_en,
......@@ -106,12 +126,10 @@ export default function GuestRegister() {
feide_id: jsonResponse.person.feide_id,
mobile_phone_country_code: countryCode,
mobile_phone: nationalNumber,
fnr: jsonResponse.fnr,
passport: jsonResponse.passport,
// TODO Separate out nationality based on what is in the server response
passportNationality: '',
countryForCallingCode: extractedCountryCode,
dateOfBirth: jsonResponse.person.date_of_birth,
authentication_method: authenticationMethod,
})
})
......@@ -143,6 +161,7 @@ export default function GuestRegister() {
): void => {
// TODO Should go to consent page here, if there are consents defined in the database. Submit should happen after after consent page
// Only add fields to the objects that the user can change (this is also checked on the server side)
const payload: any = {}
payload.person = {}
payload.person.mobile_phone = `+${getCountryCallingCode(
......@@ -164,6 +183,13 @@ export default function GuestRegister() {
payload.person.fnr = updateFormData.nationalIdNumber
}
if (updateFormData.dateOfBirth) {
payload.person.date_of_birth = format(
updateFormData.dateOfBirth as Date,
'yyyy-MM-dd'
)
}
fetch('/api/ui/v1/invited/', submitJsonOpts('POST', payload))
.then((response) => {
if (response.ok) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment