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

Fixing missing error messages & missing red borders on invalid inputs #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/modules/checkout/components/shipping-address/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const ShippingAddress = () => {
label="Email"
{...register("email", {
required: "Email is required",
pattern: emailRegex,
pattern: {
value: emailRegex,
message: "Email address is invalid"
},
})}
autoComplete="email"
errors={errors}
Expand Down
10 changes: 4 additions & 6 deletions src/modules/common/components/input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Eye from "@modules/common/icons/eye"
import EyeOff from "@modules/common/icons/eye-off"
import clsx from "clsx"
import React, { useEffect, useImperativeHandle, useState } from "react"
import { get } from "react-hook-form"
import { get } from "lodash"

type InputProps = Omit<
React.InputHTMLAttributes<HTMLInputElement>,
Expand Down Expand Up @@ -33,8 +33,6 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(

useImperativeHandle(ref, () => inputRef.current!)

const hasError = get(errors, name) && get(touched, name)

return (
<div>
<div className="relative z-0 w-full text-base-regular">
Expand All @@ -45,7 +43,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
className={clsx(
"pt-4 pb-1 block w-full px-4 mt-0 bg-transparent border appearance-none focus:outline-none focus:ring-0 focus:border-gray-400 border-gray-200",
{
"border-rose-500 focus:border-rose-500": hasError,
"border-rose-500 focus:border-rose-500": errors ? get(errors, name) : false,
}
)}
{...props}
Expand All @@ -57,7 +55,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
className={clsx(
"mx-3 px-1 transition-all absolute duration-300 top-3 -z-1 origin-0 text-gray-500",
{
"!text-rose-500": hasError,
"!text-rose-500": errors ? get(errors, name) : false,
}
)}
>
Expand All @@ -74,7 +72,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
</button>
)}
</div>
{hasError && (
{(
<ErrorMessage
errors={errors}
name={name}
Expand Down