Merged in feat/remove-date-input-from-sas-link-flow (pull request #1328)

Remove date input from SAS link flow

Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-02-13 13:30:46 +00:00
parent d6f32bef7c
commit 419d21b3d0
9 changed files with 82 additions and 71 deletions

View File

@@ -1,60 +1,54 @@
"use client" "use client"
import Image from "next/image" import Image from "next/image"
import { useRouter } from "next/navigation" import { useParams, useRouter } from "next/navigation"
import { type ReactNode, useTransition } from "react" import { type ReactNode, useTransition } from "react"
import { FormProvider, useForm } from "react-hook-form" import { FormProvider, useForm } from "react-hook-form"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { profileEdit } from "@/constants/routes/myPages"
import { ArrowRightIcon } from "@/components/Icons"
import Button from "@/components/TempDesignSystem/Button" import Button from "@/components/TempDesignSystem/Button"
import Checkbox from "@/components/TempDesignSystem/Form/Checkbox" import Checkbox from "@/components/TempDesignSystem/Form/Checkbox"
import DateSelect from "@/components/TempDesignSystem/Form/Date" import Label from "@/components/TempDesignSystem/Form/Label"
import Link from "@/components/TempDesignSystem/Link" import Link from "@/components/TempDesignSystem/Link"
import Body from "@/components/TempDesignSystem/Text/Body" import Body from "@/components/TempDesignSystem/Text/Body"
import Caption from "@/components/TempDesignSystem/Text/Caption"
import Title from "@/components/TempDesignSystem/Text/Title" import Title from "@/components/TempDesignSystem/Text/Title"
import styles from "./link-sas.module.css" import styles from "./link-sas.module.css"
import type { LangParams } from "@/types/params"
type LinkAccountForm = { type LinkAccountForm = {
dateOfBirth: string | null
termsAndConditions: boolean termsAndConditions: boolean
} }
export function LinkAccountForm({ export function LinkAccountForm({
initialDateOfBirth, userDateOfBirth,
onSubmit,
}: { }: {
initialDateOfBirth: string | null userDateOfBirth: string | null
onSubmit: (
dateOfBirth: string
) => Promise<{ success: boolean; redirectUrl?: string }>
}) { }) {
const router = useRouter() const router = useRouter()
const params = useParams<LangParams>()
let [isPending, startTransition] = useTransition() let [isPending, startTransition] = useTransition()
const intl = useIntl() const intl = useIntl()
const form = useForm<LinkAccountForm>({ const form = useForm<LinkAccountForm>({
defaultValues: { defaultValues: {
dateOfBirth: initialDateOfBirth,
termsAndConditions: false, termsAndConditions: false,
}, },
}) })
const handleSubmit = form.handleSubmit((data) => { const handleSubmit = form.handleSubmit((data) => {
startTransition(async () => { startTransition(async () => {
if (!data.dateOfBirth || !data.termsAndConditions) return if (!data.termsAndConditions) return
const result = await onSubmit(data.dateOfBirth) const url = `/${params.lang}/sas-x-scandic/login?intent=link`
if (!result.success || !result.redirectUrl) { router.push(url)
throw new Error("Unable to redirect")
}
router.push(result.redirectUrl)
}) })
}) })
const dateOfBirth = form.watch("dateOfBirth")
const termsAndConditions = form.watch("termsAndConditions") const termsAndConditions = form.watch("termsAndConditions")
const disableSubmit = !dateOfBirth || !termsAndConditions const disableSubmit = !userDateOfBirth || !termsAndConditions
return ( return (
<FormProvider {...form}> <FormProvider {...form}>
@@ -70,27 +64,36 @@ export function LinkAccountForm({
{intl.formatMessage({ id: "Link your accounts" })} {intl.formatMessage({ id: "Link your accounts" })}
</Title> </Title>
</div> </div>
<div className={styles.dateSelect}> <div className={styles.dateOfBirth}>
<Body> <Body textTransform="bold">
{intl.formatMessage({ {userDateOfBirth
id: "Birth date", ? intl.formatMessage(
})} {
id: "Birth date: {dateOfBirth, date, ::MMMM d yyyy}",
},
{
dateOfBirth: new Date(userDateOfBirth),
}
)
: intl.formatMessage({ id: "Birth date is missing" })}
</Body> </Body>
<DateSelect <Label size="small" className={styles.dateOfBirthDescription}>
name="dateOfBirth" {intl.formatMessage({
registerOptions={{ id: "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.",
required: { })}
value: true, </Label>
message: intl.formatMessage({ id: "Birth date is required" }), <Link
}, href={profileEdit[params.lang]}
}} className={styles.dateOfBirthLink}
/> color="peach80"
variant="underscored"
>
{intl.formatMessage({
id: "Edit your personal details",
})}
<ArrowRightIcon color="peach80" height={18} width={18} />
</Link>
</div> </div>
<Caption textAlign="left">
{intl.formatMessage({
id: "We require this additional information in order to match your Scandic account with your EuroBonus account.",
})}
</Caption>
<div className={styles.termsAndConditions}> <div className={styles.termsAndConditions}>
<Checkbox <Checkbox
name="termsAndConditions" name="termsAndConditions"
@@ -101,6 +104,7 @@ export function LinkAccountForm({
id: "You must accept the terms and conditions", id: "You must accept the terms and conditions",
}), }),
}, },
disabled: !userDateOfBirth,
}} }}
> >
<Body> <Body>

