Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPDX-8444] Upgrade yup #1198

Merged
merged 8 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 28 additions & 31 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"tslib": "^2.4.0",
"tss-react": "^4.1.3",
"uuid": "^9.0.0",
"yup": "^0.32.11"
"yup": "^1.4.0"
},
"devDependencies": {
"@brainly/onesky-utils": "1.4.2",
Expand Down
5 changes: 4 additions & 1 deletion pages/api/Schema/ContactPrimaryAddress/datahandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const getAddressesResponseSchema = object({
relationships: object({
addresses: object({
data: array().of(
object({ id: string().required(), type: string().required() }),
object({
id: string().required(),
type: string().required(),
}).required(),
),
}).required(),
}).required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const EditMailingInfoModal: React.FC<EditMailingInfoModalProps> = ({
// Add additional language locales here, for multiline TextField support
const multilineLocales = ['de'];

const mailingInfoSchema: yup.SchemaOf<
const mailingInfoSchema: yup.ObjectSchema<
Pick<
ContactUpdateInput,
'id' | 'greeting' | 'envelopeGreeting' | 'sendNewsletter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const addressSchema = yup.object({
address.street,
),
),
primaryMailingAddress: yup.boolean().nullable(false),
primaryMailingAddress: yup.boolean().defined(),
});

export type AddressSchema = yup.InferType<typeof addressSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const EditContactOtherModal: React.FC<EditContactOtherModalProps> = ({
dataFilteredByName?.contacts.nodes ||
[];

const contactOtherSchema: yup.SchemaOf<
const contactOtherSchema: yup.ObjectSchema<
Pick<
ContactUpdateInput,
| 'id'
Expand All @@ -192,7 +192,7 @@ export const EditContactOtherModal: React.FC<EditContactOtherModalProps> = ({
churchName: yup.string().nullable(),
preferredContactMethod: yup
.mixed<PreferredContactMethodEnum>()
.oneOf([...Object.values(PreferredContactMethodEnum), null])
.oneOf(Object.values(PreferredContactMethodEnum))
.nullable(),
locale: yup.string().nullable(),
timezone: yup.string().nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { NewSocial, Person } from './PersonModal';

interface GetPersonSchemaReturnedValues {
personSchema: yup.SchemaOf<
personSchema: yup.ObjectSchema<
Omit<PersonUpdateInput, 'familyRelationships' | 'id'>
>;
initialPerson: (PersonCreateInput | PersonUpdateInput) & NewSocial;
Expand All @@ -26,25 +26,27 @@ export const getPersonSchema = (
title: yup.string().nullable(),
suffix: yup.string().nullable(),
phoneNumbers: yup.array().of(
yup.object({
id: yup.string().nullable(),
number: yup.string().when('destroy', {
is: true,
then: yup.string().nullable(),
otherwise: yup
.string()
.required(t('This field is required'))
.nullable()
.test(
'is-phone-number',
t('This field is not a valid phone number'),
(val) => typeof val === 'string' && /\d/.test(val),
),
}),
destroy: yup.boolean().default(false),
primary: yup.boolean().default(false),
historic: yup.boolean().default(false),
}),
yup
.object({
id: yup.string().nullable(),
number: yup.string().when('destroy', {
is: true,
then: (schema) => schema.nullable(),
otherwise: (schema) =>
schema
.required(t('This field is required'))
.nullable()
.test(
'is-phone-number',
t('This field is not a valid phone number'),
(val) => typeof val === 'string' && /\d/.test(val),
),
}),
destroy: yup.boolean().default(false),
primary: yup.boolean().default(false),
historic: yup.boolean().default(false),
})
.required(),
),
emailAddresses: yup.array().of(
yup.object({
Expand All @@ -59,38 +61,48 @@ export const getPersonSchema = (
}),
),
facebookAccounts: yup.array().of(
yup.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
username: yup.string().required(),
}),
yup
.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
username: yup.string().required(),
})
.required(),
),
linkedinAccounts: yup.array().of(
yup.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
publicUrl: yup.string().required(),
}),
yup
.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
publicUrl: yup.string().required(),
})
.required(),
),
twitterAccounts: yup.array().of(
yup.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
screenName: yup.string().required(),
}),
yup
.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
screenName: yup.string().required(),
})
.required(),
),
websites: yup.array().of(
yup.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
url: yup.string().required(),
}),
yup
.object({
id: yup.string().nullable(),
destroy: yup.boolean().default(false),
url: yup.string().required(),
})
.required(),
),
newSocials: yup.array().of(
yup.object({
value: yup.string().required(),
type: yup.string().required(),
}),
yup
.object({
value: yup.string().required(),
type: yup.string().required(),
})
.required(),
),
optoutEnewsletter: yup.boolean().default(false),
birthdayDay: yup.number().nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface ContactTagsProps {
}

const tagSchema = yup.object({
tagList: yup.array().of(yup.string()).default([]),
tagList: yup.array().of(yup.string().required()).default([]),
});

export const ContactTags: React.FC<ContactTagsProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ const SelectInteractive = styled(Select, {

const contactPartnershipSchema = yup.object({
id: yup.string().required(),
status: yup
.mixed<StatusEnum | null>()
.oneOf([...Object.values(StatusEnum), null])
.nullable(),
status: yup.mixed<StatusEnum>().oneOf(Object.values(StatusEnum)).nullable(),
pledgeAmount: yup.number().moreThan(-1).nullable(),
pledgeStartDate: nullableDateTime(),
pledgeReceived: yup.boolean().default(false).nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AddTagIcon = styled(Add)(() => ({
}));

const tagSchema = yup.object({
tagList: yup.array().of(yup.string()).default([]).nullable(),
tagList: yup.array().of(yup.string().required()).default([]).nullable(),
});

export const MassActionsAddTagsModal: React.FC<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const RemoveTagIcon = styled(Remove)(() => ({
}));

const tagSchema = yup.object({
tagList: yup.array().of(yup.string()).default([]).nullable(),
tagList: yup.array().of(yup.string().required()).default([]).nullable(),
});

export const MassActionsRemoveTagsModal: React.FC<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const LoadingIndicator = styled(CircularProgress)(({ theme }) => ({

const taskSchema = yup.object({
activityType: yup
.mixed()
.mixed<ActivityTypeEnum | 'BOTH'>()
.oneOf([...Object.values(ActivityTypeEnum), 'BOTH' as const])
.defined(),
completedAt: nullableDateTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const LoadingIndicator = styled(CircularProgress)(({ theme }) => ({
margin: theme.spacing(0, 1, 0, 0),
}));

const contactSchema: yup.SchemaOf<Pick<ContactCreateInput, 'name'>> =
const contactSchema: yup.ObjectSchema<Pick<ContactCreateInput, 'name'>> =
yup.object({
name: yup.string().required(),
});
Expand Down
Loading
Loading