Skip to content

Commit

Permalink
Merge pull request #798 from Arnei/typing-validate
Browse files Browse the repository at this point in the history
Add typing to validate.ts
  • Loading branch information
Arnei authored Jul 5, 2024
2 parents a6f2b0a + d674ad5 commit 8c2e491
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ export const NewEventSchema = [
Yup.object().shape({}),
Yup.object().shape({
uploadAssetsTrack: Yup.array().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) => value === "UPLOAD",
is: (value: string) => value === "UPLOAD",
then: () => Yup.array().test(
"at-least-one-uploaded",
"at least one uploaded",
(uploadAssetsTrack) => {
// @ts-expect-error TS(2532): Object is possibly 'undefined'.
return uploadAssetsTrack.some((asset) => !!asset.file);
return uploadAssetsTrack && uploadAssetsTrack.some((asset) => !!asset.file);
}
),
}),
scheduleStartDate: Yup.date().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.date().required("Required"),
}),
Expand All @@ -41,44 +38,37 @@ export const NewEventSchema = [
then: () => Yup.array().min(1).required("Required"),
}),
scheduleStartHour: Yup.string().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.string().required("Required"),
}),
scheduleStartMinute: Yup.string().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.string().required("Required"),
}),
scheduleDurationHours: Yup.string().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.string().required("Required"),
}),
scheduleDurationMinutes: Yup.string().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.string().required("Required"),
}),
scheduleEndHour: Yup.string().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.string().required("Required"),
}),
scheduleEndMinute: Yup.string().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.string().required("Required"),
}),
location: Yup.string().when("sourceMode", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) =>
is: (value: string) =>
value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE",
then: () => Yup.string().required("Required"),
}),
Expand Down Expand Up @@ -141,8 +131,7 @@ export const NewGroupSchema = [
];

// Validation Schema used in new user wizard
// @ts-expect-error TS(7006): Parameter 'usernames' implicitly has an 'any' type... Remove this comment to see the full error message
export const NewUserSchema = (usernames) =>
export const NewUserSchema = (usernames: string[]) =>
Yup.object().shape({
username: Yup.string()
.required("Required")
Expand All @@ -151,8 +140,7 @@ export const NewUserSchema = (usernames) =>
email: Yup.string().email().required("Required"),
password: Yup.string().required("Required"),
passwordConfirmation: Yup.string()
// @ts-expect-error TS(2769): No overload matches this call.
.oneOf([Yup.ref("password"), null], "Passwords must match")
.oneOf([Yup.ref("password"), undefined], "Passwords must match")
.required("Required"),
});

Expand All @@ -161,11 +149,9 @@ export const EditUserSchema = Yup.object().shape({
name: Yup.string().required("Required"),
email: Yup.string().email().required("Required"),
passwordConfirmation: Yup.string().when("password", {
// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
is: (value) => !!value,
is: (value: any) => !!value,
then: () => Yup.string()
// @ts-expect-error TS(2769): No overload matches this call.
.oneOf([Yup.ref("password"), null], "Passwords must match")
.oneOf([Yup.ref("password"), undefined], "Passwords must match")
.required("Required"),
}),
});
Expand Down

0 comments on commit 8c2e491

Please sign in to comment.