Skip to content

Commit

Permalink
fix(frontend): notification type validation (#2207)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCatLady committed Oct 16, 2021
1 parent 3486d0b commit 2f204b9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 60 deletions.
18 changes: 8 additions & 10 deletions src/components/Settings/Notifications/NotificationsDiscord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ const NotificationsDiscord: React.FC = () => {
otherwise: Yup.string().nullable(),
})
.url(intl.formatMessage(messages.validationUrl)),
types: Yup.number().when('enabled', {
is: true,
then: Yup.number()
.nullable()
.moreThan(0, intl.formatMessage(messages.validationTypes)),
otherwise: Yup.number().nullable(),
}),
});

if (!data && !error) {
Expand Down Expand Up @@ -238,8 +231,8 @@ const NotificationsDiscord: React.FC = () => {
}
}}
error={
errors.types && touched.types
? (errors.types as string)
values.enabled && !values.types && touched.types
? intl.formatMessage(messages.validationTypes)
: undefined
}
/>
Expand All @@ -266,7 +259,12 @@ const NotificationsDiscord: React.FC = () => {
<Button
buttonType="primary"
type="submit"
disabled={isSubmitting || !isValid || isTesting}
disabled={
isSubmitting ||
!isValid ||
isTesting ||
(values.enabled && !values.types)
}
>
<SaveIcon />
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ const NotificationsLunaSea: React.FC = () => {
otherwise: Yup.string().nullable(),
})
.url(intl.formatMessage(messages.validationWebhookUrl)),
types: Yup.number().when('enabled', {
is: true,
then: Yup.number()
.nullable()
.moreThan(0, intl.formatMessage(messages.validationTypes)),
otherwise: Yup.number().nullable(),
}),
});

if (!data && !error) {
Expand Down Expand Up @@ -217,8 +210,8 @@ const NotificationsLunaSea: React.FC = () => {
}
}}
error={
errors.types && touched.types
? (errors.types as string)
values.enabled && !values.types && touched.types
? intl.formatMessage(messages.validationTypes)
: undefined
}
/>
Expand All @@ -245,7 +238,12 @@ const NotificationsLunaSea: React.FC = () => {
<Button
buttonType="primary"
type="submit"
disabled={isSubmitting || !isValid || isTesting}
disabled={
isSubmitting ||
!isValid ||
isTesting ||
(values.enabled && !values.types)
}
>
<SaveIcon />
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ const NotificationsPushbullet: React.FC = () => {
.required(intl.formatMessage(messages.validationAccessTokenRequired)),
otherwise: Yup.string().nullable(),
}),
types: Yup.number().when('enabled', {
is: true,
then: Yup.number()
.nullable()
.moreThan(0, intl.formatMessage(messages.validationTypes)),
otherwise: Yup.number().nullable(),
}),
});

if (!data && !error) {
Expand Down Expand Up @@ -197,8 +190,8 @@ const NotificationsPushbullet: React.FC = () => {
}
}}
error={
errors.types && touched.types
? (errors.types as string)
values.enabled && !values.types && touched.types
? intl.formatMessage(messages.validationTypes)
: undefined
}
/>
Expand All @@ -225,7 +218,12 @@ const NotificationsPushbullet: React.FC = () => {
<Button
buttonType="primary"
type="submit"
disabled={isSubmitting || !isValid || isTesting}
disabled={
isSubmitting ||
!isValid ||
isTesting ||
(values.enabled && !values.types)
}
>
<SaveIcon />
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ const NotificationsPushover: React.FC = () => {
/^[a-z\d]{30}$/i,
intl.formatMessage(messages.validationUserTokenRequired)
),
types: Yup.number().when('enabled', {
is: true,
then: Yup.number()
.nullable()
.moreThan(0, intl.formatMessage(messages.validationTypes)),
otherwise: Yup.number().nullable(),
}),
});

if (!data && !error) {
Expand Down Expand Up @@ -243,8 +236,8 @@ const NotificationsPushover: React.FC = () => {
}
}}
error={
errors.types && touched.types
? (errors.types as string)
values.enabled && !values.types && touched.types
? intl.formatMessage(messages.validationTypes)
: undefined
}
/>
Expand All @@ -271,7 +264,12 @@ const NotificationsPushover: React.FC = () => {
<Button
buttonType="primary"
type="submit"
disabled={isSubmitting || !isValid || isTesting}
disabled={
isSubmitting ||
!isValid ||
isTesting ||
(values.enabled && !values.types)
}
>
<SaveIcon />
<span>
Expand Down
18 changes: 8 additions & 10 deletions src/components/Settings/Notifications/NotificationsSlack/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ const NotificationsSlack: React.FC = () => {
otherwise: Yup.string().nullable(),
})
.url(intl.formatMessage(messages.validationWebhookUrl)),
types: Yup.number().when('enabled', {
is: true,
then: Yup.number()
.nullable()
.moreThan(0, intl.formatMessage(messages.validationTypes)),
otherwise: Yup.number().nullable(),
}),
});

if (!data && !error) {
Expand Down Expand Up @@ -195,8 +188,8 @@ const NotificationsSlack: React.FC = () => {
}
}}
error={
errors.types && touched.types
? (errors.types as string)
values.enabled && !values.types && touched.types
? intl.formatMessage(messages.validationTypes)
: undefined
}
/>
Expand All @@ -223,7 +216,12 @@ const NotificationsSlack: React.FC = () => {
<Button
buttonType="primary"
type="submit"
disabled={isSubmitting || !isValid || isTesting}
disabled={
isSubmitting ||
!isValid ||
isTesting ||
(values.enabled && !values.types)
}
>
<SaveIcon />
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ const NotificationsWebhook: React.FC = () => {
}
}
),
types: Yup.number().when('enabled', {
is: true,
then: Yup.number()
.nullable()
.moreThan(0, intl.formatMessage(messages.validationTypes)),
otherwise: Yup.number().nullable(),
}),
});

if (!data && !error) {
Expand Down Expand Up @@ -312,8 +305,8 @@ const NotificationsWebhook: React.FC = () => {
}
}}
error={
errors.types && touched.types
? (errors.types as string)
values.enabled && !values.types && touched.types
? intl.formatMessage(messages.validationTypes)
: undefined
}
/>
Expand All @@ -340,7 +333,12 @@ const NotificationsWebhook: React.FC = () => {
<Button
buttonType="primary"
type="submit"
disabled={isSubmitting || !isValid || isTesting}
disabled={
isSubmitting ||
!isValid ||
isTesting ||
(values.enabled && !values.types)
}
>
<SaveIcon />
<span>
Expand Down

0 comments on commit 2f204b9

Please sign in to comment.