From da313a7cf2835dfcbbd22177e35b88258c5e2f3a Mon Sep 17 00:00:00 2001 From: Ole Date: Thu, 31 Oct 2024 11:32:32 +0100 Subject: [PATCH] fix: Missing artwork ID in SWA My Collection flow (#11045) * fix: Missing artwork ID in SWA My Collection flow * test --- .../SubmitArtworkFromMyCollectionArtworks.tsx | 15 +++++++++++++-- .../SubmitArtworkFromMyCollection.tests.tsx | 9 ++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/SubmitArtworkFromMyCollectionArtworks.tsx b/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/SubmitArtworkFromMyCollectionArtworks.tsx index 3ce54e8e899..9cf937244cd 100644 --- a/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/SubmitArtworkFromMyCollectionArtworks.tsx +++ b/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/SubmitArtworkFromMyCollectionArtworks.tsx @@ -11,6 +11,7 @@ import { SubmitArtworkStackNavigation } from "app/Scenes/SellWithArtsy/ArtworkFo import { fetchArtworkInformation } from "app/Scenes/SellWithArtsy/ArtworkForm/Utils/fetchArtworkInformation" import { getInitialSubmissionFormValuesFromArtwork } from "app/Scenes/SellWithArtsy/ArtworkForm/Utils/getInitialSubmissionValuesFromArtwork" import { SubmissionModel } from "app/Scenes/SellWithArtsy/ArtworkForm/Utils/validation" +import { createOrUpdateSubmission } from "app/Scenes/SellWithArtsy/SubmitArtwork/ArtworkDetails/utils/createOrUpdateSubmission" import { dismissModal, switchTab } from "app/system/navigation/navigate" import { extractNodes } from "app/utils/extractNodes" import { useRefreshControl } from "app/utils/refreshHelpers" @@ -48,9 +49,11 @@ export const SubmitArtworkFromMyCollectionArtworks: React.FC<{}> = () => { try { setIsLoading(true) // Fetch Artwork Details + const artwork = await fetchArtworkInformation(artworkID) + if (artwork) { - const formValues = { + const artworkValues = { ...getInitialSubmissionFormValuesFromArtwork(artwork), submissionId: values.submissionId, externalId: values.externalId, @@ -58,7 +61,15 @@ export const SubmitArtworkFromMyCollectionArtworks: React.FC<{}> = () => { userEmail: values.userEmail, userPhone: values.userPhone, } - setValues(formValues) + + const submission = await createOrUpdateSubmission(artworkValues, values.submissionId) + + setValues({ + ...artworkValues, + submissionId: submission?.internalID || values.submissionId, + externalId: submission?.externalID || values.externalId, + }) + setIsLoading(false) navigation.navigate("AddTitle") diff --git a/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/__tests__/SubmitArtworkFromMyCollection.tests.tsx b/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/__tests__/SubmitArtworkFromMyCollection.tests.tsx index 05001b7c3b1..02434e5ce38 100644 --- a/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/__tests__/SubmitArtworkFromMyCollection.tests.tsx +++ b/src/app/Scenes/SellWithArtsy/ArtworkForm/Components/__tests__/SubmitArtworkFromMyCollection.tests.tsx @@ -12,10 +12,17 @@ jest.mock("app/Scenes/SellWithArtsy/ArtworkForm/Utils/useSubmissionContext", () } }, })) - jest.mock("app/Scenes/SellWithArtsy/ArtworkForm/Utils/fetchArtworkInformation", () => ({ fetchArtworkInformation: jest.fn().mockResolvedValue({ artwork: mockedFetchedArtwork }), })) +jest.mock( + "app/Scenes/SellWithArtsy/SubmitArtwork/ArtworkDetails/utils/createOrUpdateSubmission", + () => ({ + createOrUpdateSubmission: jest + .fn() + .mockResolvedValue({ internalID: "internal-id", externalID: "external-id" }), + }) +) describe("SubmitArtworkFromMyCollection", () => { beforeEach(() => {