View File

@@ -6,11 +6,23 @@
margin-top: var(--Spacing-x3); margin-top: var(--Spacing-x3);
} }
.dateSelect { .dateOfBirth {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: var(--Spacing-x1); gap: var(--Spacing-x1);
width: 100%; width: 100%;
background-color: var(--Main-Brand-WarmWhite);
padding: var(--Spacing-x2) var(--Spacing-x3);
}
.dateOfBirthLink {
display: flex;
align-items: center;
gap: var(--Spacing-x-half);
}
.dateOfBirthDescription {
color: var(--UI-Text-High-contrast);
} }
.termsAndConditions { .termsAndConditions {

View File

@@ -14,33 +14,16 @@ export default async function SASxScandicLinkPage({
}: PageArgs<LangParams>) { }: PageArgs<LangParams>) {
const profile = await getProfileSafely() const profile = await getProfileSafely()
// TODO actually check if profile is already linked // TODO check if already linked
const alreadyLinked = false const alreadyLinked = false
async function handleLinkAccount(dateOfBirth: string) {
"use server"
if (dateOfBirth !== profile?.dateOfBirth) {
// TODO update users date of birth here
console.log("updating date of birth")
}
return {
redirectUrl: `/${params.lang}/sas-x-scandic/login?intent=link`,
success: true,
}
}
if (alreadyLinked) { if (alreadyLinked) {
redirect(`/${params.lang}/sas-x-scandic/error?errorCode=alreadyLinked`) redirect(`/${params.lang}/sas-x-scandic/error?errorCode=alreadyLinked`)
} }
return ( return (
<SASModal> <SASModal>
<LinkAccountForm <LinkAccountForm userDateOfBirth={profile?.dateOfBirth ?? null} />
initialDateOfBirth={profile?.dateOfBirth ?? null}
onSubmit={handleLinkAccount}
/>
</SASModal> </SASModal>
) )
} }

View File

@@ -64,8 +64,9 @@
"Bed type": "Seng type", "Bed type": "Seng type",
"Bike friendly": "Cykelvenlig", "Bike friendly": "Cykelvenlig",
"Birth date": "Fødselsdato", "Birth date": "Fødselsdato",
"Birth date is required": "Birth date is required",
"Boardroom": "Boardroom", "Boardroom": "Boardroom",
"Birth date is missing": "Birth date is missing",
"Birth date: {dateOfBirth, date, ::MMMM d yyyy}": "Birth date: {dateOfBirth, date, ::MMMM d yyyy}",
"Book": "Book", "Book": "Book",
"Book Reward Night": "Book bonusnat", "Book Reward Night": "Book bonusnat",
"Book a table online": "Book et bord online", "Book a table online": "Book et bord online",
@@ -176,6 +177,7 @@
"Earn & spend points": "Få medlemsfordele og tilbud", "Earn & spend points": "Få medlemsfordele og tilbud",
"Edit": "Redigere", "Edit": "Redigere",
"Edit profile": "Rediger profil", "Edit profile": "Rediger profil",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Elevatorpræference", "Elevator preference": "Elevatorpræference",
"Email": "E-mail", "Email": "E-mail",
"Email address": "E-mailadresse", "Email address": "E-mailadresse",
@@ -609,7 +611,7 @@
"We had an issue processing your booking. Please try again. No charges have been made.": "Vi havde et problem med at behandle din booking. Prøv venligst igen. Ingen gebyrer er blevet opkrævet.", "We had an issue processing your booking. Please try again. No charges have been made.": "Vi havde et problem med at behandle din booking. Prøv venligst igen. Ingen gebyrer er blevet opkrævet.",
"We have a special gift waiting for you!": "Vi har en speciel gave, der venter på dig!", "We have a special gift waiting for you!": "Vi har en speciel gave, der venter på dig!",
"We look forward to your visit!": "Vi ser frem til dit besøg!", "We look forward to your visit!": "Vi ser frem til dit besøg!",
"We require this additional information in order to match your Scandic account with your EuroBonus account.": "We require this additional information in order to match your Scandic account with your EuroBonus account.", "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.": "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.",
"We successfully connected your accounts!": "We successfully connected your accounts!", "We successfully connected your accounts!": "We successfully connected your accounts!",
"We're sorry": "Vi beklager", "We're sorry": "Vi beklager",
"Wednesday": "Onsdag", "Wednesday": "Onsdag",

View File

@@ -65,8 +65,9 @@
"Bed type": "Bettentyp", "Bed type": "Bettentyp",
"Bike friendly": "Fahrradfreundlich", "Bike friendly": "Fahrradfreundlich",
"Birth date": "Geburtsdatum", "Birth date": "Geburtsdatum",
"Birth date is required": "Birth date is required",
"Boardroom": "Boardroom", "Boardroom": "Boardroom",
"Birth date is missing": "Birth date is missing",
"Birth date: {dateOfBirth, date, ::MMMM d yyyy}": "Birth date: {dateOfBirth, date, ::MMMM d yyyy}",
"Book": "Buchen", "Book": "Buchen",
"Book Reward Night": "Bonusnacht buchen", "Book Reward Night": "Bonusnacht buchen",
"Book a table online": "Tisch online buchen", "Book a table online": "Tisch online buchen",
@@ -177,6 +178,7 @@
"Earn & spend points": "Holen Sie sich Vorteile und Angebote für Mitglieder", "Earn & spend points": "Holen Sie sich Vorteile und Angebote für Mitglieder",
"Edit": "Bearbeiten", "Edit": "Bearbeiten",
"Edit profile": "Profil bearbeiten", "Edit profile": "Profil bearbeiten",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Aufzugpräferenz", "Elevator preference": "Aufzugpräferenz",
"Email": "Email", "Email": "Email",
"Email address": "E-Mail-Adresse", "Email address": "E-Mail-Adresse",
@@ -609,7 +611,7 @@
"We had an issue processing your booking. Please try again. No charges have been made.": "Wir hatten ein Problem beim Verarbeiten Ihrer Buchung. Bitte versuchen Sie es erneut. Es wurden keine Gebühren erhoben.", "We had an issue processing your booking. Please try again. No charges have been made.": "Wir hatten ein Problem beim Verarbeiten Ihrer Buchung. Bitte versuchen Sie es erneut. Es wurden keine Gebühren erhoben.",
"We have a special gift waiting for you!": "Wir haben ein besonderes Geschenk für Sie!", "We have a special gift waiting for you!": "Wir haben ein besonderes Geschenk für Sie!",
"We look forward to your visit!": "Wir freuen uns auf Ihren Besuch!", "We look forward to your visit!": "Wir freuen uns auf Ihren Besuch!",
"We require this additional information in order to match your Scandic account with your EuroBonus account.": "We require this additional information in order to match your Scandic account with your EuroBonus account.", "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.": "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.",
"We successfully connected your accounts!": "We successfully connected your accounts!", "We successfully connected your accounts!": "We successfully connected your accounts!",
"We're sorry": "Es tut uns leid", "We're sorry": "Es tut uns leid",
"Wednesday": "Mittwoch", "Wednesday": "Mittwoch",

View File

