refactor: update event title logic and improve saveEvent function structure

This commit is contained in:
Shariq Ansari 2025-08-07 18:22:31 +05:30
parent 6ec2c1e805
commit 3f4601efa0
2 changed files with 29 additions and 22 deletions

View File

@ -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

View File

@ -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