refactor: update event title logic and improve saveEvent function structure
This commit is contained in:
parent
6ec2c1e805
commit
3f4601efa0
@ -229,7 +229,13 @@ const emit = defineEmits(['save', 'edit', 'delete', 'details', 'close'])
|
|||||||
|
|
||||||
const show = defineModel()
|
const show = defineModel()
|
||||||
|
|
||||||
const title = ref('New event')
|
const title = computed(() => {
|
||||||
|
if (props.mode === 'details') return __('Event details')
|
||||||
|
if (props.mode === 'edit') return __('Editing event')
|
||||||
|
if (props.mode === 'create') return __('New event')
|
||||||
|
return __('Duplicate event')
|
||||||
|
})
|
||||||
|
|
||||||
const _event = ref({})
|
const _event = ref({})
|
||||||
|
|
||||||
const eventTitle = ref(null)
|
const eventTitle = ref(null)
|
||||||
@ -240,16 +246,6 @@ watch(
|
|||||||
(newEvent) => {
|
(newEvent) => {
|
||||||
error.value = null
|
error.value = null
|
||||||
|
|
||||||
if (props.mode === 'details') {
|
|
||||||
title.value = 'Event details'
|
|
||||||
} else if (props.mode === 'edit') {
|
|
||||||
title.value = 'Editing event'
|
|
||||||
} else if (props.mode === 'create') {
|
|
||||||
title.value = 'New event'
|
|
||||||
} else {
|
|
||||||
title.value = 'Duplicate event'
|
|
||||||
}
|
|
||||||
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (props.mode === 'create' && _event.value.id === 'new-event') {
|
if (props.mode === 'create' && _event.value.id === 'new-event') {
|
||||||
_event.value.fromDate = newEvent.fromDate
|
_event.value.fromDate = newEvent.fromDate
|
||||||
|
|||||||
@ -157,7 +157,11 @@ const events = createListResource({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function saveEvent(_event) {
|
function saveEvent(_event) {
|
||||||
if (!event.id || event.id === 'new-event' || event.id === 'duplicate-event') {
|
if (
|
||||||
|
!_event.id ||
|
||||||
|
_event.id === 'new-event' ||
|
||||||
|
_event.id === 'duplicate-event'
|
||||||
|
) {
|
||||||
createEvent(_event)
|
createEvent(_event)
|
||||||
} else {
|
} else {
|
||||||
updateEvent(_event)
|
updateEvent(_event)
|
||||||
@ -193,16 +197,23 @@ function updateEvent(_event) {
|
|||||||
if (!_event.id) return
|
if (!_event.id) return
|
||||||
|
|
||||||
if (!mode.value || mode.value === 'edit' || mode.value === 'details') {
|
if (!mode.value || mode.value === 'edit' || mode.value === 'details') {
|
||||||
events.setValue.submit({
|
events.setValue.submit(
|
||||||
name: _event.id,
|
{
|
||||||
subject: _event.title,
|
name: _event.id,
|
||||||
description: _event.description,
|
subject: _event.title,
|
||||||
starts_on: _event.fromDateTime,
|
description: _event.description,
|
||||||
ends_on: _event.toDateTime,
|
starts_on: _event.fromDateTime,
|
||||||
all_day: _event.isFullDay,
|
ends_on: _event.toDateTime,
|
||||||
event_type: _event.eventType,
|
all_day: _event.isFullDay,
|
||||||
color: _event.color,
|
event_type: _event.eventType,
|
||||||
})
|
color: _event.color,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
mode.value = 'details'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
event.value = _event
|
event.value = _event
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user