Skip to content

Commit b1b55d0

Browse files
authored
Merge pull request #3621 from IntersectMBO/fix/3560-allow-empty-image-in-drep-form
fix(#3560): allow empty image in register drep form
2 parents a207f56 + 5e4920e commit b1b55d0

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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)
1718
- Fix app crash on unhandled wallet error [Issue 3123](https://github.com/IntersectMBO/govtool/issues/3123)
1819
- Preserve new lines in markdown text [Issue 2712](https://github.com/IntersectMBO/govtool/issues/2712)
1920
- Add scroll to markdown tables [Issue 3615](https://github.com/IntersectMBO/govtool/issues/3615)

govtool/frontend/src/components/organisms/UncontrolledImageInput.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import { useRef } from "react";
3-
import { useController } from "react-hook-form";
2+
import {
3+
Control,
4+
FieldPath,
5+
FieldValues,
6+
RegisterOptions,
7+
useController,
8+
} from "react-hook-form";
49
import { FormErrorMessage } from "../atoms";
510

6-
type UncontrolledImageInputProps = {
7-
name: string;
8-
control: any;
9-
rules?: any;
11+
type UncontrolledImageInputProps<
12+
TFieldValues extends FieldValues = FieldValues,
13+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
14+
> = {
15+
name: TName;
16+
control: Control<TFieldValues>;
17+
rules?: RegisterOptions<TFieldValues, TName>;
1018
placeholder?: string;
1119
dataTestId?: string;
1220
};
1321

14-
export const UncontrolledImageInput = ({
22+
export const UncontrolledImageInput = <T extends FieldValues>({
1523
name,
1624
control,
1725
rules,
1826
placeholder,
1927
dataTestId,
20-
}: UncontrolledImageInputProps) => {
28+
}: UncontrolledImageInputProps<T>) => {
2129
const {
2230
field: { onChange },
2331
fieldState,
@@ -49,8 +57,8 @@ export const UncontrolledImageInput = ({
4957
borderRadius: "50px",
5058
height: "50px",
5159
border: "1px solid",
52-
borderColor: fieldState.error?.message ? "red" : "#6F99FF",
53-
backgroundColor: fieldState.error?.message ? "#FAEAEB" : "white",
60+
borderColor: fieldState.error ? "red" : "#6F99FF",
61+
backgroundColor: fieldState.error ? "#FAEAEB" : "white",
5462
boxSizing: "border-box",
5563
margin: 0,
5664
display: "block",

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: unknown) => isValidImageUrl(value, { optional: true }),
8181
},
8282
};

govtool/frontend/src/i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@
389389
"tooLongUrl": "Url must be less than 128 bytes",
390390
"mustBeStakeAddress": "It must be reward address in bech32 format",
391391
"mustBeReceivingAddress": "Invalid payment address",
392-
"couldNotGenerateImageSha": "Could not generate image sha"
392+
"couldNotGenerateImageSha": "Could not generate image sha",
393+
"invalidValueType": "Invalid value type"
393394
}
394395
},
395396
"proposalDiscussion": {

govtool/frontend/src/utils/isValidFormat.ts

Lines changed: 10 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,13 @@ 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: unknown, options?: Options) {
86+
if (typeof url !== "string") {
87+
return i18n.t("forms.errors.invalidValueType");
88+
}
89+
if (options?.optional && !url) return true;
8290
if (!url.length) return false;
91+
8392
try {
8493
if (URL_REGEX.test(url)) {
8594
await getImageSha(url);

0 commit comments

Comments
 (0)