-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: overwrite public pricing after fetching offers
- Loading branch information
1 parent
dc94d6b
commit c172c74
Showing
4 changed files
with
332 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { FC } from "react" | ||
import { createFragmentContainer, graphql } from "react-relay" | ||
import { Flex, Text } from "@artsy/palette" | ||
import { SystemQueryRenderer } from "System/Relay/SystemQueryRenderer" | ||
import { SaleMessage } from "./Details" | ||
import { PartnerOfferedPriceQuery } from "__generated__/PartnerOfferedPriceQuery.graphql" | ||
import { PartnerOfferedPrice_artwork$data } from "__generated__/PartnerOfferedPrice_artwork.graphql" | ||
import { Details_artwork$data } from "__generated__/Details_artwork.graphql" | ||
|
||
interface PartnerOfferedPriceProps { | ||
artwork: PartnerOfferedPrice_artwork$data | ||
fallback: object | ||
} | ||
|
||
const PartnerOfferedPrice: React.FC<PartnerOfferedPriceProps> = ({ | ||
artwork, | ||
fallback, | ||
}) => { | ||
const partnerOffer = artwork?.collectorSignals?.partnerOffer | ||
const offeredPrice = partnerOffer?.priceWithDiscount?.display | ||
|
||
return partnerOffer ? <Text lineHeight="22px">{offeredPrice}</Text> : fallback | ||
} | ||
|
||
const PartnerOfferedPriceFragmentContainer = createFragmentContainer( | ||
PartnerOfferedPrice, | ||
{ | ||
artwork: graphql` | ||
fragment PartnerOfferedPrice_artwork on Artwork { | ||
collectorSignals { | ||
partnerOffer { | ||
endAt | ||
priceWithDiscount { | ||
display | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
} | ||
) | ||
|
||
interface PartnerOfferedPriceQueryRendererProps { | ||
id: string | ||
artwork: Details_artwork$data | ||
} | ||
|
||
export const PartnerOfferedPriceQueryRenderer: FC<PartnerOfferedPriceQueryRendererProps> = ({ | ||
id, | ||
artwork, | ||
}) => { | ||
return ( | ||
<SystemQueryRenderer<PartnerOfferedPriceQuery> | ||
lazyLoad | ||
query={graphql` | ||
query PartnerOfferedPriceQuery($id: String!) { | ||
artwork(id: $id) { | ||
...PartnerOfferedPrice_artwork | ||
} | ||
} | ||
`} | ||
placeholder={<SaleMessage artwork={artwork} />} | ||
variables={{ id }} | ||
render={({ error, props }) => { | ||
const publicPrice = <SaleMessage artwork={artwork} /> | ||
|
||
if (error || !props?.artwork) { | ||
return publicPrice | ||
} | ||
|
||
return ( | ||
<PartnerOfferedPriceFragmentContainer | ||
artwork={props.artwork} | ||
fallback={publicPrice} | ||
/> | ||
) | ||
}} | ||
/> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.