Skip to content

Commit c603e84

Browse files
committed
fix(#3560): allow empty image in register drep form
1 parent 6c145b7 commit c603e84

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ changes.
1414

1515
### Fixed
1616

17+
- Fix an issue where the submit button remained disabled after removing an invalid value from the IMAGE input field on DRrep form [Issue 3560](https://github.com/IntersectMBO/govtool/issues/3560)
18+
1719
### Changed
1820

1921
### Removed

govtool/frontend/src/consts/dRepActions/fields.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ export const Rules = {
7777
value: IMAGE_REGEX,
7878
message: i18n.t("registration.fields.validations.image"),
7979
},
80-
validate: isValidImageUrl,
80+
validate: (value: string) => isValidImageUrl(value, { optional: true }),
8181
},
8282
};

govtool/frontend/src/utils/isValidFormat.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import i18n from "@/i18n";
77
import { adaHandleService } from "@/services/AdaHandle";
88
import { getImageSha } from "./getImageSha";
99

10+
type Options = {
11+
optional: boolean;
12+
};
13+
1014
export const URL_REGEX =
1115
/^(?:(?:https?:\/\/)?(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(?:\/[^\s]*)?)|(?:ipfs:\/\/(?:[a-zA-Z0-9]+(?:\/[a-zA-Z0-9._-]+)*))$|^$/;
1216
export const HASH_REGEX = /^[0-9A-Fa-f]+$/;
@@ -78,8 +82,10 @@ export async function isDRepView(view?: string) {
7882
return i18n.t("forms.errors.mustBeDRepView");
7983
}
8084

81-
export async function isValidImageUrl(url: string) {
85+
export async function isValidImageUrl(url: string, options?: Options) {
86+
if (options?.optional && !url) return true;
8287
if (!url.length) return false;
88+
8389
try {
8490
if (URL_REGEX.test(url)) {
8591
await getImageSha(url);

0 commit comments

Comments
 (0)