Skip to content

Commit

Permalink
fix: my collection artwork upload broken (#9004)
Browse files Browse the repository at this point in the history
Co-authored-by: Sultan Al-Maari <sltun2oo9@gmail.com>
  • Loading branch information
MounirDhahri and MrSltun committed Jul 17, 2023
1 parent f53f032 commit 9a29d49
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { act, fireEvent } from "@testing-library/react-native"
import { AutosuggestResultsQuery } from "__generated__/AutosuggestResultsQuery.graphql"
import { myCollectionCreateArtworkMutation } from "__generated__/myCollectionCreateArtworkMutation.graphql"
import { updateArtwork } from "app/Scenes/MyCollection/Screens/ArtworkForm/methods/uploadArtwork"
import { saveOrUpdateArtwork } from "app/Scenes/MyCollection/Screens/ArtworkForm/methods/uploadArtwork"
import { ArtworkFormValues } from "app/Scenes/MyCollection/State/MyCollectionArtworkModel"
import * as artworkMutations from "app/Scenes/MyCollection/mutations/myCollectionCreateArtwork"
import { Tab } from "app/Scenes/MyProfile/MyProfileHeaderMyCollectionAndSavedWorks"
Expand Down Expand Up @@ -493,7 +493,7 @@ describe("MyCollectionArtworkForm", () => {

const storeLocalImageMock = jest.spyOn(LocalImageStore, "storeLocalImage")

await updateArtwork(formValues, formCheckValues, props)
await saveOrUpdateArtwork(formValues, formCheckValues, props)

expect(uploadPhotosMock).toBeCalledWith(fakePhotos)
expect(addArtworkMock).toBeCalled()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionType, ContextModule, OwnerType, SaveCollectedArtwork } from "@artsy/cohesion"
import { Flex, useScreenDimensions } from "@artsy/palette-mobile"
import { Flex } from "@artsy/palette-mobile"
import { NavigationContainer, NavigationContainerRef } from "@react-navigation/native"
import { createStackNavigator } from "@react-navigation/stack"
import { MyCollectionArtworkEditQuery } from "__generated__/MyCollectionArtworkEditQuery.graphql"
Expand All @@ -12,7 +12,7 @@ import {
MyCollectionCustomArtistSchema,
} from "app/Scenes/MyCollection/Screens/Artist/AddMyCollectionArtist"
import { MyCollectionArtworkStore } from "app/Scenes/MyCollection/Screens/ArtworkForm/MyCollectionArtworkStore"
import { updateArtwork } from "app/Scenes/MyCollection/Screens/ArtworkForm/methods/uploadArtwork"
import { saveOrUpdateArtwork } from "app/Scenes/MyCollection/Screens/ArtworkForm/methods/uploadArtwork"
import { ArtworkFormValues } from "app/Scenes/MyCollection/State/MyCollectionArtworkModel"
import { Tab } from "app/Scenes/MyProfile/MyProfileHeaderMyCollectionAndSavedWorks"
import { GlobalStore } from "app/store/GlobalStore"
Expand All @@ -21,6 +21,7 @@ import { useFeatureFlag } from "app/utils/hooks/useFeatureFlag"
import { refreshMyCollection, refreshMyCollectionInsights } from "app/utils/refreshHelpers"
import { FormikProvider, useFormik } from "formik"
import { useEffect, useRef, useState } from "react"
import { Alert, Dimensions } from "react-native"
import { useTracking } from "react-tracking"
import { SavingArtworkModal } from "./Components/SavingArtworkModal"
import { artworkSchema, validateArtworkSchema } from "./Form/artworkSchema"
Expand Down Expand Up @@ -100,7 +101,7 @@ export const MyCollectionArtworkForm: React.FC<MyCollectionArtworkFormProps> = (
await Promise.all([
// This is to satisfy showing the insights modal for 2500 ms
__TEST__ ? undefined : new Promise((resolve) => setTimeout(resolve, 2500)),
updateArtwork(values, dirtyFormCheckValues, props).then((hasMarketPriceInsights) => {
saveOrUpdateArtwork(values, dirtyFormCheckValues, props).then((hasMarketPriceInsights) => {
setSavingArtworkModalDisplayText(
hasMarketPriceInsights ? "Generating market data" : "Saving artwork"
)
Expand All @@ -123,16 +124,17 @@ export const MyCollectionArtworkForm: React.FC<MyCollectionArtworkFormProps> = (

refreshMyCollection()
refreshMyCollectionInsights({})
} catch (e) {
console.error("Artwork could not be saved", e)
setLoading(false)
} finally {

dismissModal()
if (mode === "add") {
popToRoot()
} else {
goBack()
}
} catch (e) {
console.error("Artwork could not be saved", e)
setLoading(false)
Alert.alert("Artwork could not be saved")
}
}

Expand All @@ -150,7 +152,7 @@ export const MyCollectionArtworkForm: React.FC<MyCollectionArtworkFormProps> = (
validationSchema: artworkSchema,
})

const { width, height } = useScreenDimensions()
const { width, height } = Dimensions.get("screen")

return (
<NavigationContainer independent ref={navContainerRef}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useArtworkForm } from "app/Scenes/MyCollection/Screens/ArtworkForm/Form
import { ArtworkFormScreen } from "app/Scenes/MyCollection/Screens/ArtworkForm/MyCollectionArtworkForm"
import { GlobalStore } from "app/store/GlobalStore"
import { getRelayEnvironment } from "app/system/relay/defaultEnvironment"
import { getAttributionClassValueByName } from "app/utils/artworkRarityClassifications"
import { omit, pickBy } from "lodash"
import React, { useEffect, useState } from "react"
import { ScrollView } from "react-native"
Expand Down Expand Up @@ -63,7 +64,8 @@ export const MyCollectionArtworkFormArtwork: React.FC<
metric: preferredMetric,
pricePaidCurrency: preferredCurrency,
...filteredFormValues,
attributionClass: artworkData.attributionClass?.name as any,
attributionClass:
getAttributionClassValueByName(artworkData.attributionClass?.name) || undefined,
photos,
})
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deletedPhotos } from "app/Scenes/MyCollection/utils/deletedPhotos"
import { storeLocalImage } from "app/utils/LocalImageStore"
import { reverse } from "lodash"

export const updateArtwork = async (
export const saveOrUpdateArtwork = async (
values: ArtworkFormValues,
dirtyFormCheckValues: ArtworkFormValues,
props: MyCollectionArtworkFormProps
Expand Down

0 comments on commit 9a29d49

Please sign in to comment.