Skip to content

Typos & HTML5 email regex #9

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

Open
wants to merge 2 commits into
base: master
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
6 changes: 3 additions & 3 deletions src/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { createContext, useCallback, useMemo, useReducer } from 'react'
import { initialValues } from './initialValues'

const isText = /^[A-Z ]+$/i
const isEmail = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i
const isEmail = /^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/
const isPhone = /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4,6})$/ // us
const isZip = /^[0-9]{5}([- /]?[0-9]{4})?$/ // us
const isNumber = /^\d+$/
Expand Down Expand Up @@ -175,7 +175,7 @@ export function StepsProvider({ children }: ProviderProps) {
[]
)

const constextValue = useMemo(
const contextValue = useMemo(
() => ({
activeStep,
formValues,
Expand All @@ -189,7 +189,7 @@ export function StepsProvider({ children }: ProviderProps) {
)

return (
<AppContext.Provider value={constextValue}>
<AppContext.Provider value={contextValue}>
<div className='mui-step-form'>{children}</div>
</AppContext.Provider>
)
Expand Down
14 changes: 7 additions & 7 deletions src/components/SecondStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { AppContext } from '../Context'

export default function SecondStep() {
const { formValues, handleChange, handleBack, handleNext, variant, margin } = useContext(AppContext)
const { city, date, phone, agreenemt } = formValues
const { city, date, phone, agreement } = formValues

const isError = useCallback(
() =>
Object.keys({ city, date, phone, agreenemt }).some(
Object.keys({ city, date, phone, agreement }).some(
(name) => (formValues[name].required && !formValues[name].value) || formValues[name].error
),
[formValues, city, date, phone, agreenemt]
[formValues, city, date, phone, agreement]
)

return (
Expand Down Expand Up @@ -73,16 +73,16 @@ export default function SecondStep() {
<FormControlLabel
control={
<Checkbox
checked={agreenemt.value}
checked={agreement.value}
onChange={handleChange}
name='agreenemt'
name='agreement'
color='primary'
required={agreenemt.required}
required={agreement.required}
/>
}
label='Agree to terms and conditions'
/>
<FormHelperText error={!!agreenemt.error}>{agreenemt.error}</FormHelperText>
<FormHelperText error={!!agreement.error}>{agreement.error}</FormHelperText>
</Grid>
</Grid>

Expand Down
2 changes: 1 addition & 1 deletion src/initialValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const initialValues: ValidationSchema = {
minLength: 3,
maxLength: 20
},
agreenemt: {
agreement: {
value: false,
error: '',
required: true,
Expand Down