Skip to content

Commit

Permalink
Fix character count set
Browse files Browse the repository at this point in the history
  • Loading branch information
camilovegag committed Feb 12, 2024
1 parent bd0561a commit 7fec89d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/berlin/src/pages/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { GetRegistrationResponseType } from '../types/RegistrationType';
import { GetRegistrationDataResponse } from '../types/RegistrationDataType';
import { DBEvent } from '../types/DBEventType';
import { Control, Controller, FieldErrors, UseFormRegister, useForm } from 'react-hook-form';
import { useMemo, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import toast from 'react-hot-toast';
import { RegistrationFieldOption } from '../types/RegistrationFieldOptionType';
import Input from '../components/input';
Expand Down Expand Up @@ -89,6 +89,7 @@ function RegisterForm(props: {
formState: { errors, isValid },
control,
handleSubmit,
getValues,
} = useForm({
defaultValues: props.registrationData?.reduce(
(acc, curr) => {
Expand All @@ -100,6 +101,8 @@ function RegisterForm(props: {
mode: 'onBlur',
});

const values = getValues();

const sortedRegistrationFields = useMemo(() => {
const sortedFields = [...(props.registrationFields || [])];

Expand Down Expand Up @@ -160,6 +163,7 @@ function RegisterForm(props: {
type={regField.type}
register={register}
control={control}
value={values[regField.id]} // Current input value
/>
))}
</FlexColumn>
Expand All @@ -182,6 +186,7 @@ function FormField({
register,
characterLimit,
control,
value,
}: {
id: string;
name: string;
Expand All @@ -193,6 +198,7 @@ function FormField({
errors: FieldErrors<Record<string, string>>;
characterLimit: number;
control: Control<Record<string, string>, any>;

Check warning on line 200 in packages/berlin/src/pages/Register.tsx

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
value: string;
}) {
switch (type) {
case 'TEXT':
Expand All @@ -205,6 +211,7 @@ function FormField({
disabled={disabled}
errors={errors}
characterLimit={characterLimit}
value={value}
/>
);
case 'SELECT':
Expand All @@ -230,6 +237,7 @@ function FormField({
disabled={disabled}
errors={errors}
characterLimit={characterLimit}
value={value}
/>
);
default:
Expand All @@ -245,9 +253,14 @@ function TextInput(props: {
disabled: boolean;
register: UseFormRegister<Record<string, string>>;
errors: FieldErrors<Record<string, string>>;
value: string;
}) {
const [charCount, setCharCount] = useState(0);

useEffect(() => {
setCharCount(props.value.length);
}, []);

Check warning on line 262 in packages/berlin/src/pages/Register.tsx

View workflow job for this annotation

GitHub Actions / Check linting

React Hook useEffect has a missing dependency: 'props.value.length'. Either include it or remove the dependency array. If 'setCharCount' needs the current value of 'props.value.length', you can also switch to useReducer instead of useState and read 'props.value.length' in the reducer

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const inputValue = event.target.value;
setCharCount(inputValue.length);
Expand Down Expand Up @@ -305,9 +318,14 @@ function TextAreaInput(props: {
disabled: boolean;
register: UseFormRegister<Record<string, string>>;
errors: FieldErrors<Record<string, string>>;
value: string;
}) {
const [charCount, setCharCount] = useState(0);

useEffect(() => {
setCharCount(props.value.length);
}, []);

Check warning on line 327 in packages/berlin/src/pages/Register.tsx

View workflow job for this annotation

GitHub Actions / Check linting

React Hook useEffect has a missing dependency: 'props.value.length'. Either include it or remove the dependency array. If 'setCharCount' needs the current value of 'props.value.length', you can also switch to useReducer instead of useState and read 'props.value.length' in the reducer

const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const inputValue = event.target.value;
setCharCount(inputValue.length);
Expand Down

0 comments on commit 7fec89d

Please sign in to comment.