diff --git a/site/src/components/PasswordField/PasswordField.stories.tsx b/site/src/components/PasswordField/PasswordField.stories.tsx index 2ef7908e11..3f217e80fc 100644 --- a/site/src/components/PasswordField/PasswordField.stories.tsx +++ b/site/src/components/PasswordField/PasswordField.stories.tsx @@ -19,11 +19,15 @@ const meta: Meta = { }, render: function StatefulPasswordField(args) { const [value, setValue] = useState(""); + return ( setValue(e.currentTarget.value)} + field={{ + ...args.field, + value, + onChange: (e) => setValue(e.currentTarget.value), + }} /> ); }, diff --git a/site/src/components/PasswordField/PasswordField.tsx b/site/src/components/PasswordField/PasswordField.tsx index 9f80e9c8dc..c38d6b9972 100644 --- a/site/src/components/PasswordField/PasswordField.tsx +++ b/site/src/components/PasswordField/PasswordField.tsx @@ -7,15 +7,11 @@ import { useDebouncedValue } from "#/hooks/debounce"; import { cn } from "#/utils/cn"; import type { FormHelpers } from "#/utils/formUtils"; -// TODO: @BrunoQuaresma: Unable to integrate Yup + Formik for validation. The -// validation was triggering on the onChange event, but the form.errors were not -// updating accordingly. Tried various combinations of validateOnBlur and -// validateOnChange without success. Further investigation is needed. - type PasswordFieldProps = InputProps & { label: string; field: FormHelpers; }; + /** * A password field component that validates the password against the API with * debounced calls. It uses a debounced value to minimize the number of API @@ -24,10 +20,10 @@ type PasswordFieldProps = InputProps & { export const PasswordField: FC = ({ label, field, - value, ...props }) => { - const debouncedValue = useDebouncedValue(`${value}`, 500); + const value = field.value === undefined ? "" : String(field.value); + const debouncedValue = useDebouncedValue(value, 500); const validatePasswordQuery = useQuery({ queryKey: ["validatePassword", debouncedValue], queryFn: () => API.validateUserPassword(debouncedValue), diff --git a/site/src/pages/SetupPage/SetupPageView.tsx b/site/src/pages/SetupPage/SetupPageView.tsx index 161b3e5397..4ef0abd1d2 100644 --- a/site/src/pages/SetupPage/SetupPageView.tsx +++ b/site/src/pages/SetupPage/SetupPageView.tsx @@ -232,7 +232,6 @@ export const SetupPageView: FC = ({