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

View File

@@ -6,11 +6,23 @@
margin-top: var(--Spacing-x3);
}
.dateSelect {
.dateOfBirth {
display: flex;
flex-direction: column;
gap: var(--Spacing-x1);
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 {

View File

@@ -14,33 +14,16 @@ export default async function SASxScandicLinkPage({
}: PageArgs<LangParams>) {
const profile = await getProfileSafely()
// TODO actually check if profile is already linked
// TODO check if already linked
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) {
redirect(`/${params.lang}/sas-x-scandic/error?errorCode=alreadyLinked`)
}
return (
<SASModal>
<LinkAccountForm
initialDateOfBirth={profile?.dateOfBirth ?? null}
onSubmit={handleLinkAccount}
/>
<LinkAccountForm userDateOfBirth={profile?.dateOfBirth ?? null} />
</SASModal>
)
}

View File

@@ -64,8 +64,9 @@
"Bed type": "Seng type",
"Bike friendly": "Cykelvenlig",
"Birth date": "Fødselsdato",
"Birth date is required": "Birth date is required",
"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 Reward Night": "Book bonusnat",
"Book a table online": "Book et bord online",
@@ -176,6 +177,7 @@
"Earn & spend points": "Få medlemsfordele og tilbud",
"Edit": "Redigere",
"Edit profile": "Rediger profil",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Elevatorpræference",
"Email": "E-mail",
"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 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 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're sorry": "Vi beklager",
"Wednesday": "Onsdag",

View File

@@ -65,8 +65,9 @@
"Bed type": "Bettentyp",
"Bike friendly": "Fahrradfreundlich",
"Birth date": "Geburtsdatum",
"Birth date is required": "Birth date is required",
"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 Reward Night": "Bonusnacht buchen",
"Book a table online": "Tisch online buchen",
@@ -177,6 +178,7 @@
"Earn & spend points": "Holen Sie sich Vorteile und Angebote für Mitglieder",
"Edit": "Bearbeiten",
"Edit profile": "Profil bearbeiten",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Aufzugpräferenz",
"Email": "Email",
"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 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 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're sorry": "Es tut uns leid",
"Wednesday": "Mittwoch",

View File

@@ -65,8 +65,9 @@
"Bed type": "Bed type",
"Bike friendly": "Bike friendly",
"Birth date": "Birth date",
"Birth date is required": "Birth date is required",
"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 Reward Night": "Book Reward Night",
"Book a table online": "Book a table online",
@@ -180,6 +181,7 @@
"Earn & spend points": "Earn & spend points",
"Edit": "Edit",
"Edit profile": "Edit profile",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Elevator preference",
"Email": "Email",
"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 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 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're sorry": "We're sorry",
"Wednesday": "Wednesday",

View File

@@ -63,8 +63,9 @@
"Bed type": "Vuodetyyppi",
"Bike friendly": "Pyöräystävällinen",
"Birth date": "Syntymäaika",
"Birth date is required": "Birth date is required",
"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 Reward Night": "Kirjapalkinto-ilta",
"Book a table online": "Varaa pöytä verkossa",
@@ -176,6 +177,7 @@
"Earn & spend points": "Hanki jäsenetuja ja -tarjouksia",
"Edit": "Muokata",
"Edit profile": "Muokkaa profiilia",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Hissitoive",
"Email": "Sähköposti",
"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 have a special gift waiting for you!": "Meillä on erityinen lahja odottamassa sinua!",
"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're sorry": "Olemme pahoillamme",
"Wednesday": "Keskiviikko",

View File

@@ -63,8 +63,9 @@
"Bed type": "Seng type",
"Bike friendly": "Sykkelvennlig",
"Birth date": "Fødselsdato",
"Birth date is required": "Birth date is required",
"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 Reward Night": "Bestill belønningskveld",
"Book a table online": "Bestill bord online",
@@ -175,6 +176,7 @@
"Earn & spend points": "Få medlemsfordeler og tilbud",
"Edit": "Redigere",
"Edit profile": "Rediger profil",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Heispreferanse",
"Email": "E-post",
"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 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 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're sorry": "Vi beklager",
"Wednesday": "Onsdag",

View File

@@ -63,8 +63,9 @@
"Bed type": "Sängtyp",
"Bike friendly": "Cykelvänligt",
"Birth date": "Födelsedatum",
"Birth date is required": "Birth date is required",
"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 Reward Night": "Boka frinatt",
"Book a table online": "Boka ett bord online",
@@ -175,6 +176,7 @@
"Earn & spend points": "Ta del av medlemsförmåner och erbjudanden",
"Edit": "Redigera",
"Edit profile": "Redigera profil",
"Edit your personal details": "Edit your personal details",
"Elevator preference": "Hisspreferens",
"Email": "E-post",
"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 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 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're sorry": "Vi beklagar",
"Wednesday": "Onsdag",