Merged in fix/STAY-135 (pull request #3368)
Fix/STAY-135 & STAY-127 * fix: make quantity and delivery separate steps in mobile * fix: update design for delivery step in ancillary flow * fix: add error state for missing time * fix: only allow points or cash payment for ancillaries * fix: break out stepper to design system * fix: update design of select quantity step in add ancillaries flow * fix: add error states for quantity * fix: handle insufficient points case * fix: update stepper to include optional disabledMessage tooltip * fix: handle validations * fix: change name to camel case Approved-by: Bianca Widstam Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
@@ -2,36 +2,27 @@ 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 enum PaymentChoiceEnum {
|
||||
Points = "points",
|
||||
Card = "card",
|
||||
}
|
||||
|
||||
export const ancillaryFormSchema = z.object({
|
||||
deliveryTime: z.string(),
|
||||
optionalText: z.string(),
|
||||
termsAndConditions: z
|
||||
.boolean()
|
||||
.refine((value) => value === true, ancillaryError.TERMS_NOT_ACCEPTED),
|
||||
paymentMethod: nullableStringValidator,
|
||||
quantity: z.number().min(1, ancillaryError.MIN_QUANTITY_NOT_REACHED),
|
||||
paymentChoice: z.nativeEnum(PaymentChoiceEnum, {
|
||||
message: ancillaryError.MIN_QUANTITY_NOT_REACHED,
|
||||
}),
|
||||
})
|
||||
|
||||
export type AncillaryQuantityFormData = z.output<
|
||||
typeof quantitySchemaWithoutRefine
|
||||
>
|
||||
export type AncillaryFormData = z.output<typeof ancillaryFormSchema>
|
||||
|
||||
Reference in New Issue
Block a user