-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add FormProviders to forms used so they can be more easily used (GCOM-1234) #2109
base: canary
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
<Form onSubmit={submit} noValidate sx={sx}> | ||
<NameFields form={form} key='name' readOnly={readOnly} /> | ||
<AddressFields form={form} key='addressfields' readOnly={readOnly} /> | ||
<FormRow key='telephone'> | ||
<TextFieldElement | ||
control={form.control} | ||
name='telephone' | ||
variant='outlined' | ||
type='text' | ||
required={required.telephone} | ||
validation={{ | ||
pattern: { value: phonePattern, message: i18n._(/* i18n */ 'Invalid phone number') }, | ||
}} | ||
label={<Trans id='Telephone' />} | ||
InputProps={{ | ||
readOnly, | ||
endAdornment: <InputCheckmark show={valid.telephone} />, | ||
}} | ||
/> | ||
</FormRow> | ||
<ApolloCartErrorAlert error={error} /> | ||
</Form> | ||
<FormProvider {...form}> | ||
{children ?? ( | ||
<> | ||
<NameFields /> | ||
<AddressFields /> | ||
<TelephoneField /> | ||
<ApolloCartErrorAlert /> | ||
<FormAutoSubmit name={['postcode', 'countryCode', 'regionId']} /> | ||
</> | ||
)} | ||
</FormProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please re-add form element (with sx) to prevent breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
import { | ||
ChangePasswordDocument, | ||
ChangePasswordMutation, | ||
ChangePasswordMutationVariables, | ||
} from './ChangePassword.gql' | ||
|
||
export function ChangePasswordForm() { | ||
export function ChangePasswordForm({ children }: PropsWithChildren) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function ChangePasswordForm({ children }: PropsWithChildren) { | |
export type ChangePasswordFormProps = PropsWithChildren | |
export function ChangePasswordForm(props: ChangePasswordFormProps) { | |
const { children } = props |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
import { Trans } from '@lingui/react' | ||
import { ValidatedPasswordElement } from '../ValidatedPasswordElement/ValidatedPasswordElement' | ||
|
||
export function ValidatePasswordFields() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to NewPasswordFields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason NewPasswordFields is a better name then ValidatePasswordFields?
import { CreateCustomerAddressDocument } from './CreateCustomerAddress.gql' | ||
|
||
export function CreateCustomerAddressForm() { | ||
export function CreateCustomerAddressForm({ children }: PropsWithChildren) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function CreateCustomerAddressForm({ children }: PropsWithChildren) { | |
export type CreateCustomerAddressFormProps = PropsWithChildren | |
export function CreateCustomerAddressForm(props: ChangePasswordFormProps) { | |
const { children } = props |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
<NameFields form={form} prefix /> | ||
<AddressFields form={form} /> | ||
{children ?? ( | ||
<> | ||
<NameFields /> | ||
<AddressFields /> | ||
<TelephoneField /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-add prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some new logic to NameFields. prefixes had now a false
options for prefixes, so the option can be enabled via one prop instead of a prefix and prefixes prop
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [_, authenticationError] = graphqlErrorByCategory({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
const [_, authenticationError] = graphqlErrorByCategory({ | |
const [, authenticationError] = graphqlErrorByCategory({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [_, inputError] = graphqlErrorByCategory({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
const [_, inputError] = graphqlErrorByCategory({ | |
const [, inputError] = graphqlErrorByCategory({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if (formState.isSubmitSuccessful && data) { | ||
return ( | ||
<Alert | ||
severity='success' | ||
variant='standard' | ||
sx={(theme) => ({ | ||
marginTop: theme.spacings.md, | ||
marginBottom: theme.spacings.sm, | ||
})} | ||
> | ||
<Trans id='We’ve send a password reset link to your email address!' /> | ||
</Alert> | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this message not be added back somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it back
const { prefix, form, readOnly, prefixes = [mr, mrs, other] } = props | ||
const form = useFormContext() | ||
|
||
const prefixes = [mr, mrs, other] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you no longer want to be able to pass prefixes in props?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
export function NameFields(props: NameFieldProps) { | ||
export function NameFields({ prefix = false }: NameFieldsProps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructure on separate line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
{...muiRegister('currentEmail', { | ||
required: true, | ||
pattern: { value: emailPattern, message: '' }, | ||
})} | ||
InputProps={{ | ||
readOnly: true, | ||
}} | ||
/> | ||
</FormRow> | ||
|
||
<FormRow> | ||
<TextField | ||
key='email' | ||
variant='outlined' | ||
type='text' | ||
autoComplete='off' | ||
error={formState.isSubmitted && !!formState.errors.email} | ||
helperText={formState.isSubmitted && formState.errors.email?.message} | ||
label={<Trans id='New email' />} | ||
required={required.email} | ||
{...muiRegister('email', { | ||
required: true, | ||
pattern: { value: emailPattern, message: '' }, | ||
})} | ||
/> | ||
<TextField | ||
key='confirm-email' | ||
variant='outlined' | ||
type='text' | ||
autoComplete='off' | ||
error={formState.isSubmitted && !!formState.errors.confirmEmail} | ||
helperText={formState.isSubmitted && formState.errors.confirmEmail?.message} | ||
label={<Trans id='Confirm new email' />} | ||
required | ||
{...muiRegister('confirmEmail', { | ||
required: true, | ||
validate: (value) => value === watchNewEmail || i18n._(/* i18n */ "Emails don't match"), | ||
})} | ||
/> | ||
</FormRow> | ||
<FormProvider {...form}> | ||
<Form onSubmit={submit} noValidate> | ||
{children ?? ( | ||
<> | ||
<FormRow> | ||
<TextFieldElement | ||
key='current-email' | ||
variant='outlined' | ||
type='text' | ||
autoComplete='email' | ||
autoFocus | ||
error={formState.isSubmitted && !!formState.errors.currentEmail} | ||
helperText={formState.isSubmitted && formState.errors.currentEmail?.message} | ||
label={<Trans id='Current email' />} | ||
required | ||
value={email} | ||
InputProps={{ | ||
readOnly: true, | ||
}} | ||
control={control} | ||
name='currentEmail' | ||
validation={{ | ||
pattern: { value: emailPattern, message: '' }, | ||
}} | ||
/> | ||
</FormRow> | ||
|
||
<FormRow> | ||
<PasswordElement | ||
control={control} | ||
variant='outlined' | ||
name='password' | ||
label={<Trans id='Password' />} | ||
autoComplete='current-password' | ||
required={required.password} | ||
disabled={formState.isSubmitting} | ||
error={Boolean(authenticationError)} | ||
helperText={authenticationError?.message} | ||
/> | ||
</FormRow> | ||
<PasswordField /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email
& confirmEmail
field are missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
control: Control<TFieldValues> | ||
// control: Control<TFieldValues> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
submit: ReturnType<UseFormReturn<TFieldValues>['handleSubmit']> | ||
// submit: ReturnType<UseFormReturn<TFieldValues>['handleSubmit']> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
export type EditBillingAddressFormProps = { sx?: SxProps<Theme> } | ||
export type EditBillingAddressFormProps = PropsWithChildren<{ sx?: SxProps<Theme> }> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use this anywhere. Use more conventional children?: React.ReactNode
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
3b91d76
to
06e8bea
Compare
No description provided.