Skip to content

Commit 800f634

Browse files
committed
refactor: optimize input handling and component structure in form fields
1 parent 22c50e7 commit 800f634

File tree

8 files changed

+19
-40
lines changed

8 files changed

+19
-40
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Dispatch, SetStateAction, useMemo, useEffect } from "react";
1+
import React, { Dispatch, SetStateAction, useMemo } from "react";
22

33
import { TextField } from "@kleros/ui-components-library";
44
import { isEmpty } from "src/utils";
@@ -9,7 +9,6 @@ interface IForm {
99
contactInput: string;
1010
contactIsValid: boolean;
1111
setContactInput: Dispatch<SetStateAction<string>>;
12-
setContactIsValid: Dispatch<SetStateAction<boolean>>;
1312
validator: RegExp;
1413
isEditing?: boolean;
1514
}
@@ -20,14 +19,9 @@ const FormContact: React.FC<IForm> = ({
2019
contactInput,
2120
contactIsValid,
2221
setContactInput,
23-
setContactIsValid,
2422
validator,
2523
isEditing,
2624
}) => {
27-
useEffect(() => {
28-
setContactIsValid(validator.test(contactInput));
29-
}, [contactInput, setContactIsValid, validator]);
30-
3125
const fieldVariant = useMemo(() => {
3226
if (isEmpty(contactInput) || !isEditing) {
3327
return undefined;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import { errorToast, infoToast, successToast } from "utils/wrapWithToast";
2020

2121
const FormContactDetails: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
2222
const [emailInput, setEmailInput] = useState<string>("");
23-
const [emailIsValid, setEmailIsValid] = useState<boolean>(false);
2423
const { address } = useAccount();
2524
const { user, isAddingUser, isFetchingUser, addUser, updateEmail, isUpdatingUser, userExists } = useAtlasProvider();
2625

2726
const isEditingEmail = user?.email !== emailInput;
27+
const emailIsValid = EMAIL_REGEX.test(emailInput);
2828

2929
const isEmailUpdateable = user?.email
3030
? !isUndefined(user?.emailUpdateableAt) && new Date(user.emailUpdateableAt).getTime() < new Date().getTime()
@@ -96,7 +96,6 @@ const FormContactDetails: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
9696
contactInput={emailInput}
9797
contactIsValid={emailIsValid}
9898
setContactInput={setEmailInput}
99-
setContactIsValid={setEmailIsValid}
10099
validator={EMAIL_REGEX}
101100
isEditing={isEditingEmail}
102101
/>

web/src/pages/SubmitItem/ItemField/FieldInput/ImageInput.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const ImageInput: React.FC<IFieldInput> = ({ fieldProp, handleWrite }) => {
2323
.catch((err) => {
2424
console.log(err);
2525
errorToast(`Upload failed: ${err?.message}`);
26-
})
27-
.finally();
26+
});
2827
};
2928

3029
return (

web/src/pages/SubmitItem/ItemField/FieldInput/LongTextInput.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ import { cn } from "src/utils";
66
import { LANDSCAPE_WIDTH_CALC } from "./constants";
77

88
const LongTextInput: React.FC<IFieldInput> = ({ fieldProp, handleWrite }) => {
9-
const handleChange = (value: string) => {
10-
handleWrite(value);
11-
};
129
return (
1310
<TextArea
1411
aria-label={fieldProp.description}
1512
className={cn("[&_textarea]:w-full custom-scrollbar", LANDSCAPE_WIDTH_CALC)}
1613
style={{ marginBottom: responsiveSize(68, 40) }}
1714
resizeY
1815
value={fieldProp.value ?? ""}
19-
onChange={handleChange}
16+
onChange={handleWrite}
2017
variant="info"
2118
message={fieldProp.description}
2219
/>

web/src/pages/SubmitItem/ItemField/FieldInput/TextInput.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import { cn } from "src/utils";
66
import { LANDSCAPE_WIDTH_CALC } from "./constants";
77

88
const TextInput: React.FC<IFieldInput> = ({ fieldProp, handleWrite }) => {
9-
const handleChange = (value: string) => {
10-
handleWrite(value);
11-
};
129
return (
1310
<TextField
1411
aria-label={fieldProp.description}
1512
value={fieldProp.value ?? ""}
1613
className={cn("w-[80vw]", LANDSCAPE_WIDTH_CALC)}
1714
style={{ marginBottom: responsiveSize(68, 40) }}
18-
onChange={handleChange}
15+
onChange={handleWrite}
1916
variant="info"
2017
message={fieldProp.description}
2118
/>

web/src/pages/SubmitItem/Policy/ConfirmationBox.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ const ConfirmationBox: React.FC<IConfirmationBox> = ({}) => {
88
const { isPolicyRead, setIsPolicyRead } = useSubmitItemContext();
99

1010
return (
11-
<div className="mb-8">
12-
<Checkbox
13-
label="I certify that I read and understand the Policy"
14-
isSelected={isPolicyRead}
15-
small
16-
onChange={() => setIsPolicyRead(!isPolicyRead)}
17-
/>
18-
</div>
11+
<Checkbox
12+
className="mb-8"
13+
label="I certify that I read and understand the Policy"
14+
isSelected={isPolicyRead}
15+
small
16+
onChange={setIsPolicyRead}
17+
/>
1918
);
2019
};
2120

web/src/pages/SubmitItem/Policy/Info.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ const alertMessage =
1111

1212
const Info: React.FC = () => {
1313
return (
14-
<div className={cn("flex justify-center w-[84vw] mb-8", landscapeWitdhCalc)}>
15-
<AlertMessage variant="info" title="Important" msg={alertMessage} />
16-
</div>
14+
<AlertMessage
15+
className={cn("w-[84vw] mb-8", landscapeWitdhCalc)}
16+
variant="info"
17+
title="Important"
18+
msg={alertMessage}
19+
/>
1720
);
1821
};
1922

web/src/pages/SubmitList/DeployList/Progress.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ const Progress: React.FC = () => {
2929
{ title: "Submitted" },
3030
];
3131

32-
return (
33-
<div className="w-full p-8">
34-
<Steps
35-
className="w-full h-auto pt-4 pb-4"
36-
items={steps}
37-
currentItemIndex={progressValue}
38-
horizontal={isDesktop}
39-
/>
40-
</div>
41-
);
32+
return <Steps className="w-full h-auto p-8" items={steps} currentItemIndex={progressValue} horizontal={isDesktop} />;
4233
};
4334
export default Progress;

0 commit comments

Comments
 (0)