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 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 eventTitle = ref(null)
|
||||
@ -240,16 +246,6 @@ watch(
|
||||
(newEvent) => {
|
||||
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(() => {
|
||||
if (props.mode === 'create' && _event.value.id === 'new-event') {
|
||||
_event.value.fromDate = newEvent.fromDate
|
||||
|
||||
@ -157,7 +157,11 @@ const events = createListResource({
|
||||
})
|
||||
|
||||
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)
|
||||
} else {
|
||||
updateEvent(_event)
|
||||
@ -193,16 +197,23 @@ function updateEvent(_event) {
|
||||
if (!_event.id) return
|
||||
|
||||
if (!mode.value || mode.value === 'edit' || mode.value === 'details') {
|
||||
events.setValue.submit({
|
||||
name: _event.id,
|
||||
subject: _event.title,
|
||||
description: _event.description,
|
||||
starts_on: _event.fromDateTime,
|
||||
ends_on: _event.toDateTime,
|
||||
all_day: _event.isFullDay,
|
||||
event_type: _event.eventType,
|
||||
color: _event.color,
|
||||
})
|
||||
events.setValue.submit(
|
||||
{
|
||||
name: _event.id,
|
||||
subject: _event.title,
|
||||
description: _event.description,
|
||||
starts_on: _event.fromDateTime,
|
||||
ends_on: _event.toDateTime,
|
||||
all_day: _event.isFullDay,
|
||||
event_type: _event.eventType,
|
||||
color: _event.color,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
mode.value = 'details'
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
event.value = _event
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user