Skip to content

Commit

Permalink
fix: Missing artwork ID in My Collection Submit for Sale flow (#11046)
Browse files Browse the repository at this point in the history
  • Loading branch information
olerichter00 authored Oct 31, 2024
1 parent fe7e749 commit 330e239
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import { MyCollectionWhySell } from "./MyCollectionWhySell"
jest.mock("app/Scenes/SellWithArtsy/ArtworkForm/Utils/fetchArtworkInformation", () => ({
fetchArtworkInformation: () => Promise.resolve(artworkWithoutSubmission),
}))
jest.mock(
"app/Scenes/SellWithArtsy/SubmitArtwork/ArtworkDetails/utils/createOrUpdateSubmission",
() => ({
createOrUpdateSubmission: jest
.fn()
.mockResolvedValue({ internalID: "internal-id", externalID: "external-id" }),
})
)

describe("MyCollectionWhySell", () => {
let mockEnvironment: ReturnType<typeof createMockEnvironment>
Expand Down Expand Up @@ -115,7 +123,7 @@ describe("MyCollectionWhySell", () => {
signature: null,
source: "MY_COLLECTION",
state: "DRAFT",
submissionId: null,
submissionId: "internal-id",
title: "Welcome Mat",
userEmail: "",
userName: "",
Expand Down Expand Up @@ -270,7 +278,7 @@ describe("MyCollectionWhySell", () => {
signature: null,
source: "MY_COLLECTION",
state: "DRAFT",
submissionId: null,
submissionId: "internal-id",
title: "Welcome Mat",
userEmail: "",
userName: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { MyCollectionWhySell_artwork$key } from "__generated__/MyCollectionWhySe
import { SubmitArtworkProps } from "app/Scenes/SellWithArtsy/ArtworkForm/SubmitArtworkForm"
import { fetchArtworkInformation } from "app/Scenes/SellWithArtsy/ArtworkForm/Utils/fetchArtworkInformation"
import { getInitialSubmissionFormValuesFromArtwork } from "app/Scenes/SellWithArtsy/ArtworkForm/Utils/getInitialSubmissionValuesFromArtwork"
import { createOrUpdateSubmission } from "app/Scenes/SellWithArtsy/SubmitArtwork/ArtworkDetails/utils/createOrUpdateSubmission"
import { navigate } from "app/system/navigation/navigate"
import { Schema } from "app/utils/track"
import { Alert } from "react-native"
import { graphql, useFragment } from "react-relay"
import { useTracking } from "react-tracking"

Expand Down Expand Up @@ -51,28 +53,54 @@ export const MyCollectionWhySell: React.FC<MyCollectionWhySellProps> = (props) =
mb={2}
block
onPress={async () => {
trackEvent(
tracks.tappedSellArtwork(
setContextModule,
artwork.internalID,
artwork.slug,
setContextScreen,
"Submit This Artwork to Sell"
try {
trackEvent(
tracks.tappedSellArtwork(
setContextModule,
artwork.internalID,
artwork.slug,
setContextScreen,
"Submit This Artwork to Sell"
)
)
)
const passProps: SubmitArtworkProps = {
initialValues: {},
initialStep: "StartFlow",
hasStartedFlowFromMyCollection: true,
}
const passProps: SubmitArtworkProps = {
initialValues: {},
initialStep: "StartFlow",
hasStartedFlowFromMyCollection: true,
}

const artworkData = await fetchArtworkInformation(artwork.internalID)

if (!artworkData) {
console.error(
"Failed to fetch artwork details when submitting My Collection artwork for sale."
)
Alert.alert(
"Failed to fetch artwork details.",
"Please try again or enter details manually."
)
return
}

const initialValues = getInitialSubmissionFormValuesFromArtwork(artworkData)

const artworkData = await fetchArtworkInformation(artwork.internalID)
const submission = await createOrUpdateSubmission(initialValues, null)

if (artworkData) {
passProps.initialValues = getInitialSubmissionFormValuesFromArtwork(artworkData)
initialValues.submissionId = submission?.internalID || null
passProps.initialValues = initialValues
passProps.initialStep = "AddTitle"

navigate("/sell/submissions/new", { passProps })
} catch (error) {
console.error(
"Failed to fetch artwork details or create submission when submitting My Collection artwork for sale.",
error
)
Alert.alert(
"Failed to fetch artwork details or create submission.",
"Please try again or enter details manually."
)
}
navigate("/sell/submissions/new", { passProps })
}}
testID="submitArtworkToSellButton"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ export const SubmitArtworkFromMyCollectionArtworks: React.FC<{}> = () => {
setCurrentStep("AddTitle")
}
} catch (error) {
console.error(
"Failed to fetch artwork details or create submission when starting sell flow from My Collection.",
error
)
Alert.alert(
"Failed to fetch artwork details, ",
"Failed to fetch artwork details or create submission.",
"Please try again or enter details manually."
)
} finally {
Expand Down

0 comments on commit 330e239

Please sign in to comment.