feat(SW-3659): Use new input component * Use new input component * Update error formatter * Merged master into feat/use-new-input-component * Merged master into feat/use-new-input-component * Merge branch 'master' into feat/use-new-input-component * Merged master into feat/use-new-input-component * Update Input stories * Merge branch 'feat/use-new-input-component' of bitbucket.org:scandic-swap/web into feat/use-new-input-component * Update Storybook logo * Add some new demo icon input story * Fix the clear content button position * Fix broken password input icon * Merged master into feat/use-new-input-component * Merged master into feat/use-new-input-component * Add aria-hidden to required asterisk * Merge branch 'feat/use-new-input-component' of bitbucket.org:scandic-swap/web into feat/use-new-input-component * Merge branch 'master' into feat/use-new-input-component Approved-by: Bianca Widstam Approved-by: Matilda Landström
94 lines
2.7 KiB
TypeScript
94 lines
2.7 KiB
TypeScript
"use client"
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod"
|
|
import { useRouter } from "next/navigation"
|
|
import { FormProvider, useForm } from "react-hook-form"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { Button } from "@scandic-hotels/design-system/Button"
|
|
import { FormInput } from "@scandic-hotels/design-system/Form/FormInput"
|
|
|
|
import { formatFormErrorMessage } from "@/utils/getErrorMessage"
|
|
|
|
import {
|
|
type AdditionalInfoFormSchema,
|
|
additionalInfoFormSchema,
|
|
} from "./schema"
|
|
import { Title } from "./Title"
|
|
|
|
import styles from "./findMyBooking.module.css"
|
|
|
|
import type { AdditionalInfoCookieValue } from "@scandic-hotels/booking-flow/types/components/findMyBooking/additionalInfoCookieValue"
|
|
|
|
export default function AdditionalInfoForm({
|
|
confirmationNumber,
|
|
lastName,
|
|
}: {
|
|
confirmationNumber: string
|
|
lastName: string
|
|
}) {
|
|
const router = useRouter()
|
|
const intl = useIntl()
|
|
const form = useForm<AdditionalInfoFormSchema>({
|
|
resolver: zodResolver(additionalInfoFormSchema),
|
|
defaultValues: { firstName: "", email: "" },
|
|
mode: "all",
|
|
criteriaMode: "all",
|
|
reValidateMode: "onChange",
|
|
})
|
|
|
|
function onSubmit() {
|
|
const values = form.getValues()
|
|
const value: AdditionalInfoCookieValue = {
|
|
...values,
|
|
confirmationNumber,
|
|
lastName,
|
|
}
|
|
// eslint-disable-next-line react-hooks/immutability
|
|
document.cookie = `bv=${JSON.stringify(value)}; Path=/; Max-Age=600; Secure; SameSite=Strict`
|
|
router.refresh()
|
|
}
|
|
|
|
return (
|
|
<FormProvider {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className={styles.form}>
|
|
<Title isAdditional />
|
|
<div className={styles.inputs}>
|
|
<FormInput
|
|
label={intl.formatMessage({
|
|
id: "common.firstName",
|
|
defaultMessage: "First name",
|
|
})}
|
|
name="firstName"
|
|
registerOptions={{ required: true }}
|
|
errorFormatter={formatFormErrorMessage}
|
|
/>
|
|
<FormInput
|
|
label={intl.formatMessage({
|
|
id: "common.email",
|
|
defaultMessage: "Email",
|
|
})}
|
|
name="email"
|
|
type="email"
|
|
registerOptions={{ required: true }}
|
|
errorFormatter={formatFormErrorMessage}
|
|
/>
|
|
</div>
|
|
<div className={styles.buttons}>
|
|
<Button
|
|
type="submit"
|
|
variant="Primary"
|
|
size="Medium"
|
|
isDisabled={form.formState.isSubmitting}
|
|
>
|
|
{intl.formatMessage({
|
|
id: "common.confirm",
|
|
defaultMessage: "Confirm",
|
|
})}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</FormProvider>
|
|
)
|
|
}
|