Skip to content

Commit 6707b93

Browse files
committed
refactor(web): add-utility-to-check-empty-strings-with-whitespaces
1 parent 4f2e88f commit 6707b93

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

web/src/components/CasesDisplay/Search.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useDebounce } from "react-use";
77

88
import { Searchbar, DropdownCascader } from "@kleros/ui-components-library";
99

10-
import { isUndefined } from "utils/index";
10+
import { isEmpty, isUndefined } from "utils/index";
1111
import { decodeURIFilter, encodeURIFilter, useRootPath } from "utils/uri";
1212

1313
import { rootCourtToItems, useCourtTree } from "queries/useCourtTree";
@@ -58,7 +58,7 @@ const Search: React.FC = () => {
5858
const navigate = useNavigate();
5959
useDebounce(
6060
() => {
61-
const newFilters = search === "" ? { ...filterObject } : { ...filterObject, id: search };
61+
const newFilters = isEmpty(search) ? { ...filterObject } : { ...filterObject, id: search };
6262
const encodedFilter = encodeURIFilter(newFilters);
6363
navigate(`${location}/${page}/${order}/${encodedFilter}`);
6464
},

web/src/context/NewDisputeContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Address } from "viem";
55
import { DEFAULT_CHAIN } from "consts/chains";
66
import { klerosCoreAddress } from "hooks/contracts/generated";
77
import { useLocalStorage } from "hooks/useLocalStorage";
8-
import { isUndefined } from "utils/index";
8+
import { isEmpty, isUndefined } from "utils/index";
99

1010
export type Answer = {
1111
id: string;
@@ -133,7 +133,7 @@ const constructDisputeTemplate = (disputeData: IDisputeData) => {
133133
for (const answer of baseTemplate.answers) {
134134
answer.id = "0x" + BigInt(answer.id).toString(16);
135135
}
136-
if (!isUndefined(baseTemplate.policyURI) && baseTemplate.policyURI === "") delete baseTemplate.policyURI;
136+
if (!isUndefined(baseTemplate.policyURI) && isEmpty(baseTemplate.policyURI)) delete baseTemplate.policyURI;
137137

138138
baseTemplate.arbitratorAddress = klerosCoreAddress[DEFAULT_CHAIN];
139139
baseTemplate.arbitratorChainID = DEFAULT_CHAIN.toString();

web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/FormContact.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Dispatch, SetStateAction, useMemo, useEffect } from "react";
22
import styled from "styled-components";
33

44
import { Field } from "@kleros/ui-components-library";
5+
import { isEmpty } from "src/utils";
56

67
const StyledLabel = styled.label`
78
display: flex;
@@ -47,7 +48,7 @@ const FormContact: React.FC<IForm> = ({
4748
};
4849

4950
const fieldVariant = useMemo(() => {
50-
if (contactInput === "" || !isEditing) {
51+
if (isEmpty(contactInput) || !isEditing) {
5152
return undefined;
5253
}
5354
return contactIsValid ? "success" : "error";

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { wrapWithToast, OPTIONS as toastOptions } from "utils/wrapWithToast";
1414

1515
import EnsureAuth from "components/EnsureAuth";
1616
import { EnsureChain } from "components/EnsureChain";
17-
import { isUndefined } from "src/utils";
17+
import { isEmpty, isUndefined } from "src/utils";
1818

1919
const StyledModal = styled(Modal)`
2020
position: absolute;
@@ -65,7 +65,7 @@ const SubmitEvidenceModal: React.FC<{
6565
const [file, setFile] = useState<File>();
6666
const { uploadFile } = useAtlasProvider();
6767

68-
const isDisabled = useMemo(() => isSending || message.trim() === "" || isUndefined(message), [isSending, message]);
68+
const isDisabled = useMemo(() => isSending || isEmpty(message) || isUndefined(message), [isSending, message]);
6969

7070
const submitEvidence = useCallback(async () => {
7171
try {

web/src/pages/Resolver/NavigationButtons/NextButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useLocation, useNavigate } from "react-router-dom";
55
import { Button } from "@kleros/ui-components-library";
66

77
import { useNewDisputeContext } from "context/NewDisputeContext";
8+
import { isEmpty } from "src/utils";
89

910
interface INextButton {
1011
nextRoute: string;
@@ -22,7 +23,7 @@ const NextButton: React.FC<INextButton> = ({ nextRoute }) => {
2223

2324
//check if any filled address or ens is invalid
2425
const areFilledAddressesValid = disputeData?.aliasesArray?.every((alias) =>
25-
alias.address === "" && alias.name === "" ? true : alias.isValid
26+
isEmpty(alias.address) && isEmpty(alias.name) ? true : alias.isValid
2627
);
2728

2829
const isButtonDisabled =

web/src/pages/Resolver/NavigationButtons/PreviousButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import styled from "styled-components";
44
import { useNavigate } from "react-router-dom";
55

66
import { Button } from "@kleros/ui-components-library";
7+
import { isEmpty } from "src/utils";
78

89
const StyledButton = styled(Button)<{ prevRoute: string }>`
9-
display: ${({ prevRoute }) => (prevRoute === "" ? "none" : "flex")};
10+
display: ${({ prevRoute }) => (isEmpty(prevRoute) ? "none" : "flex")};
1011
`;
1112

1213
interface IReturnButton {

web/src/utils/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
export const isUndefined = (maybeObject: any): maybeObject is undefined | null =>
22
typeof maybeObject === "undefined" || maybeObject === null;
3+
4+
/**
5+
* Checks if a string is empty or contains only whitespace.
6+
*/
7+
export const isEmpty = (str: string): boolean => str.trim() === "";

0 commit comments

Comments
 (0)