Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | import * as Yup from "yup";
import { VALIDATION_MESSAGES } from "@validation/messages";
import {
AmountType,
DateType,
LocationType,
TEventModalInputs,
TPaymentTypes,
} from "./types";
import { US_ZIP_REGEX } from "@validation/regex";
const paymentTypes: TPaymentTypes[] = [
"one_time",
"monthly",
"quarterly",
"yearly",
];
export const validateURL = (url: string) => {
if (!url.match(/^https?:\/\//)) {
return (url = "https://" + url);
} else return url;
};
export const EventModalSchema = Yup.object().shape({
about: Yup.object().shape({
title: Yup.string().trim().required(VALIDATION_MESSAGES.REQUIRED),
description: Yup.string(),
}),
style: Yup.object().shape({
image: Yup.mixed().nullable(),
useAsBackground: Yup.boolean(),
}),
date_and_location: Yup.object().shape({
date: Yup.object().shape({
type: Yup.mixed<DateType>().oneOf(["one day", "period"]),
day: Yup.mixed().when("type", {
is: "one day",
then: Yup.date()
.typeError("please provide a valid date")
.nullable()
.required("A date is required")
.min(new Date(), "date must be in the future")
.max(new Date(2099, 11, 31), "date must be before the year 2099"),
}),
startDate: Yup.mixed().when("type", {
is: "period",
then: Yup.date()
.typeError("please provide a valid date")
.nullable()
.required("A starting date is required")
.min(new Date(), "date must be in the future"),
}),
endDate: Yup.mixed().when(["type", "startDate"], {
is: (type: string, startDate: any) => type === "period" && !!startDate,
then: Yup.date()
.typeError("please provide a valid date")
.nullable()
.required("An ending date is required")
.min(Yup.ref("startDate"), "end date must be after start date"),
}),
}),
location: Yup.object().shape({
type: Yup.mixed<LocationType>().oneOf(["in person", "online"]),
manual: Yup.boolean(),
location: Yup.string().when(["type", "manual"], {
is: (type: string, manual: boolean) => type === "in person" && !manual,
then: Yup.string().required("Location is required"),
}),
country: Yup.string().when(["type", "manual"], {
is: (type: string, manual: boolean) => type === "in person" && manual,
then: Yup.string().required("Required"),
}),
address: Yup.string().when(["type", "manual"], {
is: (type: string, manual: boolean) => type === "in person" && manual,
then: Yup.string().required("Required"),
}),
city: Yup.string().when(["type", "manual"], {
is: (type: string, manual: boolean) => type === "in person" && manual,
then: Yup.string().required("Required"),
}),
state: Yup.string().when(["type", "manual"], {
is: (type: string, manual: boolean) => type === "in person" && manual,
then: Yup.string().required("Required"),
}),
zip: Yup.string().when(["type", "manual"], {
is: (type: string, manual: boolean) => type === "in person" && manual,
then: Yup.string()
.matches(US_ZIP_REGEX, "Invalid ZIP format")
.required("Required"),
}),
event_url: Yup.string().when("type", {
is: (type: string) => type === "online",
then: Yup.string()
.matches(
/^(?!(?:https?:\/\/)?(?:www\.)?\w+$)(https?:\/\/)?([\w-]+\.)*[\w-]+\.[\w-]+(\/[\w-]+)*$/,
"Please enter a valid URL",
)
.required("Provide a link to your Virtual Event"),
}),
}),
}),
payment_set_up: Yup.object().shape({
payment_types: Yup.object().shape({
default: Yup.mixed<TPaymentTypes>().oneOf(paymentTypes).required(),
one_time: Yup.boolean(),
monthly: Yup.boolean(),
quarterly: Yup.boolean(),
yearly: Yup.boolean(),
}),
amountsList: Yup.array<AmountType>().min(1, "at least 1"),
}),
configuration: Yup.object().shape({
maxTickets: Yup.string().required("required"),
customer_pays_fees: Yup.boolean(),
browse_more: Yup.boolean(),
}),
});
export const EventModalDefaults = {
about: {
title: "",
description: "",
},
style: {
image: null,
useAsBackground: false,
},
date_and_location: {
date: {
type: "one day",
day: null,
include_time: false,
startDate: null,
endDate: null,
},
location: {
showMap: false,
type: "in person",
location: "",
manual: false,
country: "US",
address: "",
state: "",
city: "",
zip: "",
event_url: "",
},
},
payment_set_up: {
payment_types: {
default: "one_time" as TPaymentTypes,
one_time: true,
monthly: false,
quarterly: false,
yearly: false,
},
amountsList: [],
},
configuration: {
maxTickets: "5",
customer_pays_fees: false,
browse_more: false,
},
} as TEventModalInputs;
|