Skip to content

Commit

Permalink
fix(Prompts): use location#display and userInterestsConnection for pr…
Browse files Browse the repository at this point in the history
…ompt checks (#10681)

fix: use location#display and userInterestsConnection for prompt checks
  • Loading branch information
araujobarret committed Aug 29, 2024
1 parent 1bc5f47 commit 58c5fc8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const CollectorUpdateNotification: FC<CollectorUpdateNotificationProps> =
}

const hasEmptyCollection =
item.me.myCollectionInfo.artworksCount === 0 && item.me.myCollectionInfo.artistsCount === 0
item.me.myCollectionInfo.artworksCount === 0 && !item.me.userInterestsConnection?.totalCount
const itemInfo = hasEmptyCollection ? addArtistsToCollectiontInfo : collectorProfileInfo

return (
Expand Down Expand Up @@ -71,17 +71,12 @@ const ITEM_FRAGMENT = graphql`
me @required(action: NONE) {
...MyProfileEditModal_me
profession
location {
city
}
myCollectionInfo @required(action: NONE) {
artistsCount
artworksCount
}
}
collectorProfile @required(action: NONE) {
lastUpdatePromptAt
userInterestsConnection(first: 1, interestType: ARTIST) {
totalCount
}
}
}
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ describe("CollectorUpdateNotification", () => {
it("renders collector profile information", async () => {
renderWithRelay({
Me: () => ({
profession: null,
profession: "Blacksmith",
location: { display: "" },
}),
CollectorProfileType: () => ({
lastUpdatePromptAt: "2021-09-01T00:00:00Z",
Expand All @@ -57,10 +58,8 @@ describe("CollectorUpdateNotification", () => {
renderWithRelay({
Me: () => ({
profession: null,
myCollectionInfo: {
artistsCount: 0,
artworksCount: 0,
},
myCollectionInfo: { artworksCount: 0 },
userInterestsConnection: { totalCount: 0 },
}),
CollectorProfileType: () => ({
lastUpdatePromptAt: "2021-09-01T00:00:00Z",
Expand Down
11 changes: 6 additions & 5 deletions src/app/Scenes/Artwork/hooks/__tests__/useSendInquiry.tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("useSendInquiry", () => {
action_name: "inquirySend",
owner_type: "Artwork",
owner_id: '<mock-value-for-field-"internalID">',
owner_slug: '<mock-value-for-field-"city">',
owner_slug: '<mock-value-for-field-"slug">',
})
expect(mockTrackEvent).toHaveBeenNthCalledWith(2, {
action_type: "success",
Expand Down Expand Up @@ -94,7 +94,7 @@ describe("useSendInquiry", () => {
action_name: "inquirySend",
owner_type: "Artwork",
owner_id: '<mock-value-for-field-"internalID">',
owner_slug: '<mock-value-for-field-"city">',
owner_slug: '<mock-value-for-field-"slug">',
})
expect(mockTrackEvent).toHaveBeenNthCalledWith(2, {
action_type: "fail",
Expand All @@ -114,7 +114,7 @@ describe("useSendInquiry", () => {
const loader = await loaderHook({
Me: () => ({
lastUpdatePromptAt: null,
location: { city: null },
location: { display: null },
collectorProfile: { lastUpdatePromptAt: null },
myCollectionInfo: { artistsCount: 1, artworksCount: 1 },
}),
Expand Down Expand Up @@ -144,7 +144,8 @@ describe("useSendInquiry", () => {
const loader = await loaderHook({
Me: () => ({
collectorProfile: { lastUpdatePromptAt: null },
myCollectionInfo: { artistsCount: 0, artworksCount: 0 },
myCollectionInfo: { artworksCount: 0 },
userInterestsConnection: { totalCount: 0 },
}),
})

Expand Down Expand Up @@ -172,7 +173,7 @@ describe("useSendInquiry", () => {
const loader = await loaderHook({
Me: () => ({
lastUpdatePromptAt: null,
location: { city: null },
location: { display: null },
collectorProfile: { lastUpdatePromptAt: null },
myCollectionInfo: { artistsCount: 0, artworksCount: 0 },
}),
Expand Down
20 changes: 12 additions & 8 deletions src/app/Scenes/Artwork/hooks/useSendInquiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ export const useSendInquiry = ({

setIsLoading(true)

tracking.trackEvent(
tracks.attemptedToSendTheInquiry(artwork?.internalID, me.location?.city ?? undefined)
)
tracking.trackEvent(tracks.attemptedToSendTheInquiry(artwork?.internalID, artwork?.slug))

commit({
variables: {
Expand Down Expand Up @@ -91,8 +89,9 @@ export const useSendInquiry = ({
tracking.trackEvent(tracks.successfullySentTheInquiry(artwork.internalID, artwork.slug))

const lastUpdatePromptAt = collectorProfile.lastUpdatePromptAt
const city = me.location?.city
const locationDisplay = me.location?.display
const profession = me.profession
const artworksCount = me.myCollectionInfo.artworksCount

if (!profilePromptIsEnabled) {
setTimeout(() => {
Expand All @@ -101,15 +100,18 @@ export const useSendInquiry = ({
return
}

if (userShouldBePromptedToCompleteProfile({ city, profession, lastUpdatePromptAt })) {
if (
userShouldBePromptedToCompleteProfile({ locationDisplay, profession, lastUpdatePromptAt })
) {
dispatch({ type: "setProfilePromptVisible", payload: true })
return
}

if (
userShouldBePromptedToAddArtistsToCollection({
lastUpdatePromptAt,
...me.myCollectionInfo,
artworksCount,
artistsCount: me.userInterestsConnection?.totalCount,
})
) {
dispatch({ type: "setCollectionPromptVisible", payload: true })
Expand Down Expand Up @@ -142,16 +144,18 @@ const FRAGMENT_COLLECTOR_PROFILE = graphql`
const FRAGMENT_ME = graphql`
fragment useSendInquiry_me on Me {
location {
city
display
}
profession
collectorProfile @required(action: NONE) {
...useSendInquiry_collectorProfile
}
myCollectionInfo @required(action: NONE) {
artistsCount
artworksCount
}
userInterestsConnection(first: 1, interestType: ARTIST) {
totalCount
}
}
`

Expand Down
22 changes: 11 additions & 11 deletions src/app/utils/collectorPromptHelpers.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ const MOCK_DATE = new Date("2024-08-20T00:00:00Z")
global.Date.now = jest.fn(() => MOCK_DATE.getTime())

describe("userShouldBePromptedToCompleteProfile", () => {
it("should prompt the user when city and profession are missing and cooldown period has passed", () => {
it("should prompt the user when location and profession are missing and cooldown period has passed", () => {
const result = userShouldBePromptedToCompleteProfile({
city: undefined,
locationDisplay: "",
profession: undefined,
lastUpdatePromptAt: "2024-07-01T00:00:00Z",
})

expect(result).toBe(true)
})

it("should not prompt the user when city and profession are missing but cooldown period has not passed", () => {
it("should not prompt the user when location and profession are missing but cooldown period has not passed", () => {
const result = userShouldBePromptedToCompleteProfile({
city: undefined,
locationDisplay: undefined,
profession: undefined,
lastUpdatePromptAt: "2024-08-15T00:00:00Z",
})

expect(result).toBe(false)
})

it("should not prompt the user when city and profession are provided even if cooldown period has passed", () => {
it("should not prompt the user when location and profession are provided even if cooldown period has passed", () => {
const result = userShouldBePromptedToCompleteProfile({
city: "New York",
locationDisplay: "New York",
profession: "Artist",
lastUpdatePromptAt: "2024-07-01T00:00:00Z",
})
Expand All @@ -40,7 +40,7 @@ describe("userShouldBePromptedToCompleteProfile", () => {

it("should prompt the user when profession is missing and cooldown period has passed", () => {
const result = userShouldBePromptedToCompleteProfile({
city: "New York",
locationDisplay: "New York",
profession: undefined,
lastUpdatePromptAt: "2024-07-01T00:00:00Z",
})
Expand All @@ -50,7 +50,7 @@ describe("userShouldBePromptedToCompleteProfile", () => {

it("should return true when there is no lastUpdatePromptAt date and profile is incomplete", () => {
const result = userShouldBePromptedToCompleteProfile({
city: undefined,
locationDisplay: undefined,
profession: undefined,
lastUpdatePromptAt: undefined,
})
Expand Down Expand Up @@ -104,7 +104,7 @@ describe("userShouldBePromptedToAddArtistsToCollection", () => {
describe("userHasNotBeenPromptedWithinCooldownPeriod", () => {
it("should return true when lastUpdatePromptAt is undefined", () => {
const result = userShouldBePromptedToCompleteProfile({
city: undefined,
locationDisplay: undefined,
profession: undefined,
lastUpdatePromptAt: undefined,
})
Expand All @@ -114,7 +114,7 @@ describe("userHasNotBeenPromptedWithinCooldownPeriod", () => {

it("should return true when the cooldown period has passed", () => {
const result = userShouldBePromptedToCompleteProfile({
city: undefined,
locationDisplay: undefined,
profession: undefined,
lastUpdatePromptAt: "2024-07-01T00:00:00Z",
})
Expand All @@ -124,7 +124,7 @@ describe("userHasNotBeenPromptedWithinCooldownPeriod", () => {

it("should return false when the cooldown period has not passed", () => {
const result = userShouldBePromptedToCompleteProfile({
city: undefined,
locationDisplay: undefined,
profession: undefined,
lastUpdatePromptAt: "2024-08-15T00:00:00Z",
})
Expand Down
8 changes: 4 additions & 4 deletions src/app/utils/collectorPromptHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ type InquiryModalMe = NonNullable<useSendInquiry_me$data>
type InquiryModalCollectorProfile = NonNullable<useSendInquiry_collectorProfile$data>

interface userShouldBePromptedToCompleteProfileParams {
city?: NonNullable<InquiryModalMe["location"]>["city"]
locationDisplay?: NonNullable<InquiryModalMe["location"]>["display"]
lastUpdatePromptAt: InquiryModalCollectorProfile["lastUpdatePromptAt"]
profession?: InquiryModalMe["profession"]
}

export const userShouldBePromptedToCompleteProfile = ({
city,
locationDisplay,
lastUpdatePromptAt,
profession,
}: userShouldBePromptedToCompleteProfileParams) => {
const userHasAnIncompleteProfile = !profession || !city
const userHasAnIncompleteProfile = !profession || !locationDisplay

return (
userHasAnIncompleteProfile && userHasNotBeenPromptedWithinCooldownPeriod(lastUpdatePromptAt)
Expand All @@ -25,7 +25,7 @@ export const userShouldBePromptedToCompleteProfile = ({
interface userShouldBePromptedToAddArtistsToCollectionParams {
lastUpdatePromptAt: InquiryModalCollectorProfile["lastUpdatePromptAt"]
artworksCount: InquiryModalMe["myCollectionInfo"]["artworksCount"]
artistsCount: InquiryModalMe["myCollectionInfo"]["artistsCount"]
artistsCount: NonNullable<InquiryModalMe["userInterestsConnection"]>["totalCount"]
}

export const userShouldBePromptedToAddArtistsToCollection = ({
Expand Down
108 changes: 0 additions & 108 deletions src/app/utils/tests/collectorPromptHelpers.tests.ts

This file was deleted.

0 comments on commit 58c5fc8

Please sign in to comment.