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

Add FormProviders to forms used so they can be more easily used (GCOM-1234) #2109

Draft
wants to merge 10 commits into
base: canary
Choose a base branch
from

Conversation

mikekeehnen
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Nov 6, 2023

⚠️ No Changeset found

Latest commit: 06e8bea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Nov 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
graphcommerce ❌ Failed (Inspect) Nov 27, 2023 3:46pm
graphcommerce-hygraph-dynamic-rows-ui ❌ Failed (Inspect) Nov 27, 2023 3:46pm

Comment on lines 128 to 136
<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>
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

@bramvanderholst bramvanderholst Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function ChangePasswordForm({ children }: PropsWithChildren) {
export type ChangePasswordFormProps = PropsWithChildren
export function ChangePasswordForm(props: ChangePasswordFormProps) {
const { children } = props

Copy link
Contributor Author

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to NewPasswordFields?

Copy link
Contributor Author

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) {
Copy link
Contributor

@bramvanderholst bramvanderholst Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function CreateCustomerAddressForm({ children }: PropsWithChildren) {
export type CreateCustomerAddressFormProps = PropsWithChildren
export function CreateCustomerAddressForm(props: ChangePasswordFormProps) {
const { children } = props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 63 to 62
<NameFields form={form} prefix />
<AddressFields form={form} />
{children ?? (
<>
<NameFields />
<AddressFields />
<TelephoneField />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-add prefix?

Copy link
Contributor Author

@mikekeehnen mikekeehnen Nov 27, 2023

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

Comment on lines 19 to 20
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, authenticationError] = graphqlErrorByCategory({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, authenticationError] = graphqlErrorByCategory({
const [, authenticationError] = graphqlErrorByCategory({

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 15 to 16
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, inputError] = graphqlErrorByCategory({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, inputError] = graphqlErrorByCategory({
const [, inputError] = graphqlErrorByCategory({

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 22 to 36
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>
)
}

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it back

Comment on lines 29 to 27
const { prefix, form, readOnly, prefixes = [mr, mrs, other] } = props
const form = useFormContext()

const prefixes = [mr, mrs, other]

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 24 to 19
export function NameFields(props: NameFieldProps) {
export function NameFields({ prefix = false }: NameFieldsProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructure on separate line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 65 to 48
{...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 />
Copy link
Contributor

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.

Copy link
Contributor Author

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed?

Copy link
Contributor Author

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']>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 26 to 19
export type EditBillingAddressFormProps = { sx?: SxProps<Theme> }
export type EditBillingAddressFormProps = PropsWithChildren<{ sx?: SxProps<Theme> }>
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants