sanity-plugin-recurring-dates 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -9
- package/dist/index.d.ts +7 -1
- package/dist/index.esm.js +58 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +55 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/RecurringDate.tsx +11 -4
- package/src/components/RemoveEndDate.tsx +48 -0
- package/src/plugin.tsx +1 -1
- package/src/schema/recurringDates.tsx +2 -2
- package/src/types.ts +6 -0
package/package.json
CHANGED
|
@@ -2,20 +2,25 @@ import {Box, Flex, Grid, Select, Stack, Text} from '@sanity/ui'
|
|
|
2
2
|
import {upperFirst} from 'lodash'
|
|
3
3
|
import React, {useCallback, useState} from 'react'
|
|
4
4
|
import {rrulestr} from 'rrule'
|
|
5
|
-
import {ObjectInputMember, type ObjectInputProps, set} from 'sanity'
|
|
5
|
+
import {ObjectInputMember, type ObjectInputProps, ObjectSchemaType, set} from 'sanity'
|
|
6
6
|
import {Feedback} from 'sanity-plugin-utils'
|
|
7
7
|
|
|
8
8
|
import type {PluginConfig, WithRequiredProperty} from '../types'
|
|
9
9
|
import {validateRRuleStrings} from '../utils'
|
|
10
10
|
import {CustomRule} from './CustomRule'
|
|
11
|
+
import {RemoveEndDate} from './RemoveEndDate'
|
|
11
12
|
|
|
12
13
|
type RecurringDatesProps = ObjectInputProps & {
|
|
13
14
|
pluginConfig: WithRequiredProperty<PluginConfig, 'defaultRecurrences'>
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
type RecurringDateObjectSchemaType = Omit<ObjectSchemaType, 'options'> & {
|
|
18
|
+
options?: PluginConfig
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
export function RecurringDates(props: RecurringDatesProps) {
|
|
17
22
|
const {onChange, members, value: currentValue, schemaType, pluginConfig} = props
|
|
18
|
-
const {options}:
|
|
23
|
+
const {options, title}: RecurringDateObjectSchemaType = schemaType
|
|
19
24
|
const {defaultRecurrences, hideEndDate, hideCustom, dateTimeOptions} = {
|
|
20
25
|
...pluginConfig,
|
|
21
26
|
...options,
|
|
@@ -32,10 +37,8 @@ export function RecurringDates(props: RecurringDatesProps) {
|
|
|
32
37
|
const {value} = event.currentTarget
|
|
33
38
|
|
|
34
39
|
if (value == 'custom') {
|
|
35
|
-
// open modal...
|
|
36
40
|
onOpen()
|
|
37
41
|
} else {
|
|
38
|
-
// update the field
|
|
39
42
|
onChange(set(value, ['rrule']))
|
|
40
43
|
}
|
|
41
44
|
},
|
|
@@ -82,9 +85,13 @@ export function RecurringDates(props: RecurringDatesProps) {
|
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
// Do we have an end date set for this field?
|
|
89
|
+
const hasEndDate = currentValue && currentValue.endDate
|
|
90
|
+
|
|
85
91
|
return (
|
|
86
92
|
<Stack space={3}>
|
|
87
93
|
<Grid columns={hideEndDate ? 1 : 2} gap={3}>
|
|
94
|
+
{hasEndDate && hideEndDate && <RemoveEndDate title={title} onChange={onChange} />}
|
|
88
95
|
<Flex align="flex-end" gap={2}>
|
|
89
96
|
<Box flex={1}>
|
|
90
97
|
{startDateMember && <ObjectInputMember member={startDateMember} {...renderProps} />}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {TrashIcon, WarningOutlineIcon} from '@sanity/icons'
|
|
2
|
+
import {Box, Button, Card, Flex, Stack, Text} from '@sanity/ui'
|
|
3
|
+
import {upperFirst} from 'lodash'
|
|
4
|
+
import {useCallback} from 'react'
|
|
5
|
+
import {type ObjectInputProps, unset} from 'sanity'
|
|
6
|
+
|
|
7
|
+
export function RemoveEndDate({
|
|
8
|
+
title,
|
|
9
|
+
onChange,
|
|
10
|
+
}: {
|
|
11
|
+
title?: string
|
|
12
|
+
onChange: ObjectInputProps['onChange']
|
|
13
|
+
}) {
|
|
14
|
+
// Update the RRULE field when the select changes
|
|
15
|
+
const handleUnsetClick = useCallback(() => {
|
|
16
|
+
onChange(unset(['endDate']))
|
|
17
|
+
}, [onChange])
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Card padding={4} radius={2} tone="caution" data-ui="Alert">
|
|
21
|
+
<Flex>
|
|
22
|
+
<Box>
|
|
23
|
+
<Text size={1}>
|
|
24
|
+
<WarningOutlineIcon />
|
|
25
|
+
</Text>
|
|
26
|
+
</Box>
|
|
27
|
+
<Stack space={3} flex={1} marginLeft={3}>
|
|
28
|
+
<Text size={1} weight="semibold">
|
|
29
|
+
The {title ? upperFirst(title) : `current`} field has an end date
|
|
30
|
+
</Text>
|
|
31
|
+
<Box>
|
|
32
|
+
<Text as="p" muted size={1}>
|
|
33
|
+
This field has an end date value, but the end date is currently disabled for this
|
|
34
|
+
field.
|
|
35
|
+
</Text>
|
|
36
|
+
</Box>
|
|
37
|
+
<Button
|
|
38
|
+
icon={TrashIcon}
|
|
39
|
+
tone="critical"
|
|
40
|
+
text={<>Remove end date</>}
|
|
41
|
+
onClick={handleUnsetClick}
|
|
42
|
+
width="100%"
|
|
43
|
+
/>
|
|
44
|
+
</Stack>
|
|
45
|
+
</Flex>
|
|
46
|
+
</Card>
|
|
47
|
+
)
|
|
48
|
+
}
|
package/src/plugin.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import {DEFAULT_CONFIG} from './constants'
|
|
|
4
4
|
import recurringDateSchema from './schema/recurringDates'
|
|
5
5
|
import {PluginConfig, WithRequiredProperty} from './types'
|
|
6
6
|
|
|
7
|
-
export const recurringDates = definePlugin<PluginConfig>((config) => {
|
|
7
|
+
export const recurringDates = definePlugin<PluginConfig | void>((config) => {
|
|
8
8
|
const pluginConfig: WithRequiredProperty<PluginConfig, 'defaultRecurrences'> = {
|
|
9
9
|
...DEFAULT_CONFIG,
|
|
10
10
|
...config,
|
|
@@ -4,7 +4,7 @@ import {RecurringDates} from '../components/RecurringDate'
|
|
|
4
4
|
import {PluginConfig, WithRequiredProperty} from '../types'
|
|
5
5
|
|
|
6
6
|
export default (config: WithRequiredProperty<PluginConfig, 'defaultRecurrences'>) => {
|
|
7
|
-
const {
|
|
7
|
+
const {dateTimeOptions} = config
|
|
8
8
|
|
|
9
9
|
return defineField({
|
|
10
10
|
name: 'recurringDates',
|
|
@@ -36,7 +36,7 @@ export default (config: WithRequiredProperty<PluginConfig, 'defaultRecurrences'>
|
|
|
36
36
|
type: 'string',
|
|
37
37
|
hidden: true,
|
|
38
38
|
}),
|
|
39
|
-
]
|
|
39
|
+
],
|
|
40
40
|
components: {
|
|
41
41
|
input: (props) => RecurringDates({...props, pluginConfig: config}),
|
|
42
42
|
},
|