-
Notifications
You must be signed in to change notification settings - Fork 153
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
feat(EMI-2196): Consolidated global AddressFormFields component + usage in Auction/Invoice apps #14898
feat(EMI-2196): Consolidated global AddressFormFields component + usage in Auction/Invoice apps #14898
Changes from all commits
3fa984d
fdf0fca
402b75a
307fabe
4f3c9cc
74c79a5
d9ee50c
b4a2c84
5e26bfb
defdffe
13be370
8a9f7f9
f120235
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { Join, Spacer, Text } from "@artsy/palette" | ||
import { CreditCardInput } from "Components/CreditCardInput" | ||
import { useFormContext } from "Apps/Auction/Hooks/useFormContext" | ||
import { AddressForm } from "./AddressForm" | ||
import { AddressFormFields } from "Components/Address/AddressFormFields" | ||
import { useAuctionFormContext } from "Apps/Auction/Hooks/useAuctionFormContext" | ||
import { AuctionFormValues } from "Apps/Auction/Components/Form/Utils/initialValues" | ||
|
||
export const AddressFormWithCreditCard: React.FC<React.PropsWithChildren<unknown>> = () => { | ||
export const AddressFormWithCreditCard: React.FC<React.PropsWithChildren< | ||
unknown | ||
>> = () => { | ||
const { | ||
setFieldValue, | ||
setFieldTouched, | ||
setFieldError, | ||
errors, | ||
touched, | ||
} = useFormContext() | ||
} = useAuctionFormContext() | ||
|
||
return ( | ||
<Join separator={<Spacer y={2} />}> | ||
|
@@ -44,7 +47,7 @@ export const AddressFormWithCreditCard: React.FC<React.PropsWithChildren<unknown | |
required | ||
/> | ||
|
||
<AddressForm /> | ||
<AddressFormFields<AuctionFormValues> withPhoneNumber /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here as well is the auction registration route using our new form |
||
</Join> | ||
) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { AuctionFormValues } from "Apps/Auction/Components/Form/Utils/initialValues" | ||
import { useFormikContext } from "formik" | ||
|
||
export const useFormContext = () => { | ||
export const useAuctionFormContext = () => { | ||
const context = useFormikContext<AuctionFormValues>() | ||
return context | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import { AuctionRegistrationRoute_me$data } from "__generated__/AuctionRegistrat | |
import { AuctionRegistrationRoute_sale$data } from "__generated__/AuctionRegistrationRoute_sale.graphql" | ||
import { AuctionBidRoute_me$data } from "__generated__/AuctionBidRoute_me.graphql" | ||
import { AuctionBidRoute_sale$data } from "__generated__/AuctionBidRoute_sale.graphql" | ||
import { toStripeAddress } from "Components/Address/AddressForm" | ||
import { toStripeAddress } from "Components/Address/utils" | ||
import { useRefreshUserData } from "Apps/Auction/Queries/useRefreshUserData" | ||
import { | ||
errorMessageForCard, | ||
|
@@ -80,11 +80,16 @@ export const useCreateTokenAndSubmit = ({ | |
|
||
helpers.setSubmitting(true) | ||
|
||
if (!values.address) { | ||
helpers.setStatus("SUBMISSION_FAILED") | ||
return | ||
} | ||
Comment on lines
+83
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This caused a bunch of test failures [fixed here] even though I don't think it would be an issue in real life due to form validations. I only did it to satisfy some ts complaints about using the |
||
|
||
try { | ||
const { error, token } = await stripe.createToken( | ||
cardNumberElement, | ||
toStripeAddress(values.address!) | ||
)! | ||
toStripeAddress(values.address) | ||
) | ||
|
||
if (error) { | ||
helpers.setFieldError("creditCard", error.message) | ||
|
@@ -94,16 +99,16 @@ export const useCreateTokenAndSubmit = ({ | |
await submitAddCreditCardAndUpdateProfileMutation({ | ||
variables: { | ||
creditCardInput: { | ||
token: token?.id!, | ||
token: token.id, | ||
}, | ||
profileInput: { | ||
phone: values.phoneNumber, | ||
}, | ||
}, | ||
rejectIf: res => { | ||
if (res.createCreditCard?.creditCardOrError?.mutationError) { | ||
const mutationErrorDetail = res.createCreditCard?.creditCardOrError | ||
?.mutationError?.detail! | ||
const mutationErrorDetail = | ||
res.createCreditCard.creditCardOrError.mutationError.detail | ||
|
||
helpers.setFieldError( | ||
"creditCard", | ||
|
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.
this changed because the name was coming up in searches in multiple places and caused me to confuse myself. Maybe not worth it though.