@@ -65,8 +65,9 @@
"Bed type": "Bed type", "Bed type": "Bed type",
"Bike friendly": "Bike friendly", "Bike friendly": "Bike friendly",
"Birth date": "Birth date", "Birth date": "Birth date",
"Birth date is required": "Birth date is required",
"Boardroom": "Boardroom", "Boardroom": "Boardroom",
"Birth date is missing": "Birth date is missing",
"Birth date: {dateOfBirth, date, ::MMMM d yyyy}": "Birth date: {dateOfBirth, date, ::MMMM d yyyy}",
"Book": "Book", "Book": "Book",
"Book Reward Night": "Book Reward Night", "Book Reward Night": "Book Reward Night",
"Book a table online": "Book a table online", "Book a table online": "Book a table online",
@@ -180,6 +181,7 @@
"Earn & spend points": "Earn & spend points", "Earn & spend points": "Earn & spend points",
"Edit": "Edit", "Edit": "Edit",
"Edit profile": "Edit profile", "Edit profile": "Edit profile",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Elevator preference", "Elevator preference": "Elevator preference",
"Email": "Email", "Email": "Email",
"Email address": "Email address", "Email address": "Email address",
@@ -614,7 +616,7 @@
"We had an issue processing your booking. Please try again. No charges have been made.": "We had an issue processing your booking. Please try again. No charges have been made.", "We had an issue processing your booking. Please try again. No charges have been made.": "We had an issue processing your booking. Please try again. No charges have been made.",
"We have a special gift waiting for you!": "We have a special gift waiting for you!", "We have a special gift waiting for you!": "We have a special gift waiting for you!",
"We look forward to your visit!": "We look forward to your visit!", "We look forward to your visit!": "We look forward to your visit!",
"We require this additional information in order to match your Scandic account with your EuroBonus account.": "We require this additional information in order to match your Scandic account with your EuroBonus account.", "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.": "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.",
"We successfully connected your accounts!": "We successfully connected your accounts!", "We successfully connected your accounts!": "We successfully connected your accounts!",
"We're sorry": "We're sorry", "We're sorry": "We're sorry",
"Wednesday": "Wednesday", "Wednesday": "Wednesday",

View File

@@ -63,8 +63,9 @@
"Bed type": "Vuodetyyppi", "Bed type": "Vuodetyyppi",
"Bike friendly": "Pyöräystävällinen", "Bike friendly": "Pyöräystävällinen",
"Birth date": "Syntymäaika", "Birth date": "Syntymäaika",
"Birth date is required": "Birth date is required",
"Boardroom": "Boardroom", "Boardroom": "Boardroom",
"Birth date is missing": "Birth date is missing",
"Birth date: {dateOfBirth, date, ::MMMM d yyyy}": "Birth date: {dateOfBirth, date, ::MMMM d yyyy}",
"Book": "Varaa", "Book": "Varaa",
"Book Reward Night": "Kirjapalkinto-ilta", "Book Reward Night": "Kirjapalkinto-ilta",
"Book a table online": "Varaa pöytä verkossa", "Book a table online": "Varaa pöytä verkossa",
@@ -176,6 +177,7 @@
"Earn & spend points": "Hanki jäsenetuja ja -tarjouksia", "Earn & spend points": "Hanki jäsenetuja ja -tarjouksia",
"Edit": "Muokata", "Edit": "Muokata",
"Edit profile": "Muokkaa profiilia", "Edit profile": "Muokkaa profiilia",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Hissitoive", "Elevator preference": "Hissitoive",
"Email": "Sähköposti", "Email": "Sähköposti",
"Email address": "Sähköpostiosoite", "Email address": "Sähköpostiosoite",
@@ -609,7 +611,7 @@
"We had an issue processing your booking. Please try again. No charges have been made.": "Meillä oli ongelma varauksen käsittelyssä. Yritä uudelleen. Ei maksuja on tehty.", "We had an issue processing your booking. Please try again. No charges have been made.": "Meillä oli ongelma varauksen käsittelyssä. Yritä uudelleen. Ei maksuja on tehty.",
"We have a special gift waiting for you!": "Meillä on erityinen lahja odottamassa sinua!", "We have a special gift waiting for you!": "Meillä on erityinen lahja odottamassa sinua!",
"We look forward to your visit!": "Odotamme innolla vierailuasi!", "We look forward to your visit!": "Odotamme innolla vierailuasi!",
"We require this additional information in order to match your Scandic account with your EuroBonus account.": "We require this additional information in order to match your Scandic account with your EuroBonus account.", "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.": "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.",
"We successfully connected your accounts!": "We successfully connected your accounts!", "We successfully connected your accounts!": "We successfully connected your accounts!",
"We're sorry": "Olemme pahoillamme", "We're sorry": "Olemme pahoillamme",
"Wednesday": "Keskiviikko", "Wednesday": "Keskiviikko",

View File

@@ -63,8 +63,9 @@
"Bed type": "Seng type", "Bed type": "Seng type",
"Bike friendly": "Sykkelvennlig", "Bike friendly": "Sykkelvennlig",
"Birth date": "Fødselsdato", "Birth date": "Fødselsdato",
"Birth date is required": "Birth date is required",
"Boardroom": "Boardroom", "Boardroom": "Boardroom",
"Birth date is missing": "Birth date is missing",
"Birth date: {dateOfBirth, date, ::MMMM d yyyy}": "Birth date: {dateOfBirth, date, ::MMMM d yyyy}",
"Book": "Bestill", "Book": "Bestill",
"Book Reward Night": "Bestill belønningskveld", "Book Reward Night": "Bestill belønningskveld",
"Book a table online": "Bestill bord online", "Book a table online": "Bestill bord online",
@@ -175,6 +176,7 @@
"Earn & spend points": "Få medlemsfordeler og tilbud", "Earn & spend points": "Få medlemsfordeler og tilbud",
"Edit": "Redigere", "Edit": "Redigere",
"Edit profile": "Rediger profil", "Edit profile": "Rediger profil",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Heispreferanse", "Elevator preference": "Heispreferanse",
"Email": "E-post", "Email": "E-post",
"Email address": "E-postadresse", "Email address": "E-postadresse",
@@ -607,7 +609,7 @@
"We had an issue processing your booking. Please try again. No charges have been made.": "Vi hadde et problem med å behandle din bestilling. Vær så snill å prøv igjen. Ingen gebyrer er blevet belastet.", "We had an issue processing your booking. Please try again. No charges have been made.": "Vi hadde et problem med å behandle din bestilling. Vær så snill å prøv igjen. Ingen gebyrer er blevet belastet.",
"We have a special gift waiting for you!": "Vi har en spesiell gave som venter på deg!", "We have a special gift waiting for you!": "Vi har en spesiell gave som venter på deg!",
"We look forward to your visit!": "Vi ser frem til ditt besøk!", "We look forward to your visit!": "Vi ser frem til ditt besøk!",
"We require this additional information in order to match your Scandic account with your EuroBonus account.": "We require this additional information in order to match your Scandic account with your EuroBonus account.", "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.": "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.",
"We successfully connected your accounts!": "We successfully connected your accounts!", "We successfully connected your accounts!": "We successfully connected your accounts!",
"We're sorry": "Vi beklager", "We're sorry": "Vi beklager",
"Wednesday": "Onsdag", "Wednesday": "Onsdag",

View File

@@ -63,8 +63,9 @@
"Bed type": "Sängtyp", "Bed type": "Sängtyp",
"Bike friendly": "Cykelvänligt", "Bike friendly": "Cykelvänligt",
"Birth date": "Födelsedatum", "Birth date": "Födelsedatum",
"Birth date is required": "Birth date is required",
"Boardroom": "Boardroom", "Boardroom": "Boardroom",
"Birth date is missing": "Birth date is missing",
"Birth date: {dateOfBirth, date, ::MMMM d yyyy}": "Birth date: {dateOfBirth, date, ::MMMM d yyyy}",
"Book": "Boka", "Book": "Boka",
"Book Reward Night": "Boka frinatt", "Book Reward Night": "Boka frinatt",
"Book a table online": "Boka ett bord online", "Book a table online": "Boka ett bord online",
@@ -175,6 +176,7 @@
"Earn & spend points": "Ta del av medlemsförmåner och erbjudanden", "Earn & spend points": "Ta del av medlemsförmåner och erbjudanden",
"Edit": "Redigera", "Edit": "Redigera",
"Edit profile": "Redigera profil", "Edit profile": "Redigera profil",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Hisspreferens", "Elevator preference": "Hisspreferens",
"Email": "E-post", "Email": "E-post",
"Email address": "E-postadress", "Email address": "E-postadress",
@@ -607,7 +609,7 @@
"We had an issue processing your booking. Please try again. No charges have been made.": "Vi hade ett problem med att bearbeta din bokning. Vänligen försök igen. Inga avgifter har debiterats.", "We had an issue processing your booking. Please try again. No charges have been made.": "Vi hade ett problem med att bearbeta din bokning. Vänligen försök igen. Inga avgifter har debiterats.",
"We have a special gift waiting for you!": "Vi har en speciell present som väntar på dig!", "We have a special gift waiting for you!": "Vi har en speciell present som väntar på dig!",
"We look forward to your visit!": "Vi ser fram emot ditt besök!", "We look forward to your visit!": "Vi ser fram emot ditt besök!",
"We require this additional information in order to match your Scandic account with your EuroBonus account.": "We require this additional information in order to match your Scandic account with your EuroBonus account.", "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.": "We require your birth date in order to link your Scandic account with your SAS EuroBonus account. Please check that it is correct.",
"We successfully connected your accounts!": "We successfully connected your accounts!", "We successfully connected your accounts!": "We successfully connected your accounts!",
"We're sorry": "Vi beklagar", "We're sorry": "Vi beklagar",
"Wednesday": "Onsdag", "Wednesday": "Onsdag",