Skip to content

Commit

Permalink
Fix plugin validation errors on settings pages (#81)
Browse files Browse the repository at this point in the history
* Fix "At least one channel is required." error

* Fix "Bot Token required." error
  • Loading branch information
irshadahmad21 committed Jan 28, 2024
1 parent 9fcdc0c commit 2cb4c4c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-bobcats-pull.md
@@ -0,0 +1,5 @@
---
"wptelegram": patch
---

Fix "At least one channel is required." error
5 changes: 5 additions & 0 deletions .changeset/cuddly-weeks-play.md
@@ -0,0 +1,5 @@
---
"wptelegram-widget": patch
---

Fix "Bot Token required." error
8 changes: 4 additions & 4 deletions plugins/wptelegram-widget/js/settings/services/fields.ts
Expand Up @@ -55,10 +55,10 @@ export const validationSchema = yup.object({
excludeEmptyString: true,
})
// make bot token required when username is added
.when('username', (username, schema) => {
return username
? schema.required(() => getErrorMessage('bot_token', 'required'))
: schema;
.when('username', {
is: (username: string) => Boolean(username),
then: (schema) =>
schema.required(() => getErrorMessage('bot_token', 'required')),
}),
author_photo: yup
.mixed<'auto' | 'always_show' | 'always_hide'>()
Expand Down
38 changes: 19 additions & 19 deletions plugins/wptelegram/js/settings/services/fields.ts
Expand Up @@ -57,25 +57,25 @@ export const validationSchema = yup.object({
}),
}),
)
.when('active', (active, schema) => {
return !active
? schema
: schema
.required(
sprintf(
/* translators: %s: field label */
__('At least one %s is required.'),
__('channel'),
),
)
.min(
1,
sprintf(
/* translators: %s: field label */
__('At least one %s is required.'),
__('channel'),
),
);
.when('active', {
is: true,
then: (schema) =>
schema
.required(
sprintf(
/* translators: %s: field label */
__('At least one %s is required.'),
__('channel'),
),
)
.min(
1,
sprintf(
/* translators: %s: field label */
__('At least one %s is required.'),
__('channel'),
),
),
}),
send_when: yup
.array()
Expand Down

0 comments on commit 2cb4c4c

Please sign in to comment.