Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

172 character count resets to 0 low priority #175

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { 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 @@
formState: { errors, isValid },
control,
handleSubmit,
getValues,
} = useForm({
defaultValues: props.registrationData?.reduce(
(acc, curr) => {
Expand All @@ -100,6 +101,8 @@
mode: 'onBlur',
});

const values = getValues();

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

Expand Down Expand Up @@ -160,6 +163,7 @@
type={regField.type}
register={register}
control={control}
value={values[regField.id] ?? ''} // Current input value
/>
))}
</FlexColumn>
Expand All @@ -182,6 +186,7 @@
register,
characterLimit,
control,
value,
}: {
id: string;
name: string;
Expand All @@ -192,7 +197,8 @@
register: UseFormRegister<Record<string, string>>;
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 @@
disabled={disabled}
errors={errors}
characterLimit={characterLimit}
value={value}
/>
);
case 'SELECT':
Expand All @@ -230,6 +237,7 @@
disabled={disabled}
errors={errors}
characterLimit={characterLimit}
value={value}
/>
);
default:
Expand All @@ -245,9 +253,14 @@
disabled: boolean;
register: UseFormRegister<Record<string, string>>;
errors: FieldErrors<Record<string, string>>;
value: string;
}) {
const [charCount, setCharCount] = useState(0);

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

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

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

const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const inputValue = event.target.value;
setCharCount(inputValue.length);
Expand Down Expand Up @@ -363,7 +381,7 @@
options: RegistrationFieldOption[];
register: UseFormRegister<Record<string, string>>;
errors: FieldErrors<Record<string, string>>;
control: Control<Record<string, string>, any>;

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

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
}) {
return (
<FlexColumn $gap="0.5rem">
Expand Down
Loading