Skip to content

Commit 95f1c8b

Browse files
committed
Update the add event modal and functionality
1 parent 0ec6996 commit 95f1c8b

File tree

5 files changed

+100
-14
lines changed

5 files changed

+100
-14
lines changed

components.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ export {}
88
declare module 'vue' {
99
export interface GlobalComponents {
1010
BButton: typeof import('bootstrap-vue-next')['BButton']
11+
BButtonGroup: typeof import('bootstrap-vue-next')['BButtonGroup']
1112
BCard: typeof import('bootstrap-vue-next')['BCard']
13+
BCardBody: typeof import('bootstrap-vue-next')['BCardBody']
14+
BCardBordy: typeof import('bootstrap-vue-next')['BCardBordy']
15+
BCardFooter: typeof import('bootstrap-vue-next')['BCardFooter']
1216
BCardText: typeof import('bootstrap-vue-next')['BCardText']
1317
BCol: typeof import('bootstrap-vue-next')['BCol']
1418
BContainer: typeof import('bootstrap-vue-next')['BContainer']
1519
BFormInput: typeof import('bootstrap-vue-next')['BFormInput']
20+
BFormInvalidFeedback: typeof import('bootstrap-vue-next')['BFormInvalidFeedback']
21+
BFormTextarea: typeof import('bootstrap-vue-next')['BFormTextarea']
1622
BNav: typeof import('bootstrap-vue-next')['BNav']
1723
BRow: typeof import('bootstrap-vue-next')['BRow']
1824
EventModal: typeof import('./src/components/EventModal.vue')['default']

src/components/EventModal.vue

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,79 @@
11
<script setup lang="ts">
22
import { useCalendarStore } from '@/stores/calendar';
33
import { storeToRefs } from 'pinia';
4-
import { watch } from 'vue';
4+
import { computed, ref, watch } from 'vue';
55
66
const calendarStore = useCalendarStore()
7-
const { modal } = storeToRefs(calendarStore)
8-
const { setModal } = calendarStore
7+
const { modal, getAddedEvents } = storeToRefs(calendarStore)
8+
const { setModal, setAddedEvents } = calendarStore
99
10-
watch(modal, () => {
11-
console.log('---', modal.value)
10+
const eventTitle = ref('')
11+
const startDateTime = ref<string | Date>( new Date() )
12+
const endDateTime = ref<string | Date>( new Date() )
13+
const contentText = ref('')
14+
15+
const titleState = computed(() => (eventTitle.value?.length > 2 ? true : false))
16+
17+
const addEvent = () => {
18+
setAddedEvents({
19+
title: eventTitle.value,
20+
startDataTime: startDateTime.value,
21+
endDataTime: endDateTime.value,
22+
contentText: contentText.value
23+
}, 'add')
24+
}
25+
26+
watch(getAddedEvents.value, () => {
27+
console.log('--->>>>', getAddedEvents.value)
1228
})
1329
</script>
1430

1531
<template>
1632
<teleport to="body">
1733
<div class="modal-wrapper" v-if="modal">
18-
<BCard header="Add Event" header-tag="header" footer="Card Footer" footer-tag="footer"
19-
class="fc-modal text-center bg-white" title="Add Event">
20-
<BCardText>Header and footers using props.</BCardText>
21-
<BButton variant="primary" @click="setModal()">Close</BButton>
34+
<BCard
35+
header="Calendar Modal"
36+
header-tag="header"
37+
class="fc-modal text-center bg-white fs-5 p-0 min"
38+
title="Add Event"
39+
style="min-width: 400px;"
40+
>
41+
<BCardBody class="fs-6 pt-0">
42+
<div role="group" class="text-start">
43+
<BCol cols="12" class="p-1">
44+
<label for="title">Title:</label>
45+
<BFormInput id="title" v-model="eventTitle" placeholder="Enter event title" :state="titleState" trim />
46+
<BFormInvalidFeedback id="input-live-feedback"> Enter at least 3 letters </BFormInvalidFeedback>
47+
</BCol>
48+
<BCol cols="12" class="p-1">
49+
<label for="start">Start:</label>
50+
<VueDatePicker aria-label="start" v-model="startDateTime" placeholder="Pick the start time" />
51+
</BCol>
52+
<BCol cols="12" class="p-1">
53+
<label for="end">Until:</label>
54+
<VueDatePicker aria-label="end" v-model="endDateTime" placeholder="Pick the End time" />
55+
</BCol>
56+
<BCol cols="12" class="p-1">
57+
<BFormTextarea
58+
id="textarea"
59+
v-model="contentText"
60+
placeholder="Enter something..."
61+
rows="3"
62+
max-rows="6"
63+
/>
64+
</BCol>
65+
</div>
66+
67+
</BCardBody>
68+
69+
<template v-slot:footer>
70+
<div tag="footer" class="d-flex justify-content-end">
71+
<BButtonGroup>
72+
<BButton variant="primary" @click="setModal()">Close</BButton>
73+
<BButton variant="success" @click="addEvent()">Add</BButton>
74+
</BButtonGroup>
75+
</div>
76+
</template>
2277
</BCard>
2378
</div>
2479

src/interfaces/eventTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface CustomEvent {
2+
id?: string | number
3+
title: string
4+
startDataTime: string | Date
5+
endDataTime: string | Date
6+
contentText?: string
7+
}

src/interfaces/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import type * as FullCalendar from './builtInTypes'
2+
import type { CustomEvent } from './eventTypes'
23

3-
export type {FullCalendar}
4+
export type { FullCalendar, CustomEvent }

src/stores/calendar.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
import { ref, computed } from 'vue'
2-
import { createPinia } from 'pinia'
3-
import { defineStore } from 'pinia'
2+
import { createPinia, defineStore } from 'pinia'
3+
import type { CustomEvent } from '@/interfaces'
44

55
export const pinia = createPinia()
66

77
export const useCalendarStore = defineStore('calendar', () => {
88
const calendarApi = ref()
99
const modal = ref(false)
10+
const addedEvents = ref<CustomEvent[]>([])
1011

1112
const getCalendarApi = computed(() => calendarApi.value)
13+
const getAddedEvents = computed(() => addedEvents.value)
1214

1315
const setCalendarApi = (value: any) => {
1416
calendarApi.value = value
1517
}
16-
1718
const setModal = () => {
1819
modal.value = !modal.value
1920
}
21+
const setAddedEvents = (value: CustomEvent | string | number , type: string) => {
22+
const id = addedEvents.value.length
23+
const newEvent = { ...value as CustomEvent, id }
24+
25+
switch (type) {
26+
case 'add':
27+
addedEvents.value.push(newEvent as CustomEvent)
28+
break
29+
case 'delete':
30+
delete addedEvents.value[value as any]
31+
break
32+
default:
33+
break
34+
}
35+
addedEvents.value.push()
36+
}
2037

21-
return { calendarApi, modal, getCalendarApi, setCalendarApi, setModal }
38+
return { calendarApi, modal, addedEvents, getCalendarApi, getAddedEvents, setCalendarApi, setModal, setAddedEvents }
2239
})

0 commit comments

Comments
 (0)