Skip to content

Commit c25067e

Browse files
committed
🎨 update
1 parent cf5cecd commit c25067e

16 files changed

Lines changed: 274 additions & 195 deletions

File tree

studio/schemas/documents/event.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { calendar_event, image } from '@equinor/eds-icons'
2-
import { Stack } from '@sanity/ui'
32
import {
4-
type ArrayOfObjectsInputProps,
5-
type DateTimeInputProps,
63
defineField,
74
type PortableTextBlock,
85
type Rule,
@@ -35,6 +32,12 @@ const validateRelatedLinksTitle = (
3532
return true
3633
}
3734

35+
export type EventDayAndTime = {
36+
_type: 'eventDayAndTime'
37+
dayTime: Date
38+
overrideTimeLabel?: string
39+
}
40+
3841
export default {
3942
type: 'document',
4043
title: 'Event',
@@ -204,13 +207,41 @@ export default {
204207
],
205208
},
206209
],
210+
orderings: [
211+
{
212+
title: 'Start date ',
213+
name: 'startDateAsc',
214+
by: [{ field: 'startDayAndTime.dayTime', direction: 'asc' }],
215+
},
216+
],
207217
preview: {
208218
select: {
209219
title: 'title',
210220
date: 'eventDate',
221+
startDayAndTime: 'startDayAndTime',
222+
endDayAndTime: 'endDayAndTime',
211223
},
212-
prepare({ title, date }: { title: PortableTextBlock[]; date: EventDate }) {
213-
const eventDate = date?.date ? `${date.date}` : 'No date set'
224+
prepare({
225+
title,
226+
date,
227+
startDayAndTime,
228+
endDayAndTime,
229+
}: {
230+
title?: PortableTextBlock[]
231+
date?: EventDate
232+
startDayAndTime?: EventDayAndTime
233+
endDayAndTime?: EventDayAndTime
234+
}) {
235+
let eventDate = date?.date ? `${date.date}` : 'No date set'
236+
if (startDayAndTime) {
237+
if (endDayAndTime && !startDayAndTime?.overrideTimeLabel) {
238+
eventDate = `${startDayAndTime?.dayTime} - ${endDayAndTime?.dayTime}`
239+
} else {
240+
eventDate = startDayAndTime?.overrideTimeLabel
241+
? `${startDayAndTime?.overrideTimeLabel}`
242+
: `${startDayAndTime?.dayTime}`
243+
}
244+
}
214245
return {
215246
title: title ? blocksToText(title) : 'Untitled event',
216247
subtitle: eventDate,

studio/schemas/objects/commonFields/commonFields.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const background = {
5858
}
5959

6060
export const backgroundPosition = (hiddenCallBack?: any, fieldset?: string) => {
61+
console.log('hiddenCallBack', hiddenCallBack)
6162
return defineField({
6263
title: 'Select positioning of the image',
6364
description:

studio/schemas/objects/eventDate.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Rule, ValidationContext } from 'sanity'
22
import TimeInput, { EMPTY, INVALID_TIME_FORMAT } from '../components/TimeInput'
3-
import TimezoneInput from '../components/TimezoneInput'
43

54
export type EventDate = {
65
_type: 'eventDate'
@@ -42,13 +41,14 @@ export default {
4241
const { parent } = context as { parent: EventDate }
4342
if (!isValid(field)) {
4443
return INVALID_TIME_FORMAT
45-
} else if (!field && parent.endTime) {
44+
}
45+
if (!field && parent.endTime) {
4646
return 'Start time must not be empty'
47-
} else if (field && !parent.date) {
47+
}
48+
if (field && !parent.date) {
4849
return 'Date must be defined'
49-
} else {
50-
return true
5150
}
51+
return true
5252
}),
5353
},
5454
{
@@ -63,15 +63,17 @@ export default {
6363
const { parent } = context as { parent: EventDate }
6464
if (!isValid(field)) {
6565
return INVALID_TIME_FORMAT
66-
} else if (!field && parent.startTime) {
66+
}
67+
if (!field && parent.startTime) {
6768
return 'End time must not be empty'
68-
} else if (parent.startTime && field && field <= parent.startTime) {
69+
}
70+
if (parent.startTime && field && field <= parent.startTime) {
6971
return 'End time must be greather than start time'
70-
} else if (field && !parent.date) {
72+
}
73+
if (field && !parent.date) {
7174
return 'Date must be defined'
72-
} else {
73-
return true
7475
}
76+
return true
7577
}),
7678
},
7779
],

studio/schemas/objects/promotion/promoteEvents.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ export default {
119119
collapsed: false,
120120
},
121121
hidden: ({ parent }: any) =>
122-
parent?.promotionType !== 'manual' && parent?.eventsCount > 1,
122+
parent?.promotionType !== 'manual' || parent?.eventsCount > 1,
123123
},
124-
backgroundPosition(),
124+
backgroundPosition(
125+
(parent: any) =>
126+
parent?.promotionType !== 'manual' || parent?.eventsCount > 1,
127+
),
125128
viewAllLink,
126129
viewAllLinkLabel,
127130
theme,

web/core/AddToCalendar/AddToCalendar.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const ics = require('ics')
1111

1212
type AddToCalendarProps = {
1313
eventDate: EventDateType
14+
startDateTime: Date
15+
endDateTime: Date
1416
location?: string
1517
title: string
1618
}
@@ -50,25 +52,30 @@ const createICS = (eventData: ICSProps): string | boolean => {
5052
})
5153
}
5254

