Fix(STAY-128): Handle single ancillaries * fix: refactor ancillaries flow * fix: add logic to determine if an ancillary requires quantity * fix: breakout ancillary description to its own component * fix: cleanup * fix: cleanup Approved-by: Bianca Widstam Approved-by: Erik Tiekstra
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
|
|
|
const quantitySchemaWithoutRefine = z.object({
|
|
quantityWithPoints: z.number().nullable(),
|
|
quantityWithCard: z.number().nullable(),
|
|
})
|
|
|
|
export const ancillaryError = {
|
|
TERMS_NOT_ACCEPTED: "TERMS_NOT_ACCEPTED",
|
|
MIN_QUANTITY_NOT_REACHED: "MIN_QUANTITY_NOT_REACHED",
|
|
} as const
|
|
|
|
export const ancillaryFormSchema = z
|
|
.object({
|
|
deliveryTime: z.string(),
|
|
optionalText: z.string(),
|
|
termsAndConditions: z
|
|
.boolean()
|
|
.refine((value) => value === true, ancillaryError.TERMS_NOT_ACCEPTED),
|
|
paymentMethod: nullableStringValidator,
|
|
})
|
|
.merge(quantitySchemaWithoutRefine)
|
|
.refine(
|
|
(data) =>
|
|
(data.quantityWithPoints ?? 0) > 0 || (data.quantityWithCard ?? 0) > 0,
|
|
{
|
|
message: ancillaryError.MIN_QUANTITY_NOT_REACHED,
|
|
path: ["quantityWithCard"],
|
|
}
|
|
)
|
|
|
|
export type AncillaryQuantityFormData = z.output<
|
|
typeof quantitySchemaWithoutRefine
|
|
>
|
|
export type AncillaryFormData = z.output<typeof ancillaryFormSchema>
|