Skip to content

Commit

Permalink
fix: form field isn't controlled
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Feb 16, 2024
1 parent 8922437 commit c50f138
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
13 changes: 3 additions & 10 deletions src/app/(account)/join/steps/StepTwo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,10 @@ export default function StepTwo() {
});

const { user } = useUser();
// Fetch user's profile information on component mount
useEffect(() => {
// Check if user profile data exists
if (user && user.primaryEmailAddress && user.fullName) {
// Split the full name into first and last names
const [firstName, lastName] = user.fullName.split(' ');
// Set the first and last names in the state
form.setValue('firstName', firstName);
form.setValue('lastName', lastName);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
if (!user) return;
form.setValue('firstName', String(user.firstName));
form.setValue('lastName', String(user.lastName));
}, [user]);

const { nextStep } = useJoinUsStep();
Expand Down
4 changes: 1 addition & 3 deletions src/components/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface FieldProps {
type?: 'text' | 'password' | 'select' | 'checkbox';
options?: readonly string[] | string[];
placeholder?: string;
defaultValue?: string;
}

const Field = ({
Expand All @@ -21,7 +20,6 @@ const Field = ({
type = 'text',
options = [],
placeholder,
defaultValue,
}: FieldProps) => {
const [showPassword, setShowPassword] = useState(false);

Expand Down Expand Up @@ -71,7 +69,7 @@ const Field = ({
id={label.toLowerCase()}
name={label.toLowerCase()}
type={showPassword ? 'text' : type}
defaultValue={defaultValue}
value={value}
className="mt-1 w-full rounded-none border border-gray-300 px-3 py-2 text-grey"
/>
{type === 'password' && (
Expand Down

0 comments on commit c50f138

Please sign in to comment.