53-
const AddToCalendar = ({ eventDate, title, location }: AddToCalendarProps) => {
55+
const AddToCalendar = ({
56+
eventDate,
57+
startDateTime,
58+
endDateTime,
59+
title,
60+
location,
61+
}: AddToCalendarProps) => {
5462
const intl = useTranslations()
5563
const [fileData, setFileData] = useState<string | boolean>(false)
5664

5765
useEffect(() => {
5866
const { start: startString, end: endString } = getEventDates(eventDate)
67+
if (!startString && !eventDate?.date && !startDateTime) return
5968

60-
if (!startString) return
61-
62-
const start = new Date(startString)
69+
const start = new Date(startDateTime ?? startString ?? eventDate?.date)
6370

6471
let end: Date
65-
if (!endString) {
72+
if (!endString || !endDateTime) {
6673
/* If time is not specified add to calendar as a full day */
67-
end = new Date(startString)
74+
end = new Date(startDateTime ?? startString ?? eventDate?.date)
6875
start.setHours(0, 0, 0)
6976
end.setHours(23, 59, 59)
7077
} else {
71-
end = new Date(endString)
78+
end = new Date(endDateTime)
7279
}
7380

7481
if (isUpcoming(end)) {
@@ -82,7 +89,7 @@ const AddToCalendar = ({ eventDate, title, location }: AddToCalendarProps) => {
8289
}
8390
setFileData(createICS(eventData))
8491
}
85-
}, [eventDate, location, title])
92+
}, [eventDate, startDateTime, endDateTime, location, title])
8693

8794
if (!fileData) return null
8895
const atc = intl('add_to_calendar_event')

web/core/FormattedDateTime/FormattedDateTime.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type FormattedDateTimeProps = {
2929
/* Render time with timezone */
3030
/* @default false */
3131
showTimezone?: boolean
32+
timeClassName?: string
3233
} & HTMLAttributes<HTMLSpanElement> &
3334
DateTimeFormatOptions
3435

@@ -46,6 +47,7 @@ const FormattedDateTime = forwardRef<HTMLSpanElement, FormattedDateTimeProps>(
4647
showTimezone = false,
4748
uppercase = false,
4849
className = '',
50+
timeClassName = '',
4951
},
5052
ref,
5153
) => {
@@ -110,7 +112,7 @@ const FormattedDateTime = forwardRef<HTMLSpanElement, FormattedDateTimeProps>(
110112
{dateIcon && <DateIcon />}
111113
{timeIcon && <TimeIcon />}
112114
<time suppressHydrationWarning dateTime={datetime?.toLocaleString()}>
113-
<span className={`mt-auto block leading-6`}>
115+
<span className={twMerge(`mt-auto block leading-6`, timeClassName)}>
114116
{formatter.dateTime(new Date(datetime), config)}
115117
</span>
116118
</time>

0 commit comments

Comments
 (0)