Skip to content

Commit

Permalink
fix: input error object not accessed properly
Browse files Browse the repository at this point in the history
  • Loading branch information
winatungmiharja authored and ppdbultimate committed Jun 5, 2024
1 parent c3ca1aa commit 85220da
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/ui/src/components/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'react-datepicker/dist/react-datepicker.css';
import { Calendar } from 'lucide-react';
import { Typography } from '@/components/typography';
import cn from '@/lib/classnames';
import get from 'lodash.get';

export type DatePickerProps = {
validation?: RegisterOptions;
Expand Down Expand Up @@ -43,7 +44,7 @@ const DatePicker = ({
formState: { errors },
control,
} = useFormContext();
const error = errors[id] || null;
const error = get(errors, id);
const withLabel = label !== null;

// If there is a year default, then change the year to the props
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/dropzone-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Controller, useFormContext } from 'react-hook-form';
import type { FileWithPreview } from '@/types/dropzone';
import { Typography } from '@/components/typography';
import { FilePreview } from '@/components/file-preview';
import get from 'lodash.get';

export type DropzoneInputProps = {
accept?: Accept;
Expand Down Expand Up @@ -44,7 +45,7 @@ const DropzoneInput = ({
clearErrors,
formState: { errors },
} = useFormContext();
const error = errors[id] || null;
const error = get(errors, id);
const withLabel = label !== null;

//#region //*=========== Error Focus ===========
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { LucideIcon } from 'lucide-react';
import * as React from 'react';
import type { RegisterOptions } from 'react-hook-form';
import { useFormContext } from 'react-hook-form';
import get from 'lodash.get';
import { Typography } from '@/components/typography';

export type InputProps = {
Expand Down Expand Up @@ -52,7 +53,7 @@ const Input = ({
register,
formState: { errors },
} = useFormContext();
const error = errors[id] || null;
const error = get(errors, id);
const withLabel = label !== null;

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/password-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from 'react';
import type { RegisterOptions } from 'react-hook-form';
import { useFormContext } from 'react-hook-form';
import { Typography } from '@/components/typography';
import get from 'lodash.get';

export type PasswordInputProps = {
/** Input label */
Expand Down Expand Up @@ -48,7 +49,7 @@ const PasswordInput = ({
formState: { errors },
} = useFormContext();

const error = errors[id] || null;
const error = get(errors, id);
const withLabel = label !== null;

const [showPassword, setShowPassword] = useState(false);
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/components/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Controller, useFormContext } from 'react-hook-form';
import type { MultiValue, StylesConfig } from 'react-select';
import ReactSelect, { components } from 'react-select';
import { ChevronDown, X } from 'lucide-react';
import get from 'lodash.get';
import type { ExtractProps } from '@/types/helper';
import { Typography } from '@/components/typography';
import cn from '@/lib/classnames';
Expand Down Expand Up @@ -42,8 +43,7 @@ const Select = ({
control,
formState: { errors },
} = useFormContext();
const error = errors[id] || null;

const error = get(errors, id);
const withLabel = label !== null;

//#region //*=========== Styles ===========
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import clsx from 'clsx';
import type { RegisterOptions } from 'react-hook-form';
import { useFormContext } from 'react-hook-form';
import get from 'lodash.get';
import { Typography } from '@/components/typography';

export type TextareaProps = {
Expand Down Expand Up @@ -30,7 +31,7 @@ const Textarea = ({
register,
formState: { errors },
} = useFormContext();
const error = errors[id] || null;
const error = get(errors, id);
const withLabel = label !== null;

return (
Expand Down

0 comments on commit 85220da

Please sign in to comment.