Skip to content

Commit

Permalink
Merge branch 'malj/2414' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
millianapia committed Aug 8, 2024
2 parents db05eae + 9a0b0e1 commit d11da50
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
40 changes: 26 additions & 14 deletions sanityv3/schemas/components/EventPromotion/EventPromotionInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text, Card, Grid, Stack, Heading, Radio, Inline, Flex, Switch } from '@sanity/ui'
import { Text, Card, Grid, Stack, Heading, Radio, Inline, Flex, Switch, TextInput } from '@sanity/ui'
import { set, MemberField } from 'sanity'
import { getObjectMemberField } from '../utils/getObjectMemberField'
import type { ObjectInputProps } from 'sanity'
Expand All @@ -12,7 +12,7 @@ const InlinePreview = ({ value }: { value: EventPromotion | undefined }) => {
if (!value) return null

const time = value?.promotePastEvents ? 'past' : 'upcoming'
const number = value?.promotePastEvents ? value?.pastEventsCount || '50 (max)' : ''
const number = value?.pastEventsCount
const withTags = value?.useTags ? 'from selected tags' : ''
const automaticPromotion = value?.promoteSingleUpcomingEvent
? 'Automatically promoting single upcoming event'
Expand All @@ -31,10 +31,11 @@ export const EventPromotionInput = (props: EventPromotionInputProps) => {
const useTags = getObjectMemberField(members, 'useTags')
const promotePastEvents = getObjectMemberField(members, 'promotePastEvents')
const pastEventsCount = getObjectMemberField(members, 'pastEventsCount')
const upcomingEventsCount = getObjectMemberField(members, 'upcomingEventsCount')
const selectedTags = getObjectMemberField(members, 'tags')
const promotedEvents = getObjectMemberField(members, 'promotedEvents')

if (!promotePastEvents || !pastEventsCount || !useTags || !selectedTags || !promotedEvents)
if (!promotePastEvents || !pastEventsCount || !upcomingEventsCount || !useTags || !selectedTags || !promotedEvents)
return renderDefault(props)

return (
Expand Down Expand Up @@ -110,18 +111,29 @@ export const EventPromotionInput = (props: EventPromotionInputProps) => {
/>
)}
</Grid>
<Card padding={2} radius={2} shadow={1}>
<Inline space={2}>
<Switch
id="selectSingleUpcomingPromotion"
checked={value?.promoteSingleUpcomingEvent}
onChange={() => onChange(set(!value?.promoteSingleUpcomingEvent, ['promoteSingleUpcomingEvent']))}
<Grid columns={2} gap={3}>
<Card padding={2} radius={2} shadow={1}>
<MemberField
member={upcomingEventsCount}
renderInput={renderInput}
renderField={renderField}
renderItem={renderItem}
renderPreview={renderPreview}
/>
<Text as="label" htmlFor="selectSingleUpcomingPromotion">
Promote single upcoming event
</Text>
</Inline>
</Card>
</Card>
<Card padding={2} radius={2} shadow={1}>
<Inline space={2}>
<Switch
id="selectSingleUpcomingPromotion"
checked={value?.promoteSingleUpcomingEvent}
onChange={() => onChange(set(!value?.promoteSingleUpcomingEvent, ['promoteSingleUpcomingEvent']))}
/>
<Text as="label" htmlFor="selectSingleUpcomingPromotion">
Promote single upcoming event
</Text>
</Inline>
</Card>
</Grid>

{value?.useTags && (
<MemberField
Expand Down
3 changes: 2 additions & 1 deletion sanityv3/schemas/objects/promotion/promoteEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { Reference, Rule, ValidationContext } from 'sanity'
import { filterByRouteEvents } from '../../../helpers/referenceFilters'
import { Flags } from '../../../src/lib/datasetHelpers'
import routes from '../../routes'
import { EventPromotionInput, EventPromotionPreview } from '../../components/EventPromotion'
import { EventPromotionPreview } from '../../components/EventPromotion'
import { EventPromotionInput } from '../../components/EventPromotion/EventPromotionInput'

export type EventPromotion = {
_key: string
Expand Down
5 changes: 3 additions & 2 deletions web/lib/queries/common/pageContentFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,20 @@ _type == "keyNumbers" =>{
manuallySelectEvents,
promotePastEvents,
pastEventsCount,
upcomingEventsCount,
promoteSingleUpcomingEvent
},
!manuallySelectEvents => {
tags,
// @TODO: This query is not done yet
(!promotePastEvents || !defined(promotePastEvents)) => {
!useTags => {
"promotions": ${futureEventsQuery(false)}[0...3]{
"promotions": ${futureEventsQuery(false)}[]{
${eventPromotionFields}
},
},
useTags => {
"promotions": ${futureEventsQuery(true)}[0...3]{
"promotions": ${futureEventsQuery(true)}[]{
${eventPromotionFields}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const MultipleEventCards = ({
)
})
}
if (eventPromotionSettings?.upcomingEventsCount) {
data = data.slice(0, eventPromotionSettings.upcomingEventsCount)
}

if (eventPromotionSettings?.promotePastEvents && eventPromotionSettings?.pastEventsCount) {
data = data.slice(0, eventPromotionSettings.pastEventsCount)
}
Expand Down
1 change: 1 addition & 0 deletions web/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export type EventPromotionSettings = {
promotePastEvents: boolean
promoteSingleUpcomingEvent: boolean
pastEventsCount?: number
upcomingEventsCount?: number
}

export type EventCardData = {
Expand Down

0 comments on commit d11da50

Please sign in to comment.