feat: duplicate event from lead/deal events tab

This commit is contained in:
Shariq Ansari 2025-08-21 14:01:28 +05:30
parent 9cd6b142d7
commit bff1b6156f
2 changed files with 46 additions and 13 deletions

View File

@ -196,10 +196,8 @@ declare module 'vue' {
LucideCalendar: typeof import('~icons/lucide/calendar')['default'] LucideCalendar: typeof import('~icons/lucide/calendar')['default']
LucideChevronLeft: typeof import('~icons/lucide/chevron-left')['default'] LucideChevronLeft: typeof import('~icons/lucide/chevron-left')['default']
LucideChevronRight: typeof import('~icons/lucide/chevron-right')['default'] LucideChevronRight: typeof import('~icons/lucide/chevron-right')['default']
LucideEarth: typeof import('~icons/lucide/earth')['default'] LucideCopy: typeof import('~icons/lucide/copy')['default']
LucideLetterText: typeof import('~icons/lucide/letter-text')['default'] LucideTrash2: typeof import('~icons/lucide/trash2')['default']
LucidePlus: typeof import('~icons/lucide/plus')['default']
LucideText: typeof import('~icons/lucide/text')['default']
LucideX: typeof import('~icons/lucide/x')['default'] LucideX: typeof import('~icons/lucide/x')['default']
MarkAsDoneIcon: typeof import('./src/components/Icons/MarkAsDoneIcon.vue')['default'] MarkAsDoneIcon: typeof import('./src/components/Icons/MarkAsDoneIcon.vue')['default']
MaximizeIcon: typeof import('./src/components/Icons/MaximizeIcon.vue')['default'] MaximizeIcon: typeof import('./src/components/Icons/MaximizeIcon.vue')['default']

View File

@ -4,15 +4,30 @@
<div class="mb-6 flex items-center justify-between"> <div class="mb-6 flex items-center justify-between">
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
<h3 class="text-2xl font-semibold leading-6 text-ink-gray-9"> <h3 class="text-2xl font-semibold leading-6 text-ink-gray-9">
{{ editMode ? __('Edit an event') : __('Create an event') }} {{
mode === 'edit'
? __('Edit an event')
: mode === 'duplicate'
? __('Duplicate an event')
: __('Create an event')
}}
</h3> </h3>
</div> </div>
<div class="flex gap-1"> <div class="flex gap-1">
<Button variant="ghost" @click="deleteEvent"> <Button v-if="mode === 'edit'" variant="ghost" @click="deleteEvent">
<template #icon> <template #icon>
<LucideTrash2 class="h-4 w-4 text-ink-gray-9" /> <LucideTrash2 class="h-4 w-4 text-ink-gray-9" />
</template> </template>
</Button> </Button>
<Button
v-if="mode === 'edit'"
variant="ghost"
@click="duplicateEvent"
>
<template #icon>
<LucideCopy class="h-4 w-4 text-ink-gray-9" />
</template>
</Button>
<Button variant="ghost" @click="show = false"> <Button variant="ghost" @click="show = false">
<template #icon> <template #icon>
<LucideX class="h-4 w-4 text-ink-gray-9" /> <LucideX class="h-4 w-4 text-ink-gray-9" />
@ -119,8 +134,16 @@
<Button :label="__('Cancel')" @click="show = false" /> <Button :label="__('Cancel')" @click="show = false" />
<Button <Button
variant="solid" variant="solid"
:label="editMode ? __('Update') : __('Create')" :label="
:loading="editMode ? events.setValue.loading : events.insert.loading" mode === 'edit'
? __('Update')
: mode === 'duplicate'
? __('Duplicate')
: __('Create')
"
:loading="
mode === 'edit' ? events.setValue.loading : events.insert.loading
"
@click="update" @click="update"
/> />
</div> </div>
@ -138,7 +161,7 @@ import {
} from 'frappe-ui' } from 'frappe-ui'
import { globalStore } from '@/stores/global' import { globalStore } from '@/stores/global'
import { getFormat } from '@/utils' import { getFormat } from '@/utils'
import { onMounted, ref } from 'vue' import { onMounted, ref, computed } from 'vue'
const props = defineProps({ const props = defineProps({
event: { event: {
@ -162,7 +185,13 @@ const events = defineModel('events')
const title = ref(null) const title = ref(null)
const error = ref(null) const error = ref(null)
const editMode = ref(false) const mode = computed(() => {
return _event.value.id == 'duplicate'
? 'duplicate'
: _event.value.id
? 'edit'
: 'create'
})
const _event = ref({ const _event = ref({
title: '', title: '',
@ -181,9 +210,7 @@ onMounted(() => {
let start = dayjs(props.event.starts_on) let start = dayjs(props.event.starts_on)
let end = dayjs(props.event.ends_on) let end = dayjs(props.event.ends_on)
if (props.event.name) { if (!props.event.name) {
editMode.value = true
} else {
start = dayjs() start = dayjs()
end = dayjs().add(1, 'hour') end = dayjs().add(1, 'hour')
} }
@ -300,6 +327,14 @@ function updateEvent() {
) )
} }
function duplicateEvent() {
if (!_event.value.id) return
_event.value.id = 'duplicate'
_event.value.title = _event.value.title + ' (Copy)'
setTimeout(() => title.value?.el?.focus(), 100)
}
function deleteEvent() { function deleteEvent() {
if (!_event.value.id) return if (!_event.value.